Saturday, May 23, 2020

Teensy 3.6 Basics: Sending MIDI Clock Messages

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 send MIDI clock messages, four functions are used:

  • usbMIDI.sendRealTime(usbMIDI.Clock);
  • usbMIDI.sendRealTime(usbMIDI.Start);
  • usbMIDI.sendRealTime(usbMIDI.Continue);
  • usbMIDI.sendRealTime(usbMIDI.Stop);

To use a particular function, simple send it at the required point in time.

MIDI clock can be used with Ableton Live to sync the transport to the Teensy. In Ableton Live, set up the Teensy as a sync input source in the Link MIDI tab in preferences. This will enable an EXT button near the BPM. Click on this to enable external sync to the Teensy.

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

Sending Start and Clock

View code here:

Sending Tempo Based on Potentiometer

View code here:

Sending Tempo Based on Potentiometer, with a Button for Start and Stop