164 lines
6.3 KiB
C#
164 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RushMidiLibrary {
|
|
public static class MidiApiWindows {
|
|
[DllImport("winmm.dll")]
|
|
public static extern uint midiOutGetNumDevs();
|
|
[DllImport("winmm.dll")]
|
|
public static extern uint midiInGetNumDevs();
|
|
|
|
public enum MMRESULT : uint {
|
|
MMSYSERR_BASE = 0,
|
|
MMSYSERR_NOERROR = MMSYSERR_BASE + 0,
|
|
MMSYSERR_ERROR = MMSYSERR_BASE + 1,
|
|
MMSYSERR_BADDEVICEID = MMSYSERR_BASE + 2,
|
|
MMSYSERR_NOTENABLED = MMSYSERR_BASE + 3,
|
|
MMSYSERR_ALLOCATED = MMSYSERR_BASE + 4,
|
|
MMSYSERR_INVALHANDLE = MMSYSERR_BASE + 5,
|
|
MMSYSERR_NODRIVER = MMSYSERR_BASE + 6,
|
|
MMSYSERR_NOMEM = MMSYSERR_BASE + 7,
|
|
MMSYSERR_NOTSUPPORTED = MMSYSERR_BASE + 8,
|
|
MMSYSERR_BADERRNUM = MMSYSERR_BASE + 9,
|
|
MMSYSERR_INVALFLAG = MMSYSERR_BASE + 10,
|
|
MMSYSERR_INVALPARAM = MMSYSERR_BASE + 11,
|
|
MMSYSERR_HANDLEBUSY = MMSYSERR_BASE + 12,
|
|
MMSYSERR_INVALIDALIAS = MMSYSERR_BASE + 13,
|
|
MMSYSERR_BADDB = MMSYSERR_BASE + 14,
|
|
MMSYSERR_KEYNOTFOUND = MMSYSERR_BASE + 15,
|
|
MMSYSERR_READERROR = MMSYSERR_BASE + 16,
|
|
MMSYSERR_WRITEERROR = MMSYSERR_BASE + 17,
|
|
MMSYSERR_DELETEERROR = MMSYSERR_BASE + 18,
|
|
MMSYSERR_VALNOTFOUND = MMSYSERR_BASE + 19,
|
|
MMSYSERR_NODRIVERCB = MMSYSERR_BASE + 20,
|
|
MMSYSERR_MOREDATA = MMSYSERR_BASE + 21,
|
|
MMSYSERR_LASTERROR = MMSYSERR_BASE + 21,
|
|
|
|
|
|
MIDIERR_BASE = 64,
|
|
MIDIERR_UNPREPARED = MIDIERR_BASE + 0,
|
|
MIDIERR_STILLPLAYING = MIDIERR_BASE + 1,
|
|
MIDIERR_NOMAP = MIDIERR_BASE + 2,
|
|
MIDIERR_NOTREADY = MIDIERR_BASE + 3,
|
|
MIDIERR_NODEVICE = MIDIERR_BASE + 4,
|
|
MIDIERR_INVALIDSETUP = MIDIERR_BASE + 5,
|
|
MIDIERR_BADOPENMODE = MIDIERR_BASE + 6,
|
|
MIDIERR_DONT_CONTINUE = MIDIERR_BASE + 7,
|
|
MIDIERR_LASTERROR = MIDIERR_BASE + 7
|
|
}
|
|
|
|
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInGetErrorText(MMRESULT errCode, StringBuilder message, uint sizeOfMessage);
|
|
|
|
public static MMRESULT midiInGetErrorText(MMRESULT mmrError, StringBuilder lpText) {
|
|
return midiInGetErrorText(mmrError, lpText, (UInt32)lpText.Capacity);
|
|
}
|
|
|
|
|
|
|
|
[DllImport("winmm.dll")]
|
|
private static extern MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, out MIDIINCAPS caps, uint sizeOfMidiInCaps);
|
|
public static MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, out MIDIINCAPS caps) {
|
|
return midiInGetDevCaps(uDeviceID, out caps, (uint)Marshal.SizeOf<MIDIINCAPS>());
|
|
}
|
|
|
|
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInOpen(out HMIDIIN phmi, UIntPtr uDeviceID, MidiInProc dwCallback, UIntPtr dwInstance, MidiOpenFlags fdwOpen);
|
|
|
|
public static MMRESULT midiInOpen(out HMIDIIN phmi, UIntPtr uDeviceID, MidiInProc dwCallback, UIntPtr dwInstance) {
|
|
return midiInOpen(out phmi, uDeviceID, dwCallback, dwInstance, dwCallback == null ? MidiOpenFlags.CALLBACK_NULL : MidiOpenFlags.CALLBACK_FUNCTION);
|
|
}
|
|
|
|
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInClose(HMIDIIN hmi);
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInStart(HMIDIIN hmi);
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInStop(HMIDIIN hmi);
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInReset(HMIDIIN hmi);
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInAddBuffer(HMIDIIN hmi, ref MIDIHDR lpMidiHeader, uint wSize);
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInPrepareHeader(HMIDIIN handle, ref MIDIHDR lpMidiHeader, uint wSize);
|
|
[DllImport("winmm.dll")]
|
|
public static extern MMRESULT midiInUnprepareHeader(HMIDIIN handle, ref MIDIHDR lpMidiHeader, uint wSize);
|
|
|
|
|
|
[DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi)]
|
|
public static extern void GetSystemTimePreciseAsFileTime(out long filetime);
|
|
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
|
public delegate void MidiInProc(HMIDIIN handle, MidiInMessage wMsg, UIntPtr dwInstance, UIntPtr dwParam1, UIntPtr dwParam2);
|
|
|
|
|
|
public struct HMIDIIN {
|
|
public IntPtr handle;
|
|
}
|
|
|
|
public struct HMIDIOUT {
|
|
public IntPtr handle;
|
|
}
|
|
|
|
public enum MidiInMessage : uint {
|
|
MIM_OPEN = 0x3C1,
|
|
MIM_CLOSE = 0x3C2,
|
|
MIM_DATA = 0x3C3,
|
|
MIM_LONGDATA = 0x3C4,
|
|
MIM_ERROR = 0x3C5,
|
|
MIM_LONGERROR = 0x3C6,
|
|
MIM_MOREDATA = 0x3CC
|
|
}
|
|
|
|
public enum MidiOpenFlags : uint {
|
|
CALLBACK_TYPEMASK = 0x70000,
|
|
CALLBACK_NULL = 0x00000,
|
|
CALLBACK_WINDOW = 0x10000,
|
|
CALLBACK_TASK = 0x20000,
|
|
CALLBACK_FUNCTION = 0x30000,
|
|
CALLBACK_THREAD = CALLBACK_TASK,
|
|
CALLBACK_EVENT = 0x50000,
|
|
MIDI_IO_STATUS = 0x00020
|
|
}
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MIDIINCAPS {
|
|
public ushort wMid;
|
|
public ushort wPid;
|
|
public uint vDriverVersion;
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
public string szPname;
|
|
public uint dwSupport;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MIDIHDR {
|
|
public UIntPtr lpData;
|
|
public uint dwBufferLength;
|
|
public uint dwBytesRecorded;
|
|
public UIntPtr dwUser;
|
|
public uint dwFlags;
|
|
public UIntPtr lpNext;
|
|
public UIntPtr reserved;
|
|
public uint dwOffset;
|
|
public UIntPtr dwReserved0;
|
|
public UIntPtr dwReserved1;
|
|
public UIntPtr dwReserved2;
|
|
public UIntPtr dwReserved3;
|
|
public UIntPtr dwReserved4;
|
|
public UIntPtr dwReserved5;
|
|
public UIntPtr dwReserved6;
|
|
public UIntPtr dwReserved7;
|
|
}
|
|
}
|
|
}
|