public void OpenPort(int portNumber, string portName) { try { RtMidi.rtmidi_open_port(handle, (uint)portNumber, portName); } finally { is_port_open = true; } }
public void OpenVirtualPort(string portName) { try { RtMidi.rtmidi_open_virtual_port(handle, portName); } finally { is_port_open = true; } }
public void SendMessage(byte [] message, int length) { if (message == null) { throw new ArgumentNullException("message"); } // While it could emit message parsing error, it still returns 0...! RtMidi.rtmidi_out_send_message(Handle, message, length); }
public byte [] GetMessage() { IntPtr ptr; int size = (int)RtMidi.rtmidi_in_get_message(Handle, out ptr); byte [] buf = new byte [size]; Marshal.Copy(ptr, buf, 0, size); return(buf); }
public void Close() { if (is_port_open) { is_port_open = false; RtMidi.rtmidi_close_port(handle); } ReleaseDevice(); }
public static RtMidiApi [] GetAvailableApis() { int enumSize = RtMidi.rtmidi_sizeof_rtmidi_api(); IntPtr ptr = IntPtr.Zero; int size = RtMidi.rtmidi_get_compiled_api(ref ptr); ptr = Marshal.AllocHGlobal(size * enumSize); RtMidi.rtmidi_get_compiled_api(ref ptr); RtMidiApi [] ret = new RtMidiApi [size]; switch (enumSize) { case 1: byte [] bytes = new byte [size]; Marshal.Copy(ptr, bytes, 0, bytes.Length); for (int i = 0; i < bytes.Length; i++) { ret [i] = (RtMidiApi)bytes [i]; } break; case 2: short [] shorts = new short [size]; Marshal.Copy(ptr, shorts, 0, shorts.Length); for (int i = 0; i < shorts.Length; i++) { ret [i] = (RtMidiApi)shorts [i]; } break; case 4: int [] ints = new int [size]; Marshal.Copy(ptr, ints, 0, ints.Length); for (int i = 0; i < ints.Length; i++) { ret [i] = (RtMidiApi)ints [i]; } break; case 8: long [] longs = new long [size]; Marshal.Copy(ptr, longs, 0, longs.Length); for (int i = 0; i < longs.Length; i++) { ret [i] = (RtMidiApi)longs [i]; } break; default: throw new NotSupportedException("sizeof RtMidiApi is unexpected: " + enumSize); } return(ret); }
protected override void ReleaseDevice() { RtMidi.rtmidi_out_free(Handle); }
public RtMidiOutputDevice(RtMidiApi api, string clientName) : base(RtMidi.rtmidi_out_create(api, clientName)) { }
public RtMidiOutputDevice() : base(RtMidi.rtmidi_out_create_default()) { }
public void SetIgnoredTypes(bool midiSysex, bool midiTime, bool midiSense) { RtMidi.rtmidi_in_ignore_types(Handle, midiSysex, midiTime, midiSense); }
public void CancelCallback() { RtMidi.rtmidi_in_cancel_callback(Handle); }
public void SetCallback(RtMidiCallback callback, IntPtr userData) { RtMidi.rtmidi_in_set_callback(Handle, callback, userData); }
public RtMidiInputDevice(RtMidiApi api, string clientName, int queueSizeLimit = 100) : base(RtMidi.rtmidi_in_create(api, clientName, (uint)queueSizeLimit)) { }
public RtMidiInputDevice() : base(RtMidi.rtmidi_in_create_default()) { }
public string GetPortName(int portNumber) { return(RtMidi.rtmidi_get_port_name(handle, (uint)portNumber)); }
// no idea when to use it... public static void Error(RtMidiErrorType errorType, string message) { RtMidi.rtmidi_error(errorType, message); }