Music Software Development

MIDI messages in bytes

A MIDI keyboard sends performance instructions. A synthesizer interprets them to produce sound. In MIDI 1.0 channel messages, the high nibble of the status byte identifies the message type and the low nibble identifies a channel from 0 to 15. Interfaces usually label those channels 1 to 16.

Play and release middle C

90 3C 64   Note On, channel 1, note 60, velocity 100
80 3C 00   Note Off, channel 1, note 60, release velocity 0
90 3C 00   Another encoding for releasing the same note

The bytes above are hex. The high bit is set on the status byte and clear on the data bytes. To extract the human-facing channel number, compute (status & 0x0f) + 1. If you ever hear a stuck note, look for mismatched channels or a missing release, including the zero-velocity Note On encoding.

Change a control

B0 40 7F   Sustain pedal on, channel 1
B0 40 00   Sustain pedal off, channel 1

Control Change uses one data byte for the controller number and one for its value. Controller 64 (hex 40) is the sustain switch. Values 0–63 mean off and 64–127 mean on.

Try the note calculator to find note numbers, then see how these messages fit inside a MIDI file.