private void OnMidiMessage(object sender, MidiInMessageEventArgs evt) { if (evt.MidiEvent.CommandCode != MidiCommandCode.NoteOn || evt.MidiEvent.CommandCode == MidiCommandCode.NoteOff) { return; // Ignore non note events } NoteEvent noteEvent = evt.MidiEvent as NoteEvent; string noteName = MidiUtils.GetNoteNameFromMidiNoteNumber(noteEvent.NoteNumber); if (noteEvent.Velocity != 0 && evt.MidiEvent.CommandCode == MidiCommandCode.NoteOn) { _onNoteOnListener(noteName, noteEvent.Velocity); } else { _onNoteOffListener(noteName); } }