Take the 2-minute tour ×
Sound Design Stack Exchange is a question and answer site for sound engineers, producers, editors, and enthusiasts. It's 100% free, no registration required.

I'm creating a program to read/write MIDI files, but I've run into a problem that confuses me. There are 2 bytes dedicated to the number of tracks, which means that there could potentially be 65536 tracks. However, there are only 16 channels. Does this mean that there are 16 channels per track? Or are there really only 16 tracks allowed? And, is there a difference in meaning depending on whether you're in format 0, 1 or 2?

EDIT: I viewed this post, which says that there are 16 channels per track, but it might not be right, because it was in the context of a certain program: http://forum.cockos.com/showthread.php?t=78919

share|improve this question

migrated from avp.stackexchange.com Jan 24 at 18:30

This question came from our site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation.

    
I wrote a midi file generating program a while ago, in which I reassign channels to each midi track in the middle of the song, as well as instruments to each channel, to optimize performance and also increase the effective # of instruments to over 16 (since not all instruments are played all the time). Turned out to be a bad idea. While there was no problem in playing the midi files on standard media players like Windows Media Player or Winamp, when I tried to load the midi files into FL Studio, the instruments were all jumbled after the instrument reassignments. –  user9665 Jul 28 at 10:26
    
Therefore, it is best to not change any channel as well as track assignments after the start. Even the display of the various tracks in a midi file will be more straightforward in this case. –  user9665 Jul 28 at 10:26

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks for the excellent answer! –  JoshP Aug 25 '13 at 1:37

A channel is a set of tracks. Generally each channel would be a different instrument, though some instruments may use multiple channels. Tracks then contain different parallel information from that instrument.

For far more details on the subject than will fit in a Q/A format, I suggest taking a look at Wikipedia's article on MIDI, which has a lot of great detail.

share|improve this answer
    
Does this mean that you can have many tracks, each one pointing to a different channel? And, then, can you have more than 16 instruments, or is it limited to one instrument per channel? –  glaba Jul 29 '13 at 17:05
    
@glaba - channels have tracks, not the other way around. It's a nested relationship. Older original midi devices used a single channel, but I believe there are some newer midi devices that are complex enough that they use more than one channel. The tracks correspond to different things it needs to signal on simultaneously, but all the tracks on a particular channel are controlled by the same instrument, they just measure different parameters. –  AJ Henderson Jul 29 '13 at 18:20
    
Ok. Thank you. However, I have one more question. If all the tracks on a particular channel are controlled by the same instrument, and there are only 16 channels, then are you limited to 16 instruments in a midi file? –  glaba Jul 29 '13 at 21:12
    
@Glaba - I'm unsure of the details of a midi file. I'm talking about the Midi protocol (what actually goes on the line). I'm not 100% sure if the files have the same limitation or not. –  AJ Henderson Jul 29 '13 at 22:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.