void HandleMidiInProc(IntPtr midiIn, MidiInMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
        {
            if (MessageReceived != null)
            {
                switch (msg)
                {
                case MidiInMessage.Data:
                    HandleData(param1, param2);
                    break;

                case MidiInMessage.LongData:
                    HandleLongData(param1, param2);
                    break;

                case MidiInMessage.MoreData:
                    // TODO input too slow, handle.
                    break;

                case MidiInMessage.Error:
                    throw new InvalidOperationException($"Invalid MIDI message: {param1}");

                case MidiInMessage.LongError:
                    throw new InvalidOperationException("Invalid SysEx message.");

                default:
                    break;
                }
            }
        }
        private void MidiInProc(HMIDIIN hMidiIn, MidiInMessage wMsg, IntPtr dwInstance, IntPtr dwParam1, IntPtr dwParam2)
        {
            switch (wMsg)
            {
            case MidiInMessage.MIM_DATA:
                HandleMidiData(dwParam1, dwParam2);
                break;

            case MidiInMessage.MIM_LONGDATA:
                HandleLongData(dwParam1, dwParam2);
                break;

            case MidiInMessage.MIM_MOREDATA:
                // doesn't happen, since we don't use the IO_STATUS flag
                break;

            case MidiInMessage.MIM_ERROR:
                throw new InvalidOperationException($"Invalid MIDI message: {dwParam1}");

            case MidiInMessage.MIM_LONGERROR:
                throw new InvalidOperationException("Invalid SysEx message.");

            default:
                break;
            }
        }
Exemple #3
0
        private void InputCallback(HMIDIIN hMidiIn, MidiInMessage wMsg,
                                   UIntPtr dwInstance, UIntPtr dwParam1, UIntPtr dwParam2)
        {
            _isInsideInputHandler = true;
            try
            {
                switch (wMsg)
                {
                case MidiInMessage.MIM_DATA:
                {
                    HandleInputMimData(dwParam1, dwParam2);
                    break;
                }

                case MidiInMessage.MIM_LONGDATA:
                {
                    HandleInputMimLongData(dwParam1, dwParam2);
                }
                break;

                case MidiInMessage.MIM_MOREDATA:
                    SysEx?.Invoke(new SysExMessage(this, new byte[] { 0x13 }, 13));
                    break;

                case MidiInMessage.MIM_OPEN:
                    //SysEx(new SysExMessage(this, new byte[] { 0x01 }, 1));
                    break;

                case MidiInMessage.MIM_CLOSE:
                    //SysEx(new SysExMessage(this, new byte[] { 0x02 }, 2));
                    break;

                case MidiInMessage.MIM_ERROR:
                    SysEx?.Invoke(new SysExMessage(this, new byte[] { 0x03 }, 3));
                    break;

                case MidiInMessage.MIM_LONGERROR:
                    SysEx?.Invoke(new SysExMessage(this, new byte[] { 0x04 }, 4));
                    break;

                default:
                    SysEx?.Invoke(new SysExMessage(this, new byte[] { 0x05 }, 5));
                    break;
                }
            }
            finally
            {
                _isInsideInputHandler = false;
            }
        }
Exemple #4
0
 private void Callback(IntPtr midiInHandle, MidiInMessage message, IntPtr userData, IntPtr messageParameter1, IntPtr messageParameter2)
 {
     switch (message)
     {
         case MidiInMessage.Open:
             // message Parameter 1 & 2 are not used
             break;
         case MidiInMessage.Data:
             // parameter 1 is packed MIDI message
             // parameter 2 is milliseconds since MidiInStart
             if (MessageReceived != null)
             {
                 MessageReceived(this, new MidiInMessageEventArgs(messageParameter1.ToInt32(), messageParameter2.ToInt32()));
             }
             break;
         case MidiInMessage.Error:
             // parameter 1 is invalid MIDI message
             if (ErrorReceived != null)
             {
                 ErrorReceived(this, new MidiInMessageEventArgs(messageParameter1.ToInt32(), messageParameter2.ToInt32()));
             }
             break;
         case MidiInMessage.Close:
             // message Parameter 1 & 2 are not used
             break;
         case MidiInMessage.LongData:
             // parameter 1 is pointer to MIDI header
             // parameter 2 is milliseconds since MidiInStart
             /*
             Me.MIDIInHdr.lpData = Me.ddd
     Me.MIDIInHdr.dwBufferLength = Len(Me.ddd)
     Me.MIDIInHdr.dwFlags = 0
     Err = midiInPrepareHeader(hMidiIn, Me.MIDIInHdr, Len(Me.MIDIInHdr))
     If Err <> C_MMSYSERR_NOERROR Then
     Me.pLastError = Err
     Debug.WriteLine(CStr(Err))
     End If
     Err = midiInAddBuffer(hMidiIn, Me.MIDIInHdr, Len(Me.MIDIInHdr))
     If Err <> C_MMSYSERR_NOERROR Then
     Me.pLastError = Err
     Debug.WriteLine(CStr(Err))
     End If*/
             break;
         case MidiInMessage.LongError:
             // parameter 1 is pointer to MIDI header
             // parameter 2 is milliseconds since MidiInStart
             break;
         case MidiInMessage.MoreData:
             // parameter 1 is packed MIDI message
             // parameter 2 is milliseconds since MidiInStart
             break;
     }
 }