Saturday, May 23, 2020

Teensy 3.6 Basics: Receiving MIDI Clock

MIDI clock messages (see System Real-Time Messages) are used to synchronise software or hardware playback transport using MIDI messages. One device sends the clock messages, and another device receives. The device receiving the messages is synchronised to the device that sends the messages.

MIDI clock messages do not carry song position, location or absolute time. Instead, this is transport information for synchronising.

There are four relevant message types - 'start', 'stop', 'continue' and 'clock'. Start and stop are self explanatory - they represent the transport beginning to play and ending to play. Continue represents a transport that is not at the start of the sequence to carry on from the current position. The clock message is sent 24 times per quarter note (a resolution of 24 ppqn). The clock message interval is, of course, depending on the beats-per-minute and can be calculated as (60 / beats-per-minute) / 24 seconds.

Teensy and the Teensyduino add-on can send and receive MIDI clock messages over USB as a USB-compliant MIDI device.

To receive MIDI clock messages on the Teensy, four functions must be written, that correspond with the following:

  • void myClock()
  • void myStart()
  • void myContinue()
  • void myStop()

These functions are created by the user, and each function will only be called when that type of message is received by the Teensy.

In setup(), each function must be connected by name to the message type it should respond to.

  • usbMIDI.setHandleClock(myClock);
  • usbMIDI.setHandleStart(myStart);
  • usbMIDI.setHandleContinue(myContinue);
  • usbMIDI.setHandleStop(myStop);

MIDI clock can be used with Ableton Live to sync the Teensy to the Transport. In Ableton Live, set up the Teensy as a sync output source in the Link MIDI tab in preferences.


When the transport is played in Live, this will then send MIDI clock messages from Live to Teensy. 

Here are three examples of sending MIDI clock messages from Live to Teensy. 



Turn on LED when transport is playing, turn off when transport is stopped







Turn on LED with every beat



View the code here: https://github.com/little-scale/arduino-sketches/blob/master/MIDI_Clock_Receive_2.ino



Two pots generate notes at 1/16ths that are synchronised to Live



View the code here: https://github.com/little-scale/arduino-sketches/blob/master/MIDI_Clock_Receive_3.ino

0 comments: