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; } }
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; } }
public MidiInputLongDataBuffer(HMIDIIN inputHandle, int bufferSize = 4096) { _inputHandle = inputHandle; var header = new MIDIHDR() { lpData = Marshal.AllocHGlobal(bufferSize), dwBufferLength = (uint)bufferSize, }; try { Ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MIDIHDR>()); Marshal.StructureToPtr(header, Ptr, false); } catch { Free(); throw; } }
public static extern MMRESULT midiInStop(HMIDIIN hMidiIn);
/// <summary> /// Opens a MIDI input device. /// </summary> /// NOTE: This is adapted from the original Win32 function in order to make it typesafe. /// /// Win32 docs: http://msdn.microsoft.com/en-us/library/ms711610(VS.85).aspx public static MMRESULT midiInOpen(out HMIDIIN lphMidiIn, UIntPtr uDeviceID, MidiInProc dwCallback, UIntPtr dwCallbackInstance) { return(midiInOpen(out lphMidiIn, uDeviceID, dwCallback, dwCallbackInstance, dwCallback == null ? MidiOpenFlags.CALLBACK_NULL : MidiOpenFlags.CALLBACK_FUNCTION)); }
public static extern MMRESULT midiInUnprepareHeader(HMIDIIN hMidiIn, IntPtr headerPtr, UInt32 cbMidiInHdr);
public static extern MMRESULT midiInReset(HMIDIIN hMidiIn);
public static extern MMRESULT midiInClose(HMIDIIN hMidiIn);
private static extern MMRESULT midiInOpen(out HMIDIIN lphMidiIn, UIntPtr uDeviceID, MidiInProc dwCallback, UIntPtr dwCallbackInstance, MidiOpenFlags dwFlags);
public static extern uint midiInReset(HMIDIIN hmi);
public static extern uint midiInStop(HMIDIIN hmi);
public static extern uint midiInAddBuffer(HMIDIIN hmi, [NativeTypeName("LPMIDIHDR")] MIDIHDR *pmh, uint cbmh);
public static extern uint midiInUnprepareHeader(HMIDIIN hmi, [NativeTypeName("LPMIDIHDR")] MIDIHDR *pmh, uint cbmh);
public static extern uint midiInClose(HMIDIIN hmi);
public static extern uint midiInGetID(HMIDIIN hmi, [NativeTypeName("LPUINT")] uint *puDeviceID);
public static extern MMRESULT midiInAddBuffer(HMIDIIN hMidiIn, IntPtr lpMidiInHdr, UInt32 cbMidiInHdr);
public static extern uint midiInMessage(HMIDIIN hmi, uint uMsg, [NativeTypeName("DWORD_PTR")] nuint dw1, [NativeTypeName("DWORD_PTR")] nuint dw2);
/// <summary> /// Opens a MIDI input device. /// </summary> /// NOTE: This is adapted from the original Win32 function in order to make it typesafe. /// /// Win32 docs: http://msdn.microsoft.com/en-us/library/ms711610(VS.85).aspx public static MMRESULT midiInOpen(out HMIDIIN lphMidiIn, UIntPtr uDeviceID, MidiInProc dwCallback, UIntPtr dwCallbackInstance) { return midiInOpen(out lphMidiIn, uDeviceID, dwCallback, dwCallbackInstance, dwCallback == null ? MidiOpenFlags.CALLBACK_NULL : MidiOpenFlags.CALLBACK_FUNCTION); }
public static extern MMRESULT midiInPrepareHeader(HMIDIIN hMidiIn, IntPtr headerPtr, uint cbMidiInHdr);