Messages consist of a status byte (80-FF) followed by 1 or 2 data bytes (00-7F).
Status bytes set the data receive mode, ie they only need to be sent when changing the status.
For example, to start 3 notes, you would not need to send the '9n' bytes shown here in brackets: 9n k1 v1 (9n) k2 v2 (9n) k3 v3.
Running status is not affected by system realtime messages, but is cleared by system common/exclusive.
MIDI is a serial link, via a 5mA, 31.25KHz opto-isolated current loop
It uses a 5-pin DIN plug & 2 core shielded cable: +ve pin 4, -ve pin 5, pin 2 to cable shield
Only MIDI OUT and THRU sockets should have pin 2 connected to ground to prevent earth loops (unfortunately, some reputable brands have pin 2 grounded on MIDI IN also!)
Logical 1 Start and Stop bits encapsulate each MIDI data byte (no parity)
Because the default state is off, MIDI leads can be safely connected while the equipment is live (obviously, it's recommended to do this while no messages are being sent!).
The active sensing realtime message can be used to test the integrity of the link.
Each MIDI byte + start/stop bits (10 bits) takes 0.320 mS to transmit
Most MIDI devices have a fixed buffer size, and therefore need time to respond (so wait 20-50mS between multiple SysEx message transmissions: at 240bpm 48 ticks at 192 ppqn = 62.5mS)
MIDI THRU is a buffered, but slightly delayed, duplicate of MIDI IN
MIDI OUT can often be set to merge MIDI IN with other generated MIDI events
PC to MIDI Interface
This circuit is just about redundant now: New PCs generally no longer have game ports, and USB MIDI interfaces are now relatively cheap.
Nevertheless, here's a circuit which you can use to connect MIDI devices to you PC.
In addition to this circuit, you need:
A "MIDI enabled" 15 pin connector on your PC.
These are common with sound cards (such as the Sound Blaster range), and double as a joystick connector.
An ordinary PC joystick plug is not sufficient.
This circuit can also provide a joystick through connection, so you connect both MIDI and joystick together.
MIDI software (such as a sequencer, patch library editor, etc).
You will need to set this to use your external MIDI port connection, instead of the internal MIDI mapper, or any sound card MIDI features.
A MIDI device to connect to the PC, this would commonly be a sound module, keyboard, or any device you want to save/restore patch settings via bulk dump/loads.
Here's the circuit.
I have built it, and it works well.
It gives you:
- 1 x MIDI IN
- 1 x MIDI THRU
- 2 x MIDI OUTs
- Separate LED indication of MIDI IN and OUT
- Powered from the PC port, so no power supply required
- Uses only 2 ICs; inexpensive to build
A kit for this project is available in Australia from Dick Smith Electronics (their catalog number K-3604) for under $40 Australian.
For this you get all parts, cables, connectors, and a screen printed top with a (larger than necessary) plastic box.
If you have no need for a joystick, you would only need to connect to the necessary pins on the PC connector, straight to the MIDI interface.
If you need to allow a joystick connection, you will need to connect all 15 pins at the PC through to a 15 pin socket for the joystick.
You can place this socket either inside the box, or (as I did) in line with the ribbon cable connector.
Take care with the pin numbers!