Core MIDI and Threading

The "obvious" test cases failing, I poured over the Core MIDI documentation to discover that the MIDI read callback functions are called on a different thread than the main application. This makes quite a bit of sense. The upshot, however, is that I'll need to write a multi-threaded method of sending the data back to my application for use. The Apple sample code for MIDIReadProc, however, was carefully chosen to be self contained and does not need any UI synchronization. Which means they chose a sample that is technically correct but which misses the intended use of the function for 90% (or more) of their target audience.

I with this were atypical of documentation, but it is not. Not just for Apple, but most companies do this. The "sample code" is written by somebody who is usually not the typical developer who would use the API, and they usually have a quota of samples to fill and don't have time to polish off a "correct" way to use a complicated function.

So it seems that one of the first tasks I've set myself in OS X programming is robust inter-thread communication with hard timing constraints (though not real time at least). What better a way to introduce myself to the Core Frameworks and the *nix underpinnings of the OS. Time for a lot of test code, since I can imagine I'll be refactoring this code constantly as I learn more. After years of writing Windows code, it'll be interested to see how easy making the transition is.