Clock MIDI File Generator

I created the following HTML JavaScript page to generate a MIDI file that has MIDI clocks in it:

[Clock MIDI File Generator - example screenshot and event list]

Download: clock-midi-file-generator.zip

The generated MIDI file is set up to send the "F8" clock message the required 24 times per quarter note. This esoteric embedding of a MIDI clock in a MIDI file might be useful in some cases.

In particular, some people have a Cymatic audio player and want it to play something and also send MIDI Clock messages to another MIDI device so that the other MIDI device will use the same tempos. The Cymatic player doesn't provide an option to generate and send the MIDI Clock messages on its own, but it can play a MIDI file along with the audio file, and it will send MIDI Clock messages if they are stored in the MIDI file. The Clock MIDI File Generator will generate a MIDI file with MIDI Clocks in it for this purpose. I don't know how well this actually works, but it is at least technically possible.

The MIDI file generated by the Clock MIDI File Generator only contains F8 clock messages. The following test modification to the Generator changes the first message to a start and a clock (FA F8).

Download: clock-midi-file-generator-v1.01-test.zip

For more information about "What is MIDI Clock?" and "Why would you want to store a MIDI Clock message in a MIDI file?" continue reading the following sections.

What is MIDI Clock?

Imagine you have two MIDI devices, one that you want to play prerecorded melody notes and another that can play an internal drum pattern. You want both devices to start and stop playing together, and if the tempo of the melody changes, you want the tempo of the drum pattern to change correctly at the same time.

To do this, you connect a MIDI cable between the MIDI OUT port on your melody device and the MIDI IN port on your drum device. You set your melody device to send MIDI Clock, Start, and Stop messages on its MIDI OUT port. You set your drum device to obey the MIDI Clock, Start, and Stop messages it receives on its MIDI IN port.

In particular, the MIDI Clock message is a one-byte message (hex F8) that, when used, is sent 24 times per quarter note. A MIDI device listening for MIDI Clock messages will adjust its own tempo based on the time between MIDI Clock messages that it sees coming in.

MIDI sequencers and MIDI Clock

If you are developing a MIDI sequencer, you don't want to record incoming MIDI Clock messages into a MIDI file. But you might eventually consider having advanced options in your sequencer to:

If you want to support the really esoteric ability to store arbitrary bytes in a MIDI file (including a MIDI Clock message or anything else) so that they can be sent to the MIDI output port when the file is played, be sure to support the F7 MIDI file message mentioned later, and let users put anything they want to inside of it.

MIDI cable messages and MIDI file messages

Be aware there are some differences between MIDI messages on a MIDI cable and the messages you encounter in a MIDI file.

For example, on a MIDI cable, the System Real-Time messages can occur between the bytes of other messages. In a MIDI file, they can't.

In fact, on a MIDI cable, the System Common and System Real-Time messages with status bytes of hex F1 to F6 and F8 to FF aren't very useful to store in a MIDI file. When you are expecting a status byte in a MIDI file, some of these bytes are redefined to have a new meaning.

On a MIDI cable, the status byte FF means Reset. But when you are expecting a status byte in a MIDI file, FF is used to mark the beginning of a Meta Event.

On a MIDI cable, the status byte of F7 is used to mark the end of a System Exclusive message. In a MIDI file, the "status byte" of F7 is used to mark the beginning of a message that either contains a partial System Exclusive message that started in a previous message, or contains any other bytes you want to be sent on the MIDI OUT port when the file is played.

Why would you want to store a MIDI Clock message in a MIDI file?

It's usually not useful to store MIDI Clock messages in a MIDI file. However, according to the Standard MIDI File specification, there is a way to store a MIDI Clock message in a MIDI file if you really want to. You have to use the F7 MIDI file message mentioned previously.

Some people have a Cymatic audio player and want it to play something and also send MIDI Clock messages to another MIDI device so that the other MIDI device will use the same tempos. The Cymatic player doesn't provide an option to generate and send the MIDI Clock messages on its own, but it can play a MIDI file along with the audio file, and it will send MIDI Clock messages if they are stored in the MIDI file. I don't know how well this actually works, but it is at least technically possible.

Specifications

If you want to read the official specifications, check out the following PDF files from midi.org:

MIDI 1.0 Detailed Specification describes MIDI messages that you encounter on MIDI cables. PDF page 35 (printed page 30) is where the Clock message is described. Surrounding that, in PDF pages 32 to 37 (printed pages 27 to 32) you can also read about the Start, Stop, Continue, Song Select, and Song Position Pointer messages, with examples of how they relate to Clock messages.

Standard MIDI Files describes the messages you can encounter in MIDI files. PDF pages 8 and 9 (printed pages 6 and 7) describe the F7 MIDI file message.


Robert Hart
Posted on rnhart.net .
Adapted from messages I posted in the midi.org forum:

Home > Programs > Clock MIDI File Generator