Musical Instrument Digital Interface
|
Message |
Data |
Description |
0 |
key velocity |
Note Off. This is rarely used. |
1 |
key velocity |
Note On. If velocity is set to zero, this is treated as a note-off message. |
2 |
key value |
Polyphonic Key Pressure (after-touch).. |
3 |
controller value |
Control change. MIDI supports 128 different controllers (0-127). |
4 |
program |
Program (patch) change. |
5 |
value |
Channel pressure (after-touch). |
6 |
lsb msb |
Pitch wheel change. The value is a 14-bit value in two bytes with the low order 7 bits contained in the first byte and the high order 7 bits in the second byte. A value of 0x2000 is considered a center value indicating no pitch variation. |
One of the features of a MIDI data stream that we must also consider is called running status. When the message is a channel message, it only has to be sent when the message is different from the last channel message. For example, once a note-on message is sent, only the key and velocity values need to be sent until some other message (such as control change) needs to be sent. This is part of the data compression scheme for MIDI transmission.
The Note Off message is rarely used since a Note On message with a velocity of zero indicates a note should stop playing. Using a running status allows a synthesizer (or sequencer) to send a single Note On message followed by key and velocity information only. When the velocity it non-zero, a note is initiated and when the velocity is zero, the note is stopped.
For Note On and Note Off messages, the key value is typically used to indicate pitch and the velocity value indicates volume. However, a synthesizer may interpret the values otherwise. For example, pitch for a drum kit instrument can represent which drum sound is to be played. Likewise, velocity could be applied to envelope rate in addition to volume level.
Control change messages are used to dynamically alter the sound of the instrument. The most common control messages are for modulation (1) overall volume (7) and panning (10). Modulation is commonly used to indicate vibrato depth. Of the remaining 128 different controllers, many are not used or only vaguely defined. For example, controllers 16-20 are designated "General Purpose" controllers without any specifics of how they should be used. Others such as 72 (release time) and 73 (attack time) do not indicate the range of operation, only the function that is to be modified. A large number of controller numbers are used to specify a "LSB" value. Since only one byte is provided for the controller value, a second message must be used to produce values greater than 127. For fine grained control, the synthesizer can send a second byte using the associated LSB control number. Together the messages allow for 14-bit resolution. If an instrument intends to use the LSB, it must be capable of splicing the two message values together when they occur and also be able to function properly if the LSB value is missing.
The aftertouch messages are used to indicate variations in key pressure while a key is held down. The aftertouch messages are often ignored by event recorders since they can result in a flood of messages that quickly fill up the sequencer memory
Program change allows indication of up to 128 different instruments. However, control #0 can be used to select up to 128 different patch banks, or up to 16,384 if the LSB for control 0 (#32) is used as well. Both the program number and bank numbers are specific to the synthesizer. As a result, a sequence from one synthesizer might sound completely different on another synthesizer. For this reason, the MIDI specification was expanded to define the General MIDI (GM) patch numbers. GM defines a set of common instrument assignments on bank 0 so that a sequence recorded on one synthesizer will sound similar when played on another synthesizer. When implementing a software synthesizer we should attempt to match bank 0 program changes to sound similar to those defined for GM and use other banks for non-standard instruments.
Looking at the events listed above, we can see that some of the events apply to individual notes while others apply to all notes on a channel. The note on/off and polyphonic after-touch apply to individual notes. The control change, program change, channel after-touch and pitch wheel change apply to all notes on a channel. Events that apply to an individual note need to be sent to the instrument that is generating sound. Events that apply to all sounding notes must be handled by a channel object that has knowledge of all active notes. In addition, when a new note is started, all current channel values must be applied to the new note.