public void ProcessMidiEvent(MidiEvent midiEvent) { if (midiEvent.midiChannelEvent != MidiHelper.MidiChannelEvent.None) { switch (midiEvent.midiChannelEvent) { case MidiHelper.MidiChannelEvent.Program_Change: if (midiEvent.channel != 9) { if (midiEvent.parameter1 < synth.SoundBank.InstrumentCount) { currentPrograms[midiEvent.channel] = midiEvent.parameter1; } } else //its the drum channel { if (midiEvent.parameter1 < synth.SoundBank.DrumCount) { currentPrograms[midiEvent.channel] = midiEvent.parameter1; } } break; case MidiHelper.MidiChannelEvent.Note_On: if (blockList.Contains(midiEvent.channel)) { return; } if (this.NoteOnEvent != null) { this.NoteOnEvent(midiEvent.channel, midiEvent.parameter1, midiEvent.parameter2); } synth.NoteOn(midiEvent.channel, midiEvent.parameter1, midiEvent.parameter2, currentPrograms[midiEvent.channel]); break; case MidiHelper.MidiChannelEvent.Note_Off: if (this.NoteOffEvent != null) { this.NoteOffEvent(midiEvent.channel, midiEvent.parameter1); } synth.NoteOff(midiEvent.channel, midiEvent.parameter1); break; case MidiHelper.MidiChannelEvent.Pitch_Bend: //Store PitchBend as the # of semitones higher or lower synth.TunePositions[midiEvent.channel] = (double)midiEvent.Parameters[1] * PitchWheelSemitoneRange; break; case MidiHelper.MidiChannelEvent.Controller: switch (midiEvent.GetControllerType()) { case MidiHelper.ControllerType.AllNotesOff: synth.NoteOffAll(true); break; case MidiHelper.ControllerType.MainVolume: synth.VolPositions[midiEvent.channel] = midiEvent.parameter2 / 127.0f; break; case MidiHelper.ControllerType.Pan: synth.PanPositions[midiEvent.channel] = (midiEvent.parameter2 - 64) == 63 ? 1.00f : (midiEvent.parameter2 - 64) / 64.0f; break; case MidiHelper.ControllerType.ResetControllers: ResetControllers(); break; default: break; } break; default: break; } } else { switch (midiEvent.midiMetaEvent) { case MidiHelper.MidiMetaEvent.Tempo: _MidiFile.BeatsPerMinute = MidiHelper.MicroSecondsPerMinute / System.Convert.ToUInt32(midiEvent.Parameters[0]); break; default: break; } } }