Apple recently deprecated the MIDIDestinationCreate method and replaced it with a MidiDestinationCreateWithProtocol (MIDIDestinationCreate)
The old method required to pass a simple callback method 'MIDIReadProc' which from C# could be done by creating the following delegate signature, then creating a delegate and assigning a method as the callback. We declare the delegate signature:
internal delegate void MIDIReadProc(MIDIPacketListPtr pktlist, IntPtr readProcRefCon, IntPtr srcConnRefCon);
Create a delegate to assign our callback method to:
private CoreMidiInterop.NativeMethods.MIDIReadProc m_readProcDelegate;
Assign a method to the delegate we created:
m_readProcDelegate = CallMessageReceived;
Create a callback method, that should receive MIDI messages from macOS Core MIDI:
private void CallMessageReceived(MIDIPacketListPtr pktlist, IntPtr readProcRefCon, IntPtr srcConnRefCon)
{
...
}
Eventually pass this delegate to the apple Core MIDI method:
CoreMidiInterop.NativeMethods
.MIDIDestinationCreate(m_clientRef, CoreFoundationUtils.ToCFStringRef(name), m_readProcDelegate, CFStringRef.Zero, out MIDIEndpointRef destinationRef);
This all works as expected.
That's now deprecated and no longer works on macOS Big Sur. The new method "MidiDestinationCreateWithProtocol" requires an apple block to use as the callback param (called MIDIReceiveBlock readBlock):
OSStatus MIDIDestinationCreateWithProtocol(MIDIClientRef client, CFStringRef name, MIDIProtocolID protocol, MIDIEndpointRef *outDest, MIDIReceiveBlock readBlock);
The documentation here: MIDIReceiveBlock
How is it possible to create an apple block with C# code? I've been searching for examples but cannot find any. I did start looking at the underlying implementation of apple blocks here:
Block Implementation Specification
It's no simple thing, so any help/example of how to do this in C# would be really helpful.