public static int SendShortMessage(int aChannelCommand, int aData1, int aData2, bool through = false) { int channel = (aChannelCommand & 0x0F); int command = (aChannelCommand & 0xF0); // Debug.Log ("-----"); // Debug.Log (channel.ToString("X2")); // Debug.Log (command.ToString("X2")); // Debug.Log (aData1.ToString("X2")); // Debug.Log (aData2.ToString("X2")); // Debug.Log ("-----"); if (command == (int)CommandEnum.ProgramChange) { programEnums[channel] = (ProgramEnum)aData1; if (ignoreProgramMessages) { return(0); } } if (command.IsNoteON()) { channelCache[channel].notes[aData1].on = true; if (applyChannelVolumes) { aData2 = (int)(volumes[channel] * aData2); } } else if (command.IsNoteOFF()) { channelCache[channel].notes[aData1].on = false; } if (ShortMessageEvent != null && fireMidiOutEvents) { ShortMessageEvent(aChannelCommand, aData1, aData2); } if (muteMessages || through) { return(0); } else { if (((1 << channel) & synthChannelMask) != 0) { Synth.SendMidiMessage(aChannelCommand, aData1, aData2); } if (((1 << channel) & channelMask) != 0) { return(MidiOUTPlugin.SendShortMessage((byte)aChannelCommand, (byte)aData1, (byte)aData2)); } else { return(0); } } }
//static void OnTimer (object sender, System.Timers.ElapsedEventArgs e) //{ // Fetch (); //} //static void InitTimer () //{ // timer = new System.Timers.Timer (10); // timer.Elapsed += OnTimer; // timer.Start (); //} //static void FinalizeTimer () //{ // if (timer != null) { // timer.Stop (); // timer.Elapsed -= OnTimer; // timer.Dispose (); // } //} public static void Fetch() { MidiMessage midiMessage = new MidiMessage(); while (MidiINPlugin.PopMessage(out midiMessage) != 0) { midiInMessages.Enqueue(midiMessage); midiOutMessages.Enqueue(midiMessage); midiMessage = new MidiMessage(); } while (midiOutMessages.Count > 0) { if (midiOutMessages.TryDequeue(out midiMessage)) { MidiOUTPlugin.SendShortMessage(midiMessage.command, midiMessage.data1, midiMessage.data2); Synth.SendMidiMessage(midiMessage.command, midiMessage.data1, midiMessage.data2); midiMessage = new MidiMessage(); } } }