Monday, June 22, 2015

Receiving MIDI Time Codes over USB with the Teensy

Due to a request of a reader of my blog, I elaborated on my extensions for the Teensy 3.x usb_midi library by adding support for callback functions to receive MIDI Time Code (MTC) messages. To fully understand the code, I recommend also reading my post for generating the MTC.

Briefly, the library files where we need to add the missing functions are located (on Mac OS X) in Contents/Java/hardware/teensy/avr/cores/teensy3/. This folder can be found by right-clicking on your Arduino application and then selecting Show Package Contents from the drop down menu.

You can either download the modified files from my GitHub repository and copy them to above folder, or you can modify the files yourself by following the following simple instructions:

Open usb_midi.h and search for "#ifdef __cplusplus". Add the following code one line above that:

Now search for "private:" and add this code right before it:

You are almost done. Save and close the file, and open usb_midi.c instead. Search for "// Maximum number of transmit packets to ..." and add this line above:

As a last step, search for "return 0; } #endif // F_CPU" (they might be distributed over multiple lines) and add these lines of code before the "return 0;"

And voilá, you can now receive MTC messages over USB and evaluate them with callback functions.
Your callback function will receive the MTC as a word parameter. An example sketch showing how to do the decoding is included in the repository...


Post a Comment