예제 #1
0
 public void OpenPort(int portNumber, string portName)
 {
     try {
         RtMidi.rtmidi_open_port(handle, (uint)portNumber, portName);
     } finally {
         is_port_open = true;
     }
 }
예제 #2
0
 public void OpenVirtualPort(string portName)
 {
     try {
         RtMidi.rtmidi_open_virtual_port(handle, portName);
     } finally {
         is_port_open = true;
     }
 }
예제 #3
0
 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);
 }
예제 #4
0
        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);
        }
예제 #5
0
 public void Close()
 {
     if (is_port_open)
     {
         is_port_open = false;
         RtMidi.rtmidi_close_port(handle);
     }
     ReleaseDevice();
 }
예제 #6
0
        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);
        }
예제 #7
0
 protected override void ReleaseDevice()
 {
     RtMidi.rtmidi_out_free(Handle);
 }
예제 #8
0
 public RtMidiOutputDevice(RtMidiApi api, string clientName)
     : base(RtMidi.rtmidi_out_create(api, clientName))
 {
 }
예제 #9
0
 public RtMidiOutputDevice()
     : base(RtMidi.rtmidi_out_create_default())
 {
 }
예제 #10
0
 public void SetIgnoredTypes(bool midiSysex, bool midiTime, bool midiSense)
 {
     RtMidi.rtmidi_in_ignore_types(Handle, midiSysex, midiTime, midiSense);
 }
예제 #11
0
 public void CancelCallback()
 {
     RtMidi.rtmidi_in_cancel_callback(Handle);
 }
예제 #12
0
 public void SetCallback(RtMidiCallback callback, IntPtr userData)
 {
     RtMidi.rtmidi_in_set_callback(Handle, callback, userData);
 }
예제 #13
0
 public RtMidiInputDevice(RtMidiApi api, string clientName, int queueSizeLimit = 100)
     : base(RtMidi.rtmidi_in_create(api, clientName, (uint)queueSizeLimit))
 {
 }
예제 #14
0
 public RtMidiInputDevice()
     : base(RtMidi.rtmidi_in_create_default())
 {
 }
예제 #15
0
 public string GetPortName(int portNumber)
 {
     return(RtMidi.rtmidi_get_port_name(handle, (uint)portNumber));
 }
예제 #16
0
 // no idea when to use it...
 public static void Error(RtMidiErrorType errorType, string message)
 {
     RtMidi.rtmidi_error(errorType, message);
 }