Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/CoreMidi/MidiCIDeviceIdentification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using ObjCRuntime;
using CoreFoundation;
using Foundation;

namespace CoreMidi {

[NoWatch, NoTV, Mac (10,14, onlyOn64: true), iOS (12,0)]
[StructLayout (LayoutKind.Sequential)]
public struct MidiCIDeviceIdentification {
public byte[] Manufacturer;
public byte[] Family;
public byte[] ModelNumber;
public byte[] RevisionLevel;
public byte[] Reserved;
}
}
108 changes: 108 additions & 0 deletions src/CoreMidi/MidiServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
using MidiObjectRef = System.Int32;
using MidiClientRef = System.Int32;
using MidiDeviceRef = System.Int32;
using MidiDeviceListRef = System.Int32;
using MidiPortRef = System.Int32;
using MidiEndpointRef = System.Int32;
using MidiEntityRef = System.Int32;
Expand Down Expand Up @@ -221,6 +222,9 @@ public class MidiObject
internal static IntPtr kMIDIPropertyTransmitsNotes;
internal static IntPtr kMIDIPropertyTransmitsProgramChanges;
internal static IntPtr kMIDIPropertyUniqueID;
internal static IntPtr kMIDIDriverPropertyUsesSerial;
internal static IntPtr kMIDIPropertyFactoryPatchNameFile;
internal static IntPtr kMIDIPropertyUserPatchNameFile;

static MidiObject ()
{
Expand Down Expand Up @@ -273,6 +277,9 @@ static MidiObject ()
kMIDIPropertyTransmitsNotes = Dlfcn.GetIntPtr (midiLibrary, "kMIDIPropertyTransmitsNotes");
kMIDIPropertyTransmitsProgramChanges = Dlfcn.GetIntPtr (midiLibrary, "kMIDIPropertyTransmitsProgramChanges");
kMIDIPropertyUniqueID = Dlfcn.GetIntPtr (midiLibrary, "kMIDIPropertyUniqueID");
kMIDIDriverPropertyUsesSerial = Dlfcn.GetIntPtr (midiLibrary, "kMIDIDriverPropertyUsesSerial");
kMIDIPropertyFactoryPatchNameFile = Dlfcn.GetIntPtr (midiLibrary, "kMIDIPropertyFactoryPatchNameFile");
kMIDIPropertyUserPatchNameFile = Dlfcn.GetIntPtr (midiLibrary, "kMIDIPropertyUserPatchNameFile");
}

#if XAMCORE_2_0
Expand Down Expand Up @@ -1446,6 +1453,10 @@ public class MidiDevice : MidiObject {
[DllImport (Constants.CoreMidiLibrary)]
extern static MidiEntityRef MIDIDeviceGetEntity (MidiDeviceRef handle, nint item);

[NoiOS]
[DllImport (Constants.CoreMidiLibrary)]
extern static int MIDIDeviceAddEntity (MidiDeviceRef device, /* CFString */ IntPtr name, bool embedded, nuint numSourceEndpoints, nuint numDestinationEndpoints, MidiEntityRef newEntity);

public MidiEntity GetEntity (nint entityIndex)
{
if (handle == MidiObject.InvalidRef)
Expand All @@ -1456,6 +1467,16 @@ public MidiEntity GetEntity (nint entityIndex)
return new MidiEntity (h);
}

[NoiOS]
public int Add (string name, bool embedded, nuint numSourceEndpoints, nuint numDestinationEndpoints, MidiEntity newEntity)
{
if (handle == MidiObject.InvalidRef)
throw new ObjectDisposedException ("handle");
using (NSString nsName = new NSString (name)) {
return MIDIDeviceAddEntity (handle, nsName.Handle, embedded, numSourceEndpoints, numDestinationEndpoints, newEntity.Handle);
}
}

public nint EntityCount {
get {
return MIDIDeviceGetNumberOfEntities (handle);
Expand Down Expand Up @@ -1498,6 +1519,34 @@ public int UniqueID {
}
}

public bool UsesSerial {
get {
return GetInt (kMIDIDriverPropertyUsesSerial) != 0;
}
set {
SetInt (kMIDIDriverPropertyUsesSerial, value ? 1 : 0);
}
}

public string FactoryPatchNameFile {
get {
return GetString (kMIDIPropertyFactoryPatchNameFile);
}
set {
SetString (kMIDIPropertyFactoryPatchNameFile, value);
}
}

public string UserPatchNameFile {
get {
return GetString (kMIDIPropertyUserPatchNameFile);
}
set {
SetString (kMIDIPropertyUserPatchNameFile, value);
}
}


public int AdvanceScheduleTimeMuSec {
get {
return GetInt (kMIDIPropertyAdvanceScheduleTimeMuSec);
Expand Down Expand Up @@ -1838,6 +1887,65 @@ internal MidiDevice (MidiDeviceRef handle) : base (handle)
internal MidiDevice (MidiDeviceRef handle, bool owns) : base (handle, owns)
{
}
#endif // !COREBUILD
}

public class MidiDeviceList : MidiObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mandel-macaque: How can customers use this class? There are no static members, and no exposed constructors. The class isn't used anywhere else in the PR either.


#if !COREBUILD && MONOMAC
[DllImport (Constants.CoreMidiLibrary)]
static extern nuint MIDIDeviceListGetNumberOfDevices (MidiDeviceListRef devList);

[DllImport (Constants.CoreMidiLibrary)]
static extern MidiDeviceRef MIDIDeviceListGetDevice (MidiDeviceListRef devList, nuint index);

[DllImport (Constants.CoreMidiLibrary)]
static extern int MIDIDeviceListAddDevice (MidiDeviceListRef devList, MidiDeviceRef dev);

[DllImport (Constants.CoreMidiLibrary)]
static extern int MIDIDeviceListDispose (MidiDeviceListRef devList);

internal MidiDeviceList (MidiDeviceListRef handle) : base (handle)
{
}

internal MidiDeviceList (MidiDeviceListRef handle, bool owns) : base (handle, owns)
{
}

public nuint GetNumberOfDevices ()
{
if (handle == MidiObject.InvalidRef)
throw new ObjectDisposedException ("handle");
return MIDIDeviceListGetNumberOfDevices (handle);
}

public MidiDevice Get (nuint index)
{
if (handle == MidiObject.InvalidRef)
throw new ObjectDisposedException ("handle");
var h = MIDIDeviceListGetDevice (handle, index);
if (h == MidiObject.InvalidRef)
return null;
return new MidiDevice (h);
}

public int Add (MidiDevice device)
{
if (handle == MidiObject.InvalidRef)
throw new ObjectDisposedException ("handle");
return MIDIDeviceListAddDevice (handle, device.Handle);
}

internal override void DisposeHandle ()
{
if (handle != MidiObject.InvalidRef){
if (owns)
MIDIDeviceListDispose (handle);
handle = MidiObject.InvalidRef;
}
}

#endif // !COREBUILD
}

Expand Down
79 changes: 79 additions & 0 deletions src/coremidi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,83 @@ interface MidiNetworkSession {
MidiEndpoint DestinationEndPoint { get; }
}
#endif

[NoWatch, NoTV, Mac (10,14, onlyOn64: true), iOS (12,0)]
[BaseType (typeof(NSObject), Name="MIDICIProfile")]
[DisableDefaultCtor]
interface MidiCIProfile : NSSecureCoding
{
[Export ("name")]
string Name { get; }

[Export ("profileID")]
NSData ProfileId { get; }

[Export ("initWithData:name:")]
IntPtr Constructor (NSData data, string inName);
}

[NoWatch, NoTV, Mac (10,14, onlyOn64: true), iOS (12,0)]
[BaseType (typeof(NSObject), Name="MIDICIProfileState")]
[DisableDefaultCtor]
interface MidiCIProfileState : NSSecureCoding
{
[Export ("enabledProfiles")]
MidiCIProfile[] EnabledProfiles { get; }

[Export ("disabledProfiles")]
MidiCIProfile[] DisabledProfiles { get; }

[Export ("initWithEnabledProfiles:disabledProfiles:")]
IntPtr Constructor (MidiCIProfile[] enabled, MidiCIProfile[] disabled);
}

delegate void MidiCIProfileChangedHandler (MidiCISession session, byte channel, MidiCIProfile profile, bool enabled);
delegate void MidiCIPropertyResponseHandler (MidiCISession session, byte channel, NSData response, NSError error);
delegate void MidiCIPropertyChangedHandler (MidiCISession session, byte channel, NSData data);

[NoWatch, NoTV, Mac (10,14, onlyOn64: true), iOS (12,0)]
[BaseType (typeof(NSObject), Name="MIDICISession")]
[DisableDefaultCtor]
interface MidiCISession
{
[Export ("initWithMIDIEntity:dataReadyHandler:")]
IntPtr Constructor (uint entity, Action handler);

[Export ("entity")]
uint Entity { get; }

[Export ("supportsProfileCapability")]
bool SupportsProfileCapability { get; }

[Export ("supportsPropertyCapability")]
bool SupportsPropertyCapability { get; }

[Export ("deviceIdentification")]
MidiCIDeviceIdentification DeviceIdentification { get; }

[Export ("profileStateForChannel:")]
MidiCIProfileState GetProfileState (byte channel);

[Export ("enableProfile:onChannel:error:")]
bool EnableProfile (MidiCIProfile profile, byte channel, [NullAllowed] out NSError outError);

[Export ("disableProfile:onChannel:error:")]
bool DisableProfile (MidiCIProfile profile, byte channel, [NullAllowed] out NSError outError);

[NullAllowed, Export ("profileChangedCallback", ArgumentSemantic.Assign)]
MidiCIProfileChangedHandler ProfileChangedCallback { get; set; }

[Export ("hasProperty:onChannel:responseHandler:")]
void HasProperty (NSData inquiry, byte channel, MidiCIPropertyResponseHandler handler);

[Export ("getProperty:onChannel:responseHandler:")]
void GetProperty (NSData inquiry, byte channel, MidiCIPropertyResponseHandler handler);

[Export ("setProperty:onChannel:responseHandler:")]
void SetProperty (NSData inquiry, byte channel, MidiCIPropertyResponseHandler handler);

[NullAllowed, Export ("propertyChangedCallback", ArgumentSemantic.Assign)]
MidiCIPropertyChangedHandler PropertyChangedCallback { get; set; }
}
}
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ COREMEDIA_SOURCES = \
# CoreMidi

COREMIDI_CORE_SOURCES = \
CoreMidi/MidiCIDeviceIdentification.cs \
CoreMidi/MidiServices.cs \
CoreMidi/MidiThruConnection.cs \
CoreMidi/MidiThruConnectionParams.cs \
Expand Down
1 change: 0 additions & 1 deletion tests/xtro-sharpie/iOS-CoreMIDI.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
!missing-field! kMIDIPropertyUniqueID not bound
!missing-pinvoke! MIDIClientCreateWithBlock is not bound
!missing-pinvoke! MIDIDestinationCreateWithBlock is not bound
!missing-pinvoke! MIDIDeviceAddEntity is not bound
!missing-pinvoke! MIDIDeviceCreate is not bound
!missing-pinvoke! MIDIDeviceDispose is not bound
!missing-pinvoke! MIDIDeviceListAddDevice is not bound
Expand Down
24 changes: 0 additions & 24 deletions tests/xtro-sharpie/iOS-CoreMIDI.todo

This file was deleted.

84 changes: 84 additions & 0 deletions tests/xtro-sharpie/macOS-CoreMIDI.ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
# Fixed in XAMCORE_4_0
!unknown-native-enum! MidiNetworkConnectionPolicy bound

# added in MidiServices.cs
!missing-field! kMIDIPropertyAdvanceScheduleTimeMuSec not bound
!missing-field! kMIDIPropertyCanRoute not bound
!missing-field! kMIDIPropertyConnectionUniqueID not bound
!missing-field! kMIDIPropertyDeviceID not bound
!missing-field! kMIDIPropertyDisplayName not bound
!missing-field! kMIDIPropertyDriverDeviceEditorApp not bound
!missing-field! kMIDIPropertyDriverOwner not bound
!missing-field! kMIDIPropertyDriverVersion not bound
!missing-field! kMIDIPropertyImage not bound
!missing-field! kMIDIPropertyIsBroadcast not bound
!missing-field! kMIDIPropertyIsDrumMachine not bound
!missing-field! kMIDIPropertyIsEffectUnit not bound
!missing-field! kMIDIPropertyIsEmbeddedEntity not bound
!missing-field! kMIDIPropertyIsMixer not bound
!missing-field! kMIDIPropertyIsSampler not bound
!missing-field! kMIDIPropertyManufacturer not bound
!missing-field! kMIDIPropertyMaxReceiveChannels not bound
!missing-field! kMIDIPropertyMaxSysExSpeed not bound
!missing-field! kMIDIPropertyMaxTransmitChannels not bound
!missing-field! kMIDIPropertyModel not bound
!missing-field! kMIDIPropertyName not bound
!missing-field! kMIDIPropertyNameConfiguration not bound
!missing-field! kMIDIPropertyOffline not bound
!missing-field! kMIDIPropertyPanDisruptsStereo not bound
!missing-field! kMIDIPropertyPrivate not bound
!missing-field! kMIDIPropertyReceiveChannels not bound
!missing-field! kMIDIPropertyReceivesBankSelectLSB not bound
!missing-field! kMIDIPropertyReceivesBankSelectMSB not bound
!missing-field! kMIDIPropertyReceivesClock not bound
!missing-field! kMIDIPropertyReceivesMTC not bound
!missing-field! kMIDIPropertyReceivesNotes not bound
!missing-field! kMIDIPropertyReceivesProgramChanges not bound
!missing-field! kMIDIPropertySingleRealtimeEntity not bound
!missing-field! kMIDIPropertySupportsGeneralMIDI not bound
!missing-field! kMIDIPropertySupportsMMC not bound
!missing-field! kMIDIPropertySupportsShowControl not bound
!missing-field! kMIDIPropertyTransmitChannels not bound
!missing-field! kMIDIPropertyTransmitsBankSelectLSB not bound
!missing-field! kMIDIPropertyTransmitsBankSelectMSB not bound
!missing-field! kMIDIPropertyTransmitsClock not bound
!missing-field! kMIDIPropertyTransmitsMTC not bound
!missing-field! kMIDIPropertyTransmitsNotes not bound
!missing-field! kMIDIPropertyTransmitsProgramChanges not bound
!missing-field! kMIDIPropertyUniqueID not bound
!missing-field! kMIDIDriverPropertyUsesSerial not bound
!missing-field! kMIDIPropertyFactoryPatchNameFile not bound
!missing-field! kMIDIPropertyUserPatchNameFile not bound

# deprecated pinvokes and not binded.
!missing-pinvoke! MIDISetupToData is not bound
!missing-pinvoke! MIDISetupInstall is not bound
!missing-pinvoke! MIDISetupGetCurrent is not bound
!missing-pinvoke! MIDISetupFromData is not bound
!missing-pinvoke! MIDISetupDispose is not bound
!missing-pinvoke! MIDISetupCreate is not bound
!missing-pinvoke! MIDISetSerialPortOwner is not bound
!missing-pinvoke! MIDIGetSerialPortOwner is not bound
!missing-pinvoke! MIDIGetSerialPortDrivers is not bound

# not known use
!missing-pinvoke! MIDIEndpointGetRefCons is not bound
!missing-pinvoke! MIDIEndpointSetRefCons is not bound

# old apis that have been ignored, please refer to issue https://github.com/xamarin/xamarin-macios/issues/4452
!missing-pinvoke! MIDIClientCreateWithBlock is not bound
!missing-pinvoke! MIDIDestinationCreateWithBlock is not bound
!missing-pinvoke! MIDIDeviceCreate is not bound
!missing-pinvoke! MIDIDeviceDispose is not bound
!missing-pinvoke! MIDIDeviceRemoveEntity is not bound
!missing-pinvoke! MIDIDriverEnableMonitoring is not bound
!missing-pinvoke! MIDIEntityAddOrRemoveEndpoints is not bound
!missing-pinvoke! MIDIExternalDeviceCreate is not bound
!missing-pinvoke! MIDIGetDriverDeviceList is not bound
!missing-pinvoke! MIDIGetDriverIORunLoop is not bound
!missing-pinvoke! MIDIInputPortCreateWithBlock is not bound
!missing-pinvoke! MIDIPacketListAdd is not bound
!missing-pinvoke! MIDIPacketListInit is not bound
!missing-pinvoke! MIDISendSysex is not bound
!missing-pinvoke! MIDISetupAddDevice is not bound
!missing-pinvoke! MIDISetupAddExternalDevice is not bound
!missing-pinvoke! MIDISetupRemoveDevice is not bound
!missing-pinvoke! MIDISetupRemoveExternalDevice is not bound
Loading