What MIDI is, what MIDI does.

While MIDI (Musical Instrument Digital Interface) can be used to play back songs from your sound card, or a chip in old console games, its main purpose is music production (it's also used for controlling lighting or anything that accepts the MIDI protocol). In music production MIDI is used to give performance information to samplers, drum machines , synths and many other musical devices. The first demonstration of the MIDI protocol was two synthesizers connected by MIDI cables, you play a key on one keyboard and the note would sound from the other. With a MIDI sequencer you can arrange songs using multiple musical devices. A MIDI sequencer (normally a computer running a sequencer program like Cubase VST or Cakewalk or Logic) sends information about what note to play, how long to play it, wether there is a pitch bend or filter sweep and many other things to a instrument/device which generates the actual sound. MIDI has no audio properties, it's just instructions, so when .mid files sound like crap it's because of your soundcard not the file. The classic example is that of the player piano, where MIDI would be the piano roll.

MIDI IN and MIDI OUT and MIDI THRU, oh my!

Here is an example of a basic MIDI setup with one musical device and a sequencer to play it. The MIDI cables are setup up so when you play a note on the synth it sends the information (what key was pressed, the velocity) from the MIDI OUT to the sequencers MIDI IN, which may record that information for later playback. When playing a song the MIDI out sends information to the synths MIDI in to play.
 ___________________
|Sequencer         |  
|            MIDI IN ----------
|            MIDI OUT ---      |
|___________________|    |     |
                         |     |
 __________________      |     | 
|SYNTHESIZER       |     |     |
|                  |     |     |  
|          MIDI IN===----      |
|          MIDI OUT== ---------|
|__________MIDI THRU
Here is the setup with two musical devices and a sequencer that has only one MIDI out. Here you would have to use the MIDI THRU. We are assuming the Sythesizer has a keyboard so it would be the instrument you would play on.
 ___________________
|Sequencer         |  
|            MIDI IN ----------
|            MIDI OUT ---      |
|___________________|    |     |
                         |     |
 __________________      |     |
|SYNTHESIZER       |     |   |  
|                  |     |     |  
|          MIDI IN===----      |
|          MIDI OUT==----------
|__________MIDI THRU=------    
                           |  
 __________________        |  
|Sampler           |     |         
|                  |     |      
|          MIDI IN===----      
|__________MIDI OUT== 


The more devices the more complicated this can get especially if you want instruments to be able to play eachother or want to draw diagrams of it in ascii.

The limitations of MIDI and How to make it work beter

MIDI surfaced in 1983 at the North American Music Manufacturers show in Los Angeles and is still the standard for sequencing in music production despite its many limitations. The main limitation being that MIDI is serial ("The MIDI data stream is a unidirectional asynchronous bit stream at 31.25 Kbits/sec. with 10 bits transmitted per byte (a start bit, 8 data bits, and one stop bit)"1). So that if you're trying to trigger 2 samples to play at the same time one will actually start playing an instant (not audible) later. If you try and trigger too many samples at the same time and have not optimized your setup there will be audible timing errors because MIDI can’t handle it and is trying to catch up, this sounds terrible. Another thing is that MIDI measures many variables between 0-127 (not note placement.). So the velocity of a kick drum is always between 0-127 which might not seem like a big deal but if you emulating real instruments something closer to infinity is necessary.

MIDI is cool, history wise, because it was so necessary when it came out. It’s a big part of why electronic music, and the techniques that came with it, became so huge. The fact that it hasn’t been replaced after almost 20 years is annoying. The alternative to using MIDI to control machines is voltage control which pre dates MIDI, lacks the functionality of MIDI but is dead on timing wise. The other option is doing everything in your computer with .wav and .aif files played by soft synths and soft samplers and forgetting about external hardware all togther (except a midi controller keyboard with lots of knobs). This option makes me sad but really does seem to be the most sensible for numerous reasons beyond the midi protocol.

If you want to make your MIDI work better try getting a sound card for each of the devices you are using. Or if that is too expensive then buy an extra sound card for your percussion parts. There is also a technique called running status which involves manipulating the information in the messages, I do not understand this technique. The other, probably best and easiest, option is an external MIDI box, MIDI Man makes a few good ones, I use an external MIDI box with 6 outs and have no timing problems.

Here is a neat quote about the inner workings of the MIDI IN jack.

"In a studio containing dozens of discrete components, ground loops from audio and power cables are always a danger - and the designers of MIDI didn't want their cables to contribute to the problem. In addition, the MIDI specification states that the actual shield connections on the MIDI jacks should never be attached to any chassis or electrical grounds. To prevent other possible electrical problems, MIDI IN jacks are not hardwired to the device on which they are mounted. Instead all MIDI IN jacks contain an optoisolator, which is an electronic device consisting of a tiny LED and a photocell. When the jack receives a bit the LED lights up, and the photocell responds by sending current into the rest of the receiving device. In this way, there is never any direct electrical connection between the MIDI encoding/decoding circuitry of two different pieces of equipment."2

1http://www.harmony-central.com/MIDI/Doc/tutorial.html#intro
2"MIDI for the Professional" by Paul D. Lehrman