public void InClose() { int shdr = Marshal.SizeOf(typeof(MidiHeader)); IntPtr nhdr = Marshal.AllocHGlobal(shdr); WinMM.midiInUnprepareHeader(inHandle, nhdr, shdr); WinMM.midiInReset(inHandle); WinMM.midiInStop(inHandle); WinMM.midiInClose(inHandle); }
private void GetInNames() { Console.WriteLine("In Devices: "); MidiInCaps caps = new MidiInCaps(); for (int i = 0; i < WinMM.midiInGetNumDevs(); i++) { WinMM.midiInGetDevCaps(i, ref caps, Marshal.SizeOf(typeof(MidiInCaps))); Console.WriteLine(caps.name); } }
public int OutOpen(string deviceName) { int result = -1; int deviceID = GetOutIdByName(deviceName); result = WinMM.midiOutOpen(ref outHandle, deviceID, null, 0, 0); if (result != 0) { throw new Exception("Cannot open OUT device " + deviceName); } return(result); }
public int SendMidi(byte[] midi) { int result = -1; int msg = BitConverter.ToInt32(midi, 0); // convert byte[] to int result = WinMM.midiOutShortMsg(outHandle, msg); // sending message if (result != 0) { throw new Exception("Cannot send short message"); } AfterShortSent?.Invoke(midi); // if not null Invoke return(result); }
public int InOpen(string deviceName) { int result = -1; int deviceID = GetInIdByName(deviceName); IntPtr pointer = Marshal.GetIUnknownForObject(this); midiProc = new MidiProc(CallBack); result = WinMM.midiInOpen(ref inHandle, deviceID, midiProc, pointer, CALLBACK_FUNCTION); if (result != 0) { throw new Exception("MidiInOpen failed with code: " + result + ". Cannot open IN device " + deviceName); } AddSysexBuffer(); result = WinMM.midiInStart(inHandle); if (result != 0) { throw new Exception("Cannot start IN device " + deviceName); } return(result); }
private int GetOutIdByName(string deviceName) { MidiOutCaps caps = new MidiOutCaps(); int deviceID = -1; int num = WinMM.midiOutGetNumDevs(); for (int i = 0; i < num; i++) { WinMM.midiOutGetDevCaps(i, ref caps, Marshal.SizeOf(typeof(MidiOutCaps))); if (caps.name == deviceName) { deviceID = i; break; } } if (deviceID == -1) { throw new Exception("Midi OUT device " + deviceName + " not found"); } return(deviceID); }
private int AddSysexBuffer() { int result = -1; int shdr = Marshal.SizeOf(typeof(MidiHeader)); IntPtr nhdr = Marshal.AllocHGlobal(shdr); header = new MidiHeader(); header.bufferLength = header.bytesRecorded = 128; header.bytesRecorded = 0; header.data = Marshal.AllocHGlobal(128); header.flags = 0; Marshal.StructureToPtr(header, nhdr, false); result = WinMM.midiInPrepareHeader(inHandle, nhdr, shdr); if (result != 0) { throw new Exception("Cannot prepare IN header"); } result = WinMM.midiInAddBuffer(inHandle, nhdr, shdr); if (result != 0) { throw new Exception("Cannot add IN buffer"); } return(result); }
public void OutClose() { WinMM.midiOutClose(outHandle); }