forked from XAYRGA/JAIMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keyboard.cs
114 lines (99 loc) · 4 KB
/
Keyboard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using System.Drawing;
using System.Runtime;
using System.Runtime.InteropServices;
using SdlDotNet.Input;
using System.Diagnostics;
using JaiSeqX.Player;
namespace JaiMaker
{
public static class Keyboard
{
public static BMSChannelManager channelManager = new BMSChannelManager();
static string keyOrderString = @"1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./";
static int[] pitches;
public static void init()
{
var lastPitch = 0;
pitches = new int[1024];
for (int i=0; i < keyOrderString.Length;i++)
{
var str = keyOrderString[i];
pitches[str] = lastPitch++;
}
}
public static void stopSound(byte inkey)
{
channelManager.stopVoice(0, inkey);
}
public static void startSound(byte inkey)
{
var prog = Root.currentProg;
if (prog!=null)
{
var note = pitches[inkey] + Root.keyOffset;
var vel = Root.currentVel;
if (prog.Keys[note]!=null)
{
var notedata = prog.Keys[note];
var key = notedata.keys[vel];
if (key!=null)
{
try
{
var wsysid = key.wsysid;
var waveid = key.wave;
var wsys = Root.allWSYS[wsysid];
if (wsys != null)
{
var wave = wsys.waves[waveid];
var sound = channelManager.loadSound(wave.pcmpath, wave.loop, wave.loop_start, wave.loop_end).CreateInstance();
var pmul = prog.Pitch * key.Pitch;
var vmul = prog.Volume * key.Volume;
var real_pitch = Math.Pow(2, ((note - wave.key) * pmul) / 12);
var true_volume = (Math.Pow(((float)vel + Root.keyOffset) / 127, 2) * vmul) * 0.5;
sound.Volume = (float)(true_volume * 0.6);
sound.ShouldFade = true;
sound.FadeOutMS = 30;
if (prog.IsPercussion)
{
real_pitch = (float)(key.Pitch * prog.Pitch);
sound.ShouldFade = true;
sound.FadeOutMS = 200; // no instant stops
}
sound.Pitch = (float)(real_pitch);
channelManager.startVoice(sound, 0, inkey);
sound.Play();
}
else
{
Console.WriteLine("Null WSYS??");
}
}
catch (Exception E)
{
var b = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("fuuuuuck");
Console.WriteLine(E.ToString());
Console.ForegroundColor = b;
}
} else
{
Console.WriteLine("Null key :(");
}
} else
{
Console.WriteLine("ugh.");
}
}
}
}
}