Saturday, May 25, 2013

Receiving Teensy MIDI Channels as Indexed from Zero

There are many instances when my Teensy / Arduino code may not work on standard Teensy installations as expected.

This applies to many cases where MIDI data is received by the Teensy.  This is because I prefer to deal with MIDI channels when indexed from zero instead of one.

If you would like to run my Teensy code on your install, one things you can do is update the Teensy MIDI API files.

To do this, right click on the Arduino app, go to Show Package Contents and navigate to the following file, and opening it in a text editor:
Arduino > Contents > Resources > Java > Hardware > Teensy > cores > usb_midi > usb_api.cpp

Find the following code:

type2 = b1 & 0xF0;
    c = (b1 & 0x0F) + 1;


And change it to:

type2 = b1 & 0xF0;
    c = (b1 & 0x0F);


Save the file. As a result, any MIDI data received will return channel numbers 0 - 15 instead of 1 - 16.

0 comments: