UEE051H3 - STUDIO TECHNOLOGY

MIDI - Section 3, MIDI Message Structure and Channel Messages

Return to MIDI Introduction and Contents
Return to Studio Technology home page



3. The MIDI Message Structure

All MIDI messages start with a 'header' byte. All header bytes have the top, or MSB (Most Significant Bit) set to 1. In multiple byte MIDI messages all subsequent bytes have the MSB set to 0. The other three bits in the top 'nibble' determine whether the MIDI message is either a CHANNEL message or a SYSTEM message, as illustrated here:

Thus, if bits 4 5 and 6 in the header byte are all set to 1, then we have a system message header byte, any other pattern of bits in bit positions 4 5 and 6 indicate a channel message. It follows therefore, that there are seven different types of channel message, corresponding to bits 4 5 and 6 set to 000, 001, 010, 011, 100, 101, or 110.

The key distinction between these two classes of MIDI message, is that (as their names imply) SYSTEM messages are intended for all devices connected to the MIDI interface, whereas CHANNEL messages are intended only for a single MIDI 'channel' and should be ignored by all other channels. For CHANNEL messages, the intended channel number is always supplied as the lower nibble (4 bits) in the channel message header byte; it follows therefore that there are sixteen possible MIDI channels. Before looking any further into MIDI messages it is important to understand the role of MIDI channels, as described in the next section.



3.1 The MIDI Channel

The lower nibble (4 bits) of the channel header message byte always specify the MIDI channel, which is the intended recipient of any given MIDI channel message, as illustrated below.

Channel Message Header Byte.. 1 M M M C C C C

Here, 'M' denotes the three bits which determine the exact type of channel message, and the 'C' bits specify the MIDI channel. By convention, MIDI channels are always numbered from 1 to 16, but are coded as the values 0 (binary 0000) to 15 (binary 1111) respectively, in the channel message header byte. MIDI channels allow a single MIDI controller (ie a keyboard or more generally a sequencer) to control multiple MIDI instruments (ie synthesisers) within a MIDI setup. By assigning each instrument to receive on a different MIDI channel we can arrange that a sequencer can send different MIDI 'note on' messages to each instrument, thus creating an ensemble. Without MIDI channels, all instruments connected in a MIDI chain would sound all notes.

In the early days of MIDI each instrument was generally mono-timbral, that is it would only play one kind of 'instrument' at a time, and would only require one MIDI channel. Nowadays most synthesisers are multi-timbral, which means that they are capable of synthesising a number of different 'instruments' simultaneously (and of allowing each to be played polyphonically). It follows that in a multi-timbral synthesiser each instrument, or 'part' would need to be assigned to its own MIDI channel. It is easy to see, therefore, that even in a modest MIDI setup we can quickly use up all sixteen MIDI channels. In fact, devising ways of overcoming the limitation of sixteen MIDI channels is a frequent challenge to today's stage or studio synthesist.



3.2 MIDI Channel Messages

There are seven MIDI channel messages, all carrying the channel number of the intended recipient of the message in the lower nibble (4 bits) of the channel message header byte. The complete set of channel messages is listed below:

All seven of the channel messages require one or two additional 'data' bytes which, by definition, must have their top bit set to zero (otherwise they might be mistaken for 'header' message bytes). Thus, from the table above, two of the channel messages: 'program change' and 'overall key pressure' have a total length, including message header, of two bytes, and all others have a total length of three bytes. The meaning and format of the data contained within these data bytes depends on the message type, as detailed in the following sections.

3.2.1 Channel Messages: Note On and Note Off

The three bytes of the MIDI Note On message have the following structure:

And the three bytes of the MIDI Note Off message have a structure which is virtually identical: As the name implies, the 'Note On' message is an instruction to the instrument listening on channel 'C', to play the note with note value (ie pitch) 'N' and note velocity (ie loudness) 'V'. The note value is coded as bits 0..7 of byte 2 and, with 7 bits, has a range of 0 to 127 (decimal). The MIDI standard defines note value decimal 60 as 'middle C', and each increment, or decrement alters the pitch by one semitone, so 61 is C#, 62 is D, 63 D# above middle C and so on. Note value 59 is B and 58 is Bb below middle C. The note value range of 0 to 127 this gives a coverage of over ten octaves, which is well beyond the range of most instruments.

The term 'velocity' refers to the speed at which a key is pressed, and determines the loudness of the note which will be played, again on a scale of values from 0 to 127 (decimal). It is up to the instrument receiving the message to interpret the velocity value and use this to control the note being synthesised. With some timbres (such as an organ) the loudness remains more or less constant for the duration of the note, and the 'velocity' value will determine this level.  With other timbres (piano, for example) the note has attack, sustain and decay phases, and the instrument may use the velocity value to determine the maximum loudness of the attack part of the note, or it may even use the velocity value to vary the attack time (to emulate the acoustic instrument).

The Note On message instructs the instrument to start the note, and the instrument then relies on receiving a matching Note Off message to tell it when to stop the note. Clearly, the Note Off message must have the same note value (in byte 2) as the earlier corresponding Note On message, otherwise the receiving instrument will not know which note is to be stopped. The MIDI specification also requires the same velocity value (in byte 3) of the Note Off message, as the earlier Note On, although most instruments are perfectly happy if this value is set to 0 in the Note Off message. In fact, some instruments will interpret a Note On message with a velocity value equal to 0, as a Note Off command, although this is technically not in accord with the MIDI specification.

It should be clear, at this stage, that all notes in a MIDI system require a matching pair of MIDI messages: Note On and Note Off. If you are playing a keyboard with a MIDI output then you would, for instance, expect a Note On message to be sent when a key is pressed, and the matching Note Off when the same key is released. As one might expect the vast majority of messages in a conventional MIDI based synthesis system are Note On and Note Off messages, and it is easy to see that the maximum note capacity of a single MIDI connection is, at 6 bytes per note, about 5000 notes per second. One of the most common problems in a heavily loaded MIDI system is the 'hanging note', which occurs when a Note On message has been received and acted upon correctly, but the corresponding Note Off message has been lost, missed or corrupted; the unmistakeable effect is the note that continues to sound long after everything else has stopped!

3.2.2 MIDI Messages: Polyphonic Key Pressure (aftertouch)

This is a three byte message with the following structure:

This message is rarely implemented, except on the most sophisticated keyboards.  It provides 'aftertouch' information, that is the pressure on the keypress at the bottom of its travel, for each individual key.  If implemented, this information can be used to control sophisticated modulation effects, such as vibrato.  The reason it is rarely implemented is that each key needs to have a separate pressure transducer, to measure aftertouch, which is clearly costly in hardware.  Less sophisticated keyboards or controllers may make use of the Overall Key Pressure message.

3.2.3 MIDI Messages: Control Change

This is a three byte message with the following structure:

This is a general purpose Channel Message, which allows a MIDI keyboard or controller to send information generated by all of the various 'performance' switches and controls on the instrument.  Obvious examples are the overall 'volume'; the 'sustain' (or hold) pedal, and the 'modulation' wheel provided on many keyboards (in addition to the 'pitch wheel'), but there are many more controllers defined for this message in addition to controllers which are left to the manufacturer to define for a specific instrument.  The table below lists some of the more important control numbers (shown above as the N bits).  Refer to the full MIDI specification for an exhaustive list.
 
Controller Number N (hex) Function
00 Bank Select
01 Modulation Wheel
02 Breath Controller
07 Main Volume
08 Balance
0A Pan
40 Sustain Pedal
43 Soft Pedal
60 Data increment
61 Data decrement
62 NRPC V = LSbyte
63 NRPC V = MSbyte
64 RPC V = LSbyte
65 RPC V = MSbyte
7B All Notes Off
The Registered Parameter Controllers (RPCs) and Non-Registered Parameter Controllers (NRPCs) merit additional explanation.  These allow 14-bit values to be specified, known as Registered Parameter Numbers (RPNs) and NRPNs, to be sent on a particular MIDI channel to control internal parameters of a synthesizer.  The difference between RPNs and NRPNs is that the former need to be registered with the Midi Manufacturer's Association (MMA) and are therefore part of the overall MIDI specification, whereas individual manufacturers are free to make use of NRPNs for specific instruments.  Examples of RPCs are shown in the following table.
 
RPC Number (hex) Parameter
00 00 Pitch Bend Sensitivity
00 01 Fine Tuning
00 02 Coarse Tuning
The actual data values for the RPN and NRPN messages are sent using the data increment or data decrement Control Change messages.  Thus, as an example, to change the fine tuning incrementally by +1, on MIDI channel 3, would require the following 9 byte sequence:
[B3] [64] [01]    [B3] [65] [00]    [B3] [60] [01]

3.2.4 MIDI Messages: Program Change

This is a two byte message with the following structure:

The word 'program' refers here to the 'programming' setup of the synthesiser listening on channel 'C', something which is sometimes also refered to as the current 'patch'. Most MIDI equipped synthesisers allow a number of factory presets and/or user programmed 'patches' to be stored and selected using the Program Change message. Each program, or patch, will of course generate a different timbre, or instrument, so the Program Change message is, in effect, allowing control, via MIDI, of the current sound that will be generated (by subsequent Note On messages). The Program Change message does not allow any of the detailed parameters associated with a 'patch' to be altered (which is something that can normally only be achieved using MIDI System Exclusive messages), but merely allows the currently selected patch associated with the MIDI channel to be altered. For many performances Program Change messages will only be sent to MIDI synthesisers at the start of a new song, in order to select the required 'instrument' for each MIDI channel. The Program Change message may, however, also be sent during a performance in order to change the instrument for a given MIDI channel 'on the fly'; a feature that is especially useful in arrangements which require more than sixteen instruments in total, but where sixteen instruments, or less, are playing at any one time.

The Program Change message clearly allows up to 128 different programs, or patches, coded as values 0..127 (decimal) in the lower seven bits of the second byte.

3.2.5 MIDI Messages: Overall Key Pressure

This is a two byte message with the following structure:

This message provides 'aftertouch' information, that is the key pressure at the bottom of its travel, as an overall 'average' value for all of the keys currently pressed (rather than on an individual key basis as provided by the Polyphonic Key Pressure message).  This information might be used by a synthesizer to control modulation effects, such as vibrato.

3.2.6 MIDI Messages: Pitch Wheel (Pitch Bend)

This is a three byte message with the following structure:

Many MIDI controller keyboards have a 'pitch wheel', often at the right hand side of the keyboard.  The pitch wheel allows the player to 'bend' the pitch of the notes currently played (in a fashion analogous to the way a guitarist can alter the pitch of a string by 'pulling' the string and stretching it).  The MIDI controller will generate the Pitch Wheel message above, providing a 14-bit value which represents the pitch offset from the centre position, thus a value of 2000 (hexadecimal) represents the centre position; 0 is at one extreme of the pitch wheel's travel and 3FFF (hex) is at the other extreme.  Because of the fine resolution of this function, any use of the pitch wheel does generate a significant number of these MIDI messages as the position of the pitch wheel control is altered.

Note that the amount by which the pitch is varied by this function is not fixed, but can - for most synthesizers - be set using a 'Set Pitch Bend Range' function, often implemented as one of the Registered Parameter Number (RPN) Control Change functions.



3.3 MIDI System Messages

There are 3 basic groups of MIDI System Messages: the System Exclusive (SysEx) messages, the System Common messages, and the System Realtime messages.  These are listed, together with their status byte values and any parameters, in the table below.
 
Message Status (hex) Data 1 Data 2
System Exclusive
System Exclusive Start F0 Manufacturer's ID Data, (data), (data), etc
End of SysEx F7 - -
System Common
Quarter Frame F1 Data -
Song Pointer F2 LSbyte MSbyte
Song Select F3 - -
Tune Request F6 - -
System Realtime
Timing Clock F8 - -
Start FA - -
Continue FB - -
Stop FC - -
Active Sensing FE - -
Reset FF - -
still under construction.