This site ( Jeff Glatt - MIDI info ) has lots of information about MIDI.
The MIDI data stream protocol (what goes over the wire) is a stream of bytes (values 00000000-1111111 binary = 0-255 decimal = 00-FF hexadecimal).
Values 00-7F (0-127) are data bytes, used e.g. for the note number and/or many other parameters.
Values 80-FF (128-255) are status/command bytes, used for MIDI commands:
- 8x: Note On
- 9x: Note Off
- Ax: Key Pressure / Aftertouch (polyphonic - per key)
- Bx: Control Change (e.g. Modulation Wheel)
- Cx: Program Change (to select instrument/sound/voice)
- Dx: Key Pressure / Aftertouch (per channel)
- Ex: Pitch Bend
where x is the channel number.
The status bytes in the range 80-EF encode the channel number in the lower 4 bits (0000-1111 = 0-15 = 0-F). For example, 82 is a Note On command for channel 2. These status bytes are channel messages, because they are directed to one specific channel of a MIDI device.
Status bytes F0-FF are system messages, because they are directed to all channels of a MIDI device.
MIDI connections using classical (non-USB) hardware use round 5-pin DIN connectors and cables. To send MIDI data from device A (e.g keyboard) to device B (e.g. tone generator), you connect the MIDI-OUT port of device A to the MIDI-IN port of device B.
Next, you set the MIDI transmit channel of the keyboard to channel 0 and then you press a key. The keyboard will send a byte with the value 80 (8 = NoteOn, 0 = channel 0) over the cable to the tone generator, followed by two data bytes for note number and velocity. The tone generator receives these 3 bytes. Because the first byte specified channel 0, the tone generator uses the sound currently selected for channel 0 to play the note. The second byte specifies the note number (0-127) and the third byte specifies the velocity.
If the keyboard can be split into two independent regions for right and left hand, you can set the transmit channel for each region, e.g. channel 0 for right hand region and channel 1 for left hand region. Keys played on the right hand region will then be sent to channel 0 (status byte 80), keys played on the left hand region will be sent to channel 1 (status byte 81). The tone generator receives these notes indepently on two channels and can play the right hand notes on channel 0 with e.g. a piano voice, and the left hand notes on channel 1 with e.g. a string voice.
Older electronic organs usually had an upper and lower manual plus pedals played by foot, each sending on its own channel (e.g. 0=upper, 1=lower, 2=pedal). Therefore, the connected tone generator can play three different voices on three channels. If the manuals can be split, you can control even more channels (e.g. 0= upper right, 1= upper left, 2= lower right, 3= lower left, 4= pedal). Even older church or theater organs had even more manuals.
However, you can send at most 16 channels over one port, because there are only 4 bits available to encode the channel. If you need more channels, you need more ports, e.g. a second MIDI-OUT port to send channels 17-32.
These days, MIDI devices often use USB cables instead of the classical ports. This allows multiple virtual ports. For example, when I connect my Yamaha PSR-S950 keyboard to my PC via USB, the PC shows two virtual MIDI-OUT ports A and B connected to my keyboard, each with 16 channels. Using a sequencer program, I can send data on 32 independent channels (0-15 via port A, 16-31 via port B) to play 32 different instruments at the same time.
A sequencer program organizes its MIDI data in tracks. Each track can contain MIDI data for at most 16 channels. To play a song with 32 instruments, at least two tracks are required (channel 0-15 for port A in track 1, channel 16-32 for port B in track 2, ...).
A SMF0 file (Standard Midi File - format 0) has only one track. All channel messages as well as the channel-independent system messages are stored in one single track. That makes it hard to edit a track, because everything is one big pile of data.
A SMF1 file (Standard Midi File - format 1) can contain more than one track. For example:
- Track 1 contains the notes played by right hand with a piano voice on channel 0.
- Track 2 contains the notes played by left hand with the same piano voice on channel 0, too.
- Track 3 contains the bass voice on channel 1.
- Track 4 contains a clarinet voice on channel 2.
- Track 5 contains the drums on channel 9.
.. and so on ..
You can map channels to tracks pretty much any way you want.
For example, you can merge tracks 3 and 4 to a single track. Since bass uses channel 1 and clarinet uses channel 2, both voices can be played independently from each other. Merging bass and clarinet in one track doesnt make terribly much sense musically, but its technically possible.
Or you can merge tracks 1 and 2, since they both use the same channel and the same voice. But maybe you want to use two different piano voices for right and left hand. If you assign track 1 to port A and track 2 to port B, you can select two different voices.
Or you change track 2 from channel 0 to channel 3. Then you can use two different voices, even when both tracks are assigned to the same port.
The limitation is at most 16 channels per track.
If two tracks use the same channel (or channels) on the same port, they can be edited independently in the sequencer, but they cannot be played independently from each other, because when the sequencer sends the data in the tracks, all tracks assigned to port A get merged to one data stream. All tracks assigned to port B get merged to another data stream.
In the example above, a program change from piano to strings at measure 4 in track 1 will select strings for track 2, too - because both are using channel 0 on port A.
The correct mapping therefore depends on the architecture of the connected tone generator.