I just ran into the same problem on Mac OS X. The cause was that i didn't have a run loop in place. The documentation for CoreMIDI isn't quite extensive, but the MIDIClientCreate docs indicate that notifications are dispatched using run loop sources:
Note that notifyProc will always be called on the run loop which was current when MIDIClientCreate was first called. Apple MIDI Services Reference : MIDIClientCreate
So a solution was to call CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true)
in my custom run loop. Since i created the MIDIClientRef
on a secondary thread, i had to add this call to the run loop of my main thread as well (eventually this needs to be done for all parent threads). CFRunLoopRunInMode
will process the input sources of the run loop and exits immediately in my case (third parameter is true
), but you can also choose to block the thread until the run loop is stopped (CFRunLoopRun
), maybe on a new thread, whatever fits your design best.
If you are not familiar with Apple's Core Foundation and Cocoa Run Loops yet, the following guide should be a good introduction: Apple Threading Programming Guide : Run Loops