Hi all,
I have the following code where I want the function MyMIDINotifyProc to be called to notify me of changes to the midi devices connected to the iOS devices. However, strangely it is never called when i connect or disconnect devices - what could be the problem here?
Thank you. Help much appreciated.
Pier.
void MyMIDINotifyProc (const MIDINotification *message, void *refCon) { printf("MIDI Notify, messageId=%d,", (int)message->messageID); }
/* csound MIDI input open callback, sets the device for input */ static int MidiInDeviceOpen(CSOUND *csound, void **userData, const char *dev) {
int k = 0; //6counter++; endpoints = 0;
CFStringRef name = NULL, cname = NULL, pname = NULL; CFStringEncoding defaultEncoding = CFStringGetSystemEncoding(); MIDIClientRef mclient = NULL; MIDIPortRef mport = NULL; MIDIEndpointRef endpoint; MIDIdata *mdata = (MIDIdata *) malloc(DSIZE*sizeof(MIDIdata)); OSStatus ret; cdata *refcon = (cdata *) malloc(sizeof(cdata)); memset(mdata, 0, sizeof(MIDIdata)*DSIZE); refcon->mdata = mdata; refcon->p = 0; refcon->q = 0; refcon->pnot = refcon->pchn = 0;
cname = CFStringCreateWithCString(NULL, "my client", defaultEncoding); ret = MIDIClientCreate(cname, MyMIDINotifyProc, refcon, &mclient);
if(!ret){ /* MIDI output port */ pname = CFStringCreateWithCString(NULL, "outport", defaultEncoding); ret = MIDIInputPortCreate(mclient, pname, ReadProc, refcon, &mport); if(!ret){ /* sources, we connect to all available input sources */ endpoints = MIDIGetNumberOfSources(); csoundMessage(csound, "midi srcs %d\n", endpoints); midiDevicesArray = malloc(endpoints*sizeof(CFStringRef));
for(k=0; k < endpoints; k++){ endpoint = MIDIGetSource(k); void *srcRefCon = endpoint; MIDIPortConnectSource(mport, endpoint, srcRefCon); // insert into dictionary instead ? midiDevicesArray[k] = ConnectedEndpointName(endpoint);
} } } refcon->mclient = mclient; *userData = (void*) refcon; if(name) CFRelease(name); if(pname) CFRelease(pname); if(cname) CFRelease(cname); /* report success */ return 0; }
|