All MIDI messages are expressed in byte sized units (8 bits). There are two types of MIDI bytes: status bytes and data bytes. The distinguishing feature between data bytes and status bytes is the most significant bit (the left most bit) of the 8 bit number in binary.
Binary | Hex | Decimal | |
Data byte | 00000000 -01111111 | 0 - 7F | 0 - 127 |
Status Byte | 10000000 -11111111 | 80 - FF | 128-255 |
Every MIDI status message byte consists of two hex digits. The left digit is the code for the MIDI status type. The right digit is the MIDI channel number. Most MIDI status messages are followed by two data bytes; status-data1-data2. The exceptions are $Cn, $Dn, and Fx. $Cn and $Dn where the status messages is followed by one data byte. The MIDI status message $Fx is a category of MIDI messages called System Exclusive messages or a sysex messages. $Fx can be followed by any number of data bytes. The $Fx messages are used for system wide messages and also by synthesizer manufacturers to implement graphical editing programs that can manipulate the controls on their hardware using MIDI data. We will not be covering sysex ($Fx) messages in class. This table lists the MIDI status types.
Eight different MIDI Status messages, $8n-$FF, are defined in the MIDI specification. The left hex digit indicates the type of message, the right hex digit indicates the MIDI channel, except for %F0-$FF. The MIDI protocol is very specific about how many data bytes follow a status byte. The most common number is two. Data bytes have different meanings depending on the status byte they're associated with. Data bytes can indicate which key was pressed down, which key was released, how loud the note is, what button was pushed, whether the sustain pedal is up or down, and the position of knobs, wheels, and sliders.
You'll use the NOF (8n), NON (9n), Control Change (Bn), and Program Change (Cn) messages in your midterm project. You can ignore the others for now.
Status |
Number Data Bytes | Data 1 (0-127) |
Data 2 (0-127) |
Description | |
Note Off (NOF) | $8n | 2 | Note Number | Velocity (ignored) | Turns off the note on the specified channel |
Note On (NON) | $9n | 2 | Note Number | Velocity | Turns on the note on the specified channel using the specified velocity. Can also turn a note off sending a velocity of zero. |
Aftertouch (Poly) | $An | 2 | Note Number | Pressure value | Aftertouch is applied by continued pressure on the piano key after the note is played. Depending on the instrument you might get a vibrato, a swell, or nothing. This message applies to a single key. |
Control Change | $Bn | 2 | Control Number | Control value | Control the volume, stereo pan, sustain, plus many more. |
Program Change | $Cn | 1 | Patch Number | Not used | Select instrument sounds like flute, timpani, piano,or trombone. |
Aftertouch (Channel) | $Dn | 1 | Pressure value | Not used | Aftertouch is applied by continued pressure on the piano key after the note is played. Depending on the instrument you might get a vibrato, a swell, or nothing. This message applies to all notes on a single channel. |
Pitch Wheel | $En | 2 | Pitch Bend LSB | Pitch Bend MSB | Change the pitch of a note by moving the pitch wheel. |
System | $Fx | **** | Manufacturer Messages that
affect |
System tasks. Can be used to save and load complete synthesizer setups. |
|
n = Channels 1-16 ($0-$F) | |||||
x=$0-$F but is not related to channel |
The two MIDI messages you'll use most often are those that turn a note on (NON) and a note off (NOF). Both NON and NOF messages are three bytes long, a status byte followed by two data bytes. Each of the bytes has a specific meaning.
If the left hex digit of the status byte is an 8, it's a NOF message. If the left hex digit of the status byte is a 9, it's a NON message. The right hex digit of the status byte indicates which of the 16 MIDI channels the note is to be played on. According to users, MIDI channels are numbered from 1-16. According to the MIDI specification, MIDI channels are numbered from from 0-$F. You'll be using the zero based system. To send a NON message to channel 1 you'd use $90 as the status byte. To send a NOF message on channel 12 you'd use $8b for the status byte.
Data 1 byte is mapped a note on the piano keyboard. The full range of data bytes is from 0-127. The piano only has 88 keys. The lowest key on the piano is MIDI note number 21. The highest key is MIDI note number 108. Middle C is MIDI note number 60. The black and white keys are numbered consecutively. Because there are 12 half steps in an octave, when you add or subtract 12 from any MIDI note number you'll get that note one octave higher or lower. This picture shows the MIDI note numbers for all C's on the piano: 24, 36, 48, 60, 72, 84, 96, 108.
The data 2 byte is called velocity which indicates how soft or loud the the note is played. The MIDI velocity range is 0-127 with zero being silence and 127 being the loudest. Musical dynamics cover nine levels: silence (rest), ppp, pp, p, mp, mf, f, ff, and fff. It's up to you to determine how the velocity numbers are mapped to the nine dynamic levels.
There are two ways to turn a note off: use NOF status byte $8n, or use the NON status byte $9n and a velocity of zero.
MUSC 108 students always use NOF status byte $8n and velocity of 0.
Time | Status | Data1 | Data2 | Comments |
0 | 90 | 60 | 100 | NON on channel 0 with a velocity of 100 |
1000 | 80 | 60 | 0 | Wait 1000 ms then turn note off using |
NOF status and velocity = 0 |
The MIDI Patch Change message is used to change instruments. MIDIDisplay can use any of the 128 sounds specified in the "General MIDI Level 1 Sound Set" (GM) standard. Some GM charts number the instruments 1-128, others number them 0-127. You always need to remember that MIDI data bytes are zero based. This is one of the few MIDI messages where the data 2 byte is not used. Important: MIDIDisplay expects the $Cn message to have two bytes: data 1 = patch number, data 2 = 0. Standard MIDI Files correctly expect only one data byte and using data2 will cause an error.
Status Byte (n=channel) | Data1 | Data2* |
Cn |
Patch Number 0 - 127 |
Used in MIDIDisplay Only * The MIDI standard defines the Patch Change message has a status byte followed by ONE data byte, data2 is not used. |
MIDIDisplay can display the GM instrument list in its help system.
You've used three MIDI status types in previous labs, $8n (NOF) and the $9n (NON) and $Cn (Patch Change). You'll also use the $Bn (Control Change) status messages in your project. MIDI Control Change messages are also referred to as Controller, Continuous Controllers, and CC messages. All MIDI Control messages use the status byte $Bn where n represents the MIDI channel followed by two data bytes. Data 1 byte represents the type of controller. Data 2 byte represents the data being sent to that controller. If the data 1 byte is 7, it's the Volume Control message (CC7) and data 2 indicates how loud the volume is. The other MIDI control messages you'll use in your project are Pan (CC10), Expression (CC11), Reset All Controllers (CC121) and optionally Sustain Pedal (CC64).
Status (n = channel) | Data1 | Data2 | Controller Name |
Bn | 7 | 0-127 | Volume |
Bn | 10 | 0-127 | Pan |
Bn | 11 | 0-127 | Expression |
Bn | 64 | 0-127 | Sustain Pedal |
Bn | 121 | 0 | Reset all controllers ALWAYS use as first message and last message on each track |
MIDI Control Message 10 adjusts the left/right placement of sound.
Controller Name | status | data1 | data2 | Notes |
Control number | Control value | |||
Stereo Pan | $Bn | 10 | 0-127 | 0 is far left 64 is center 127 is far right |
MIDI Control Message 64 determines whether the sustain pedal is up or down.
Up: any number 0-63. Use 0.
Down: any number 64-127. Use 127.
Controller Name | status | data1 | data2 | Notes |
Control number | Control value | |||
Sustain Pedal Up | $Bn | 64 | 0-63 | Use 0 |
Sustain Pedal Down | $Bn | 64 | 64-127 | Use 127 |
MIDI Control Message 10 adjusts the left/right placement of sound.
Controller Name | status | data1 | data2 | Notes |
Control number | Control value | |||
Reset All Controllers | $Bn | 121 | 0 | Should be first and last message in any Standard MIDI File |
In music dynamics refers to loud and soft. Dynamics may affect a single note like an accent; a two note group like a slur; or a long phrase with a crescendo and decrescendo. Dynamics define the meter and rhythmic pulse of the music by accent patterns in groups of two, three, or four notes. The dynamic contour of a phrase makes the music expressive. Dynamics also refers to the volume balance of one instrument compared to another in a mix.
MIDI provides three methods to control dynamics:
Why three? Here's a hypothetical situation. You decide to use velocity values for all dynamic changes in instrument one. You then add a second instrument and discover that instrument two overpowers instrument one and you need to increase all the velocities of instrument one. You then add instrument three and it overpowers instrument two so you reduce all velocities in instrument three. Later you decide you want instrument three to use a different sound but now the velocities are too soft. It gets worse as you add or change instruments. Wouldn't it be nice if every instrument had its own volume control knob that could control the balance of sound at the beginning of a song. That's the job of the MIDI Volume Control (CC7) message.
You're feeling good. All instruments are balanced and you can hear the rhythmic drive in each part. Now you'd like to make each instrument more expressive by adding crescendos and decrescendos to the phrases but you don't want to change the velocities that provide the rhythmic drive. Wouldn't it be nice if there was another control knob for each instrument that you could move up or down to shape the crescendos and decrescendos in each part. That's the job of the MIDI Expression Control (CC11) message. By inserting expression messages mixed in with NON and NOF messages you can create musically expressive phrases without changing the velocity.
Use velocity to produce single note accents and rhythmic drive in each instrument. Higher velocities are used on the strong beats and lower velocities are used on the weak beats. Note velocity sometimes affects the timbre of a note. Modern sample libraries have multiple waveforms for each note depending on the velocity. A piano library may contain samples of each note six different dynamic levels from pp to ff and choose samples based on velocity. A string instrument might use velocity levels to change bowing styles. A trumpet might create a growl effect within a certain velocity range.
MIDI Expression Control (CC11) should be thought of as a local volume control for a single instrument that can be used to create crescendos and decrescendos. It can also be used to shape the swell and decay of a long sustained note.
MIDI Volume Control (CC7) should be thought of as the master volume control. It is used at the beginning of the song to set the initial balance between instruments.
The MIDI standard does not specify how MIDI timing is done. That is left to the computer clock chip and the software programmer. There are three time systems used in MIDI software: Chronological time, Difference time, PPQ time. All three of them are implemented in MIDIDisplay.
When using Chronological time the software is constantly checking the time. The software just sits and waits until the clock time is greater than or equal to the MIDI time stamp. When it is, the message is sent. There are at least two drawbacks to this method: the constant checking of the clock takes time away from other tasks, and any tempo changes during playback require recalculation of all time stamps not yet played.
Difference time calculates the time difference between the note just sent and the next note. It is more efficient than chronological time because the difference indicates how long to wait before sending the next message. The software can create a timer (just like an alarm clock) that can be set to go off when the difference time has expired. Once the timer is set, it runs in the background leaving the computer free to do other tasks. When the timer goes off, the message is sent. Tempo changes can be handled easily because the difference time can be multiplied by the ratio of the original tempo (60 for your projects) and the current tempo setting.
In music notation all rhythm values are proportions of a quarter note. In PPQ time all note values are proportional to the PPQ value of a quarter note. A standard PPQ value is 480. PPQ time is similar to difference time in that timers can be programmed to go off when the PPQ duration has expired. PPQ time is easily converted to difference time by multiplying the PPQ value by the millisecond duration of one PPQ at the current tempo. The number of PPQs in one quarter note is chosen to provide an integer value for subdivisions of the quarter note down to the 128th note, including dotted values. Many software programs give you a choice of PPQ settings. These numbers have been used as PPQ values in various software programs. Rhythmic nuances can be expressed more precisely with larger PPQ values.
PPQ values | |||||
Multiples of 96 | 96 | 192 | 384 | 768 | |
Multiples of 120 | 120 | 240 | 480 | 960 | 3840 |
Multiples of 128 | 128 | 256 | 512 | 1024 |
You'll use a PPQ of 480 in this class.
Note Value | PPQ = 480 |
Whole | 1760 |
Dotted Half | 1440 |
Half |
960 |
Dotted Quarter | 720 |
Quarter | 480 |
Dotted Eighth | 360 |
Eighth | 240 |
Dotted 16th | 180 |
16th | 120 |
Dotted 32nd | 90 |
32nd | 60 |
Dotted 64th | 45 |
64th | 30 |
Dotted 128th | 22 or 23 |
128th | 15 |
The duration of a quarter note can only be determined if we know the tempo. Tempo is measured as beats per minute. Usually the quarter note represents one beat. The general formula for the duration of one quarter note, at any tempo, for any duration unit (seconds, milliseconds, or PPQ) is:
Duration Unit | Tempo | Formula | Duration of One Quarter Note |
Milliseconds | 60 | 1000 * 60/60 | 1000 milliseconds |
120 | 1000 * 60/120 | 500 milliseconds | |
Seconds | 60 | 1 * 60/60 | 1 second |
90 | 1 * 60/90 | 0.67 seconds | |
PPQ (480) | 60 | 480 * 60/60 | 480 PPQ |
100 | 480 * 60/100 | 288 PPQ |
Revised John Ellinger, January - September 2013