public MidiPort CreateOutputPort(string name) { MIDIPortRef port; CoreMidiInterop.MIDIOutputPortCreate(Handle, Midi.ToCFStringRef(name), out port); return(new MidiPort(port, true)); }
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); }
int GetIntegerProp(IntPtr id) { int ret; CoreMidiInterop.MIDIObjectGetIntegerProperty(Handle, id, out ret); return(ret); }
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)); } }
public MidiClient(string name) { IntPtr h; name_string = Midi.ToCFStringRef(name); CoreMidiInterop.MIDIClientCreate(name_string, OnNotify, IntPtr.Zero, out h); Handle = h; }
public void Dispose() { if (should_dispose) { CoreMidiInterop.MIDIPortDispose(Handle); should_dispose = false; } }
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); }
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; }
void SetStringProp(IntPtr id, string value) { if (id == IntPtr.Zero) { return; } CFStringRef str; CoreMidiInterop.MIDIObjectSetStringProperty(Handle, id, Midi.ToCFStringRef(value)); }
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; }
public void Dispose() { if (list != IntPtr.Zero) { Marshal.FreeHGlobal(list); list = IntPtr.Zero; } if (should_dispose) { CoreMidiInterop.MIDIPortDispose(Handle); should_dispose = false; } }
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); } }
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() }); }
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() }); }
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); }
public MidiEntity GetEntity(nint e) { return(new MidiEntity(CoreMidiInterop.MIDIDeviceGetEntity(device, e))); }
public static MidiDevice GetDevice(nint d) => new MidiDevice(CoreMidiInterop.MIDIGetDevice(d));
public void Dispose() { CoreMidiInterop.MIDIClientDispose(Handle); CoreFoundationInterop.CFRelease(name_string); }
void SetIntegerProp(IntPtr id, int value) { CoreMidiInterop.MIDIObjectSetIntegerProperty(Handle, id, value); }
public static MidiEndpoint GetSource(nint s) => new MidiEndpoint(CoreMidiInterop.MIDIGetSource(s), "Source" + s, false);
public void ConnectSource(MidiEndpoint endpoint) => CoreMidiInterop.MIDIPortConnectSource(Handle, endpoint.Handle, IntPtr.Zero);
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)); }
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)); }