Example #1
0
        private void InputCallback(Win32Api.Api.HandleMidiIn hMidiIn, Win32Api.Api.MidiInMessage wMsg, UIntPtr dwInstance, UIntPtr dwParam1, UIntPtr dwParam2)
        {
            isInsideInputHandler = true;
            try
            {
                if (wMsg == Win32Api.Api.MidiInMessage.MIM_DATA)
                {
                    ShortMessage.DecodeMessage(dwParam1, out Channel channel, out UInt7 note, out UInt7 velocity);

                    if (ShortMessage.IsNoteOn(dwParam1))
                    {
                        this.NoteOn?.Invoke(new MidiMessage(this, channel, note, velocity));
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
            finally
            {
                isInsideInputHandler = false;
            }
        }