예제 #1
0
        public MidiPort CreateOutputPort(string name)
        {
            MIDIPortRef port;

            CoreMidiInterop.MIDIOutputPortCreate(Handle, Midi.ToCFStringRef(name), out port);
            return(new MidiPort(port, true));
        }
예제 #2
0
        public MidiEndpoint CreateVirtualSource(string name, out MidiError statusCode)
        {
            IntPtr ptr;

            statusCode = (MidiError)CoreMidiInterop.MIDISourceCreate(Handle, Midi.ToCFStringRef(name), out ptr);
            return(statusCode == MidiError.Ok ? new MidiEndpoint(ptr, name, true, null) : null);
        }
예제 #3
0
        int GetIntegerProp(IntPtr id)
        {
            int ret;

            CoreMidiInterop.MIDIObjectGetIntegerProperty(Handle, id, out ret);
            return(ret);
        }
예제 #4
0
        String GetStringProp(IntPtr id)
        {
            if (id == IntPtr.Zero)
            {
                return(null);
            }

            CFStringRef str;

            CoreMidiInterop.MIDIObjectGetStringProperty(Handle, id, out str);
            var cstr = CoreFoundationInterop.CFStringGetCStringPtr(str, CoreFoundationInterop.kCFStringEncodingUTF8);

            unsafe {
                if (cstr == IntPtr.Zero)
                {
                    return(null);
                }
                byte *p     = (byte *)cstr;
                int   count = 0;
                for (byte *i = p; *i != 0; i++)
                {
                    count++;
                }
                return(System.Text.Encoding.UTF8.GetString((byte *)cstr, count));
            }
        }
예제 #5
0
        public MidiClient(string name)
        {
            IntPtr h;

            name_string = Midi.ToCFStringRef(name);
            CoreMidiInterop.MIDIClientCreate(name_string, OnNotify, IntPtr.Zero, out h);
            Handle = h;
        }
예제 #6
0
 public void Dispose()
 {
     if (should_dispose)
     {
         CoreMidiInterop.MIDIPortDispose(Handle);
         should_dispose = false;
     }
 }
예제 #7
0
        public MidiEndpoint CreateVirtualDestination(string name, out MidiError statusCode)
        {
            IntPtr ptr;
            var    d = new ReadDispatcher();

            statusCode = (MidiError)CoreMidiInterop.MIDIDestinationCreate(Handle, Midi.ToCFStringRef(name),
                                                                          d.DispatchProc, IntPtr.Zero, out ptr);
            return(statusCode == MidiError.Ok ? new MidiEndpoint(ptr, name, true, d) : null);
        }
예제 #8
0
        public MidiPort CreateInputPort(string name)
        {
            MIDIPortRef port;
            var         d = new ReadDispatcher();

            CoreMidiInterop.MIDIInputPortCreate(Handle, Midi.ToCFStringRef(name), d.DispatchRead, IntPtr.Zero, out port);
            d.Port = new MidiPort(port, true);
            return(d.Port);
        }
 public void Dispose()
 {
     CoreMidiInterop.MIDIClientDispose(Handle);
     if (name_string != IntPtr.Zero)
     {
         CoreFoundationInterop.CFRelease(name_string);
     }
     name_string = IntPtr.Zero;
 }
예제 #10
0
        void SetStringProp(IntPtr id, string value)
        {
            if (id == IntPtr.Zero)
            {
                return;
            }
            CFStringRef str;

            CoreMidiInterop.MIDIObjectSetStringProperty(Handle, id, Midi.ToCFStringRef(value));
        }
예제 #11
0
        public MidiClient(string name)
        {
            IntPtr h;

            name_string = Midi.ToCFStringRef(name);
            int ret = CoreMidiInterop.MIDIClientCreate(name_string, null, IntPtr.Zero, out h);

            if (ret != 0)
            {
                throw new MidiException($"Failed to create MIDI client for {name}: error code {ret}");
            }
            Handle = h;
        }
예제 #12
0
        public void Dispose()
        {
            if (list != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(list);
                list = IntPtr.Zero;
            }

            if (should_dispose)
            {
                CoreMidiInterop.MIDIPortDispose(Handle);
                should_dispose = false;
            }
        }
예제 #13
0
        public void Send(MidiEndpoint endpoint, MidiPacket [] arr)
        {
            var list = Marshal.AllocHGlobal(Marshal.SizeOf <MidiPacketListNative> ());

            try {
                var p = CoreMidiInterop.MIDIPacketListInit(list);
                foreach (var item in arr)
                {
                    p = CoreMidiInterop.MIDIPacketListAdd(list, arr.Length, p, item.TimeStamp, item.Length, item.Bytes);
                }
                CoreMidiInterop.MIDISend(Handle, endpoint.Handle, list);
            } finally {
                Marshal.FreeHGlobal(list);
            }
        }
예제 #14
0
        public void CallMessageReceived(MIDIPacketListPtr pktlist, IntPtr readProcRefCon, IntPtr srcConnRefCon)
        {
            if (MessageReceived == null)
            {
                return;
            }
            var packets = new List <MidiPacket> ();

            for (var p = CoreMidiInterop.MIDIPacketListInit(pktlist);
                 p != IntPtr.Zero;
                 p = CoreMidiInterop.MIDIPacketNext(p))
            {
                var packet = Marshal.PtrToStructure <MIDIPacketNative> (p);
                packets.Add(new MidiPacket(packet.TimeStamp, packet.Length, packet.Data));
            }
            MessageReceived(this, new MidiPacketsEventArgs {
                Packets = packets.ToArray()
            });
        }
예제 #15
0
        public void CallMessageReceived(MIDIPacketListPtr pktlist, IntPtr readProcRefCon, IntPtr srcConnRefCon)
        {
            if (MessageReceived == null)
            {
                return;
            }
            var packets = new List <MidiPacket> ();
            var list    = Marshal.PtrToStructure <MidiPacketListNative> (pktlist);
            var p       = pktlist + 4;

            for (int i = 0; i < list.NumPackets; i++)
            {
                var packet = Marshal.PtrToStructure <MIDIPacketNative> (p);
                packets.Add(new MidiPacket(packet.TimeStamp, packet.Length, p + 10));
                p = CoreMidiInterop.MIDIPacketNext(p);
            }
            MessageReceived(this, new MidiPacketsEventArgs {
                Packets = packets.ToArray()
            });
        }
예제 #16
0
        public void Send(MidiEndpoint endpoint, MidiPacket [] arr)
        {
            var msize = Marshal.SizeOf <MIDIPacketNative> ();
            var size  = arr.Select(a => msize + a.Length).Sum();

            if (list == IntPtr.Zero || size > buf_size)
            {
                if (list != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(list);
                }
                list = Marshal.AllocHGlobal(buf_size);
            }

            var p = CoreMidiInterop.MIDIPacketListInit(list);

            foreach (var item in arr)
            {
                p = CoreMidiInterop.MIDIPacketListAdd(list, 1024, p, item.TimeStamp, item.Length, item.Bytes);
            }
            CoreMidiInterop.MIDISend(Handle, endpoint.Handle, list);
        }
예제 #17
0
 public MidiEntity GetEntity(nint e)
 {
     return(new MidiEntity(CoreMidiInterop.MIDIDeviceGetEntity(device, e)));
 }
예제 #18
0
 public static MidiDevice GetDevice(nint d) => new MidiDevice(CoreMidiInterop.MIDIGetDevice(d));
예제 #19
0
 public void Dispose()
 {
     CoreMidiInterop.MIDIClientDispose(Handle);
     CoreFoundationInterop.CFRelease(name_string);
 }
예제 #20
0
 void SetIntegerProp(IntPtr id, int value)
 {
     CoreMidiInterop.MIDIObjectSetIntegerProperty(Handle, id, value);
 }
예제 #21
0
 public static MidiEndpoint GetSource(nint s) => new MidiEndpoint(CoreMidiInterop.MIDIGetSource(s), "Source" + s, false);
예제 #22
0
 public void ConnectSource(MidiEndpoint endpoint) => CoreMidiInterop.MIDIPortConnectSource(Handle, endpoint.Handle, IntPtr.Zero);
예제 #23
0
 public void Disconnect(MidiEndpoint endpoint) => CoreMidiInterop.MIDIPortDisconnectSource(Handle, endpoint.Handle);
        public static MidiEndpoint GetDestination(nint d)
        {
            var ret = CoreMidiInterop.MIDIGetDestination(d);

            return(ret == IntPtr.Zero ? null : new MidiEndpoint(ret, "Destination" + d, false, null));
        }
예제 #25
0
 public static MidiEndpoint GetDestination(nint d) => new MidiEndpoint(CoreMidiInterop.MIDIGetDestination(d), "Destination" + d, false);
        public static MidiEndpoint GetSource(nint s)
        {
            var ret = CoreMidiInterop.MIDIGetSource(s);

            return(ret == IntPtr.Zero ? null : new MidiEndpoint(ret, "Source" + s, false, null));
        }