Up until iOS 14, the signature of MIDI message receive callbacks was the following:
typedef void (*MIDIReadProc)(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon);
where readProcRefCon
was an arbitrary pointer that could be used to capture context such as a pointer to a C++ object to call into, or even a function pointer encapsulating that call.
However, this has now been deprecated and replaced with the following:
typedef void (^MIDIReceiveBlock)(const MIDIEventList *evtlist, void *srcConnRefCon);
The readProcRefCon
parameter has now been removed, making it far from straightforward to pass messages along to other services without resorting to some sort of global variable, which would be an anti-pattern. So, is there some way to avoid that?
Documentation for the old signature is here and for the new signature is here. No explanation is given as to why the context pointer was removed.