As a hobby lately I have been doing a Piano (Midi) to keyboard software, but I have encountered a problem, to be able to be listening and executing several keys at the same time I have decided to use if and else if, but I understand that the program is using enough resources from the cpu and when an if is activated
Example 1 for On Note:
if (RawNotes.Contains ("Len: 0") == true && RawNotes.Contains ("0 NoteOn Ch: 1 C") == true && RawNotes.Contains ("#") == false)
Example 2 for Off Note:
else if (RawNotes.Contains("Vel") == true && RawNotes.Contains("0 NoteOn Ch: 1 C") == true && RawNotes.Contains("#") == false)
inspect the RawNotes string
Example RawNotes String Output
this string is constantly changing, thats the Output that the string gives me using Console.WriteLine(RawNotes);
0 NoteOn Ch: 1 C3 Vel: 41 Len: 0 //<-- NoteOn
0 TimingClock
0 TimingClock
0 TimingClock
0 TimingClock
0 NoteOn Ch: 1 C3 Vel: 0 // <-- NoteOff
0 AutoSensing
0 TimingClock
And the main part of the code, it is only possible to execute for a few seconds since the if says so?
Thread One = new Thread(() =>
{
while (true)
{
if (RawNotes.Contains ("Len: 0") == true && RawNotes.Contains ("0 NoteOn Ch: 1 C") == true && RawNotes.Contains ("#") == false)
{
sim.Keyboard.KeyDown((VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), Key1)); // <-- The problem
}
else if (RawNotes.Contains("Vel") == true && RawNotes.Contains(MultiHelp + "C") == true && RawNotes.Contains("#") == false)
{
sim.Keyboard.KeyUp((VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), Key1));
//And so on...