MIDI Programming 101:
Program change (Preset), Control change, Note On/Off, and System Exclusive.
*******************************************************************************************
Most MIDI command strings consist of a status byte followed by one or two data bytes. The most notable exception to this is the System Exclusive which starts with a status byte of $F0, has 4 or more data bytes, then ends with a status byte of $F7. Status bytes are always $80 or greater. Status bytes are always denoted in hexadecimal. Data bytes are always less than $80 (128 in decimal). Data bytes may be denoted in either decimal or hexadecimal. Program change, Control change, and Note On/Off are the most often used of the MIDI "Channel Voice" commands. Since they are standard MIDI commands they are almost never explained in manufacturers programming manuals.
*******************************************************************************************
The Program change is denoted by status byte $C0 (for MIDI channel 1) through status byte $CF (for MIDI channel 16), followed by one data byte:
SEND_STRING MIDI,"$C0 + (MIDI_CHANNEL - 1), PROGRAM - 1"
Specific example, to recall preset 128 on MIDI ch 1:
MIDI_CHANNEL = 1
1 - 1 = 0
$C0 + 0 = $C0,
PROGRAM = 128
128 - 1 = 127, thus the send string,
SEND_STRING MIDI,"$C0,127"
*******************************************************************************************
The Control change is denoted by status byte $B0 (for MIDI channel 1) through status byte $BF (for MIDI channel 16), followed by two data bytes:
SEND_STRING MIDI,"$B0 + (MIDI_CHANNEL - 1), CONTROLLER, VALUE"
Specific example set volume to 50% on MIDI ch 5:
MIDI_CHANNEL = 5
5 - 1 = 4
$B0 + 4 = $B4,
The standard MIDI Volume controller is 7,
127 * 50% = 64 (approximately), thus the send string,
SEND_STRING MIDI,"$B4, 7, 64"
Selected MIDI controller numbers:
BANK SELECT MSB = 0
VOLUME = 7
PAN = 10
EXPRESSION = 11 (* A SECOND VOLUME CONTROL *)
GENERAL PURPOSE CONTROLLER # 1 = 16
GENERAL PURPOSE CONTROLLER # 2 = 17
GENERAL PURPOSE CONTROLLER # 3 = 18
GENERAL PURPOSE CONTROLLER # 4 = 19
BANK SELECT LSB = 32
HOLD = 64 (* 2nd data byte of 63 or less = OFF, 64 or greater = ON *)
REVERB SEND = 91
EFFECTS 2 DEPTH = 92
CHORUS SEND = 93
EFFECTS 4 DEPTH = 94
EFFECTS 5 DEPTH = 95
ALL SOUND OFF = 120 (* 2nd data byte is always "0" *)
RESET ALL CONTROLLERS = 121 (* 2nd data byte is always "0" *)
*******************************************************************************************
Note On is denoted by status byte $90 (for MIDI channel 1) through status byte $9F (for MIDI channel 16), Note Off is denoted by status byte $80 (for MIDI channel 1) through status byte $8F (for MIDI channel 16):
SEND_STRING MIDI,"$90 + (MIDI_CHANNEL - 1), Note, Velocity" (* Note On *)
SEND_STRING MIDI,"$80 + (MIDI_CHANNEL - 1), Note, Velocity" (* Note Off *)
Most modern controllers send a $90 note on with velocity 0 for note off (We'll save the reason why for MIDI programming 102):
SEND_STRING MIDI,"$80 + (MIDI_CHANNEL - 1), Note, 0" (* Note Off *)
Specific example, Middle C (Note #60) on, on MIDI ch 6. If you're not sure what velocity to use try something between 64 (half) and 127(full), how about 96?
MIDI_CHANNEL = 6
6 - 1 = 5
$90 + 5 = $95
Note = 60
Velocity = 96, thus the send string,
SEND_STRING MIDI,"$95,60,96"
To turn the same note off:
SEND_STRING MIDI,"$95,60,0"
*******************************************************************************************
Most System Exclusives start with $F0, then a three byte system exclusive address, then more data bytes as determined by the manufacturer, then an end byte of $F7. Unlike the channel voice messages which are part of the MIDI standard, the system exclusives are usually well explained in the manufacturers programming manual.
One exception to this is MMC, or MIDI Machine Control. It's part of the MIDI standard. These MMC commands were captured from a Roland FC-200 MIDI Foot Controller. The address of "$F7,$F7,$06" means "Universal Realtime Message, Broadcast, MMC". Then there is a single data byte followed by the end byte $F7.
(* MMC STOP *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$01,$F7"
(* MMC PLAY *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$02,$F7"
(* MMC DEFERRED PLAY *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$03,$F7"
(* MMC FAST FWD *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$04,$F7"
(* MMC REW *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$05,$F7"
(* MMC RECORD STROBE *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$06,$F7"
(* MMC RECORD EXIT *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$07,$F7"
(* MMC RECORD PAUSE *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$08,$F7"
(* MMC PAUSE *) SEND_STRING MIDI,"$F0,$7F,$7F,$06,$09,$F7"
*******************************************************************************************
A good source of generic MIDI programming information is the MIDI Manufacturers Association website. Check out http://www.midi.org/about-midi/table1.htm 02/27/01