Post by JohnG on Jul 5, 2011 13:49:16 GMT
An introduction to MIDI.
It struck me recently that, although I had written a basic introduction to MIDI on other forums (fora?), I didn't really have a simple introduction, for beginners, here on my own site. So here goes.
What is MIDI?
Well, the letters stand for Musical Instrument Digital Interface. But you already knew that, didn't you?
Let's just pause a moment and think what that means.
"Musical Instrument." Well, I feel pretty sure that anybody reading this will know what that means.
"Digital Interface." Now we might have hit upon a more problematic area.
The "digital" must mean that it works in a similar way to many of our modern appliances. The CD, the DVD, the smart phone and, most importantly, the home computer, be it a PC or a Mac.
And the "interface" means the mechanism (the plug, socket and cable) by which we can connnect one of these devices to another MIDI device. Although, these days, that might be by a cable we call a USB cable, at the time MIDI was invented USB didn't exist, so a special set of connectors had to be invented, as well as the way MIDI data was sent across that connection.
(More about MIDI data in a little while.)
It's well worth while going back and looking at the history of MIDI, after all it is now more than thirty years ago that the MIDI standards came into being.
A bit of MIDI history.
It was way back in the early eighties that it was seen by one or two visionary people (Dave Smith of Sequential Circuits most notably (think Prophet synthesisers)) that a method of connecting devices together, which was common to all manufacturers, would be a great idea.
In other words "a standard".
Up until that point there were many proprietary systems for interconnection, each one unique to each manufacturer.
That didn't allow, for instance, a Roland keyboard to be connected to a Yamaha sound module.
What was needed was a simple system, that was very low cost to implement, yet robust enough and could transmit a reasonable distance to be used on stage, to be designed for use by all.
The five pin, 180 degree DIN plug already existed and was suitable for the job and cheap enough, so that was chosen.
For many applications transmission in one direction was all that was needed, so a simple three wire system was sufficient for that.
Two wires for the signal and one, the screen, to protect those two from electrical interference.
To send MIDI data from one device to another we connect the MIDI Out connector on one device to the MIDI In connector on the other.
The internal electrical circuit for transmission and reception was again chosen for simplicity and low cost, yet sufficiently robust to do the job effectively.
Next, the transmission speed was considered.
These days, we're so used to speeds up in the mega or even giga bits per second, that we don't perhaps consider what could be done back in the early eighties.
We forget that the IBM PC had, only recently, been introduced.
It used an Intel 8088 processor and five and a quarter inch floppy disks (they really were floppy in those days).
Hard disks didn't yet exist that could fit within the cabinet of a PC.
It ran at just a few megahertz, compared to the gigahertz of a modern computer.
That's a thousand times slower.
Inside a computer of those days there was a timer that ran at 1 MHz. (A million ticks per second.)
Timing for all the connected devices was taken from that "clock".
Try dividing a million by two a few times, and you'll end up with 31,250.
The electronic chip chosen to do the transmission could work successfully at that speed, and it also meant that, with a good quality cable, the MIDI data could be sent at distances of up to about 50 feet or 15 metres.
So far so good(?).
MIDI data.
Now that we've decided how, physically, we're going to connect our devices together, we need to decide just what it is we want to send.
Starting from basics, when we press a key on a keyboard, we want to tell the other device what key we have pressed, C, A, whatever.
When we release the key we need to send that information too.
So we need to have, at the very minimum, two message types, let's call them Note On and Note Off.
We need to have a way of defining what note we pressed or released, that's the Note Number. Middle C is note number 60.
And one more thing, we need to define how hard we played the note, quietly or loudly, that's called Note Velocity.
(There is more, but we'll come to that later.)
The question is, using a digital system (that is, bits and Bytes,) how many Bytes do we need for each message?
We need one Byte to define the message type (Note On or Note Off), one Byte to define the Note Number, and one for the Note Velocity.
So each Note message can be transmitted using just three Bytes.
A Byte is capable of holding 128 different values for note.
A full size piano has 88 notes.
So a byte allows us to define notes more than an octave below and above what a piano is capable of playing.
It should be enough.
A byte is capable of defining 127 different values for Note Velocity. (Zero means no sound.)
Is that enough?
Well, when we look at e.g. an orchestral score, we normally find that just eight dynamic levels are defined.
From fff (forte fortissimo or very, very loud) through ff, f, mf (mezzo forte), mp, p (piano or quiet), pp and ppp.
(Actually, fff and ppp are seldom used.)
So 127 values allows 16 variations of each dynamic level. 16 variations of forte, 16 of piano, and so on.
It should be sufficient.
Across the MIDI interface, running at 31,250 bps, each three Byte message can be transmitted in just a thousandth of a second.
Is that quick enough that we won't notice the tiny lag in time?
Yes, it is. Most people will only notice a time lag as it approaches a hundredth of a second.
Summary.
So now we know about the interface itself, and the basic structure and speed of MIDI data via that interface.
We have 5 pin DIN connectors labelled MIDI In and Out.
Data travels from Out to In at 31,250 bits per second.
MIDI messages are (typically) just three Bytes in length and take a thousandth of a second to travel.
MIDI messages about notes contain the message type, On or Off, the note number, and the loudness of the playing of the note.
Questions.
Q. What happens when we play a chord of, say, three notes.
A. Three consecutive Note On messages are sent maybe C on, E on and G on.
And when we release, three consecutive Note Off messages.
Q. Does the fact that they don't get sent simultaneously matter?
A. Usually not, because actually, there is often a slight gap in how we play them, because of the different lengths of our fingers.
The difference of a thousandth of a second or so is usually unnoticeable.
AND, MIDI has a clever trick.
If the message type (Note On) of the second message is the same as the first, then there's no need to send the message type again.
We just send the note data and the note velocity, so we save one byte, and again for the third note.
So we get Note On C, E, G, rather than Note On C, Note On E, Note On G. Clever eh?
Controlling the sound.
Not only do we want to send "note data", we may also want to send control data.
Just what is meant by "Control" data?
Many instruments, including a piano, have pedals to control the way it sounds, often referred to as loud and soft pedals.
We might have similar pedals connected to our electronic keyboard, or one to control volume, sometimes referred to as a "swell" pedal, as on a church organ.
Many modern instruments have two rotary controls, or a joystick built in, to the left of the keys.
These can be used to change the sound in some way, often bringing in vibrato, or altering the pitch of the note being played, Pitch Bend.
These are also sent in just three bytes.
One to define the message type (a control message), the second to define which control it is, and the third to define the "value" of the control.
As we press the pedal a "pedal on" message is sent, and a "pedal off" when we release it.
With a volume pedal, a whole series of messages may be sent, one after another, to mimic the current pedal position.
The Pitch Bend control has a message type all of its own.
Because human hearing is very sensitive to changes in pitch, we need more than just 128 numbers to represent the change in pitch.
So we use one byte for the message type and two bytes for the value. (Still just three bytes in total.)
This gives us NOT 128 plus 128 values, but 128 times 128 or, more than 16 thousand values for pitch.
A very sensitive control.
Many modern keyboards have dozens of rotary knobs, faders and buttons, and as we move these so some sort of controller message may be transmitted from the keyboard to a MIDI attached sound module.
So, there are many more controller messages, but I'm not going to detail them all here, it's the gist of what is happening, as we play our keyboards, that I want you to grasp.
But a few final controls just to finish off.
Clearly, at the beginning of a song we need to tell the MIDI device what instrument sound is required, a piano or a saxophone or whatever.
In order to do this a "Program Change" message needs to be sent right at the start.
If we send no such message then the default will be a grand piano.
However, gone are the days when a keyboard had just 128 sounds within it.
Nowadays we might have close to a thousand to choose from.
This choice is effected by sending one or more "Bank Select" controller messages before the Program Change message(s) to choose the appropriate variation of sound that we require.
Bank Selects and Program Changes are all three Byte messages too.
A little more data.
Just to confuse matters a little, I haven't told you ALL about what is in a message.
In actual fact we only need half a byte to contain the "Message Type".
The other half is used for something known as the MIDI "Channel".
So what's a channel?
Often, with a keyboard, we can define a keyboard split.
So the lower, left hand side of the keyboard may play the bass and/or the chords with one instrument type, perhaps piano, and the upper, right hand side the melody with a different sound, maybe a flute.
To do this we need to send the note commands to a separate part of the sound module for each instrument type.
So we have, in advance, to send a program change for flute to channel 1, and one for piano to channel 2.
The note on messages for the chords will have channel 2 included in them, the melody notes, channel 1 included.
We can have a maximum of 16 channels per MIDI interface.
The drums (percussion) go on channel 10.
What about MIDI files?
MIDI files clearly record all these messages, PLUS, as it's stored data, we need to add timing information so the device or program playing back the messages knows exactly when to send the messages.
So, in between the messages "Delta Time" is inserted.
Delta time is not like a conventional clock, it is based on the speed and timing of the tune being played, hence its unusual name.
It is the time between the last message and the next one.
It allows the notes to be played back with great accuracy.
Clearly, the device playing the file, often a sequencing program, needs to know the tempo and various other bits of information in order to play back and display notation information accurately, so it will also contain Meta Data, some examples might be the tempo e.g. 110 b.p.m., what key the piece is in e.g. C#, and what time signature e.g. 3/4 time.
And that, together with the note on and off data plus control data constitutes the basic contents of a MIDI file.
Lastly, the standard.
All these things, and many more, had to be written down and agreed between the many musical instrument and computer manufacturers.
An organisation called the MIDI Manufacturers Association, the MMA, was created to do this.
They have a web presence on which much of the technical information can be found.
Warning! Be prepared to be baffled by technology if you visit it.
Hopefully, we now have an overview of what MIDI is.
There is a lot more, but it starts to get complicated!
If it seems complicated at first reading, try reading it again a bit more slowly.
Try a pause between each section.
If there are any questions don't be afraid to ask.
© John L. Garside, 2015.
It struck me recently that, although I had written a basic introduction to MIDI on other forums (fora?), I didn't really have a simple introduction, for beginners, here on my own site. So here goes.
What is MIDI?
Well, the letters stand for Musical Instrument Digital Interface. But you already knew that, didn't you?
Let's just pause a moment and think what that means.
"Musical Instrument." Well, I feel pretty sure that anybody reading this will know what that means.
"Digital Interface." Now we might have hit upon a more problematic area.
The "digital" must mean that it works in a similar way to many of our modern appliances. The CD, the DVD, the smart phone and, most importantly, the home computer, be it a PC or a Mac.
And the "interface" means the mechanism (the plug, socket and cable) by which we can connnect one of these devices to another MIDI device. Although, these days, that might be by a cable we call a USB cable, at the time MIDI was invented USB didn't exist, so a special set of connectors had to be invented, as well as the way MIDI data was sent across that connection.
(More about MIDI data in a little while.)
It's well worth while going back and looking at the history of MIDI, after all it is now more than thirty years ago that the MIDI standards came into being.
A bit of MIDI history.
It was way back in the early eighties that it was seen by one or two visionary people (Dave Smith of Sequential Circuits most notably (think Prophet synthesisers)) that a method of connecting devices together, which was common to all manufacturers, would be a great idea.
In other words "a standard".
Up until that point there were many proprietary systems for interconnection, each one unique to each manufacturer.
That didn't allow, for instance, a Roland keyboard to be connected to a Yamaha sound module.
What was needed was a simple system, that was very low cost to implement, yet robust enough and could transmit a reasonable distance to be used on stage, to be designed for use by all.
The five pin, 180 degree DIN plug already existed and was suitable for the job and cheap enough, so that was chosen.
For many applications transmission in one direction was all that was needed, so a simple three wire system was sufficient for that.
Two wires for the signal and one, the screen, to protect those two from electrical interference.
To send MIDI data from one device to another we connect the MIDI Out connector on one device to the MIDI In connector on the other.
The internal electrical circuit for transmission and reception was again chosen for simplicity and low cost, yet sufficiently robust to do the job effectively.
Next, the transmission speed was considered.
These days, we're so used to speeds up in the mega or even giga bits per second, that we don't perhaps consider what could be done back in the early eighties.
We forget that the IBM PC had, only recently, been introduced.
It used an Intel 8088 processor and five and a quarter inch floppy disks (they really were floppy in those days).
Hard disks didn't yet exist that could fit within the cabinet of a PC.
It ran at just a few megahertz, compared to the gigahertz of a modern computer.
That's a thousand times slower.
Inside a computer of those days there was a timer that ran at 1 MHz. (A million ticks per second.)
Timing for all the connected devices was taken from that "clock".
Try dividing a million by two a few times, and you'll end up with 31,250.
The electronic chip chosen to do the transmission could work successfully at that speed, and it also meant that, with a good quality cable, the MIDI data could be sent at distances of up to about 50 feet or 15 metres.
So far so good(?).
MIDI data.
Now that we've decided how, physically, we're going to connect our devices together, we need to decide just what it is we want to send.
Starting from basics, when we press a key on a keyboard, we want to tell the other device what key we have pressed, C, A, whatever.
When we release the key we need to send that information too.
So we need to have, at the very minimum, two message types, let's call them Note On and Note Off.
We need to have a way of defining what note we pressed or released, that's the Note Number. Middle C is note number 60.
And one more thing, we need to define how hard we played the note, quietly or loudly, that's called Note Velocity.
(There is more, but we'll come to that later.)
The question is, using a digital system (that is, bits and Bytes,) how many Bytes do we need for each message?
We need one Byte to define the message type (Note On or Note Off), one Byte to define the Note Number, and one for the Note Velocity.
So each Note message can be transmitted using just three Bytes.
A Byte is capable of holding 128 different values for note.
A full size piano has 88 notes.
So a byte allows us to define notes more than an octave below and above what a piano is capable of playing.
It should be enough.
A byte is capable of defining 127 different values for Note Velocity. (Zero means no sound.)
Is that enough?
Well, when we look at e.g. an orchestral score, we normally find that just eight dynamic levels are defined.
From fff (forte fortissimo or very, very loud) through ff, f, mf (mezzo forte), mp, p (piano or quiet), pp and ppp.
(Actually, fff and ppp are seldom used.)
So 127 values allows 16 variations of each dynamic level. 16 variations of forte, 16 of piano, and so on.
It should be sufficient.
Across the MIDI interface, running at 31,250 bps, each three Byte message can be transmitted in just a thousandth of a second.
Is that quick enough that we won't notice the tiny lag in time?
Yes, it is. Most people will only notice a time lag as it approaches a hundredth of a second.
Summary.
So now we know about the interface itself, and the basic structure and speed of MIDI data via that interface.
We have 5 pin DIN connectors labelled MIDI In and Out.
Data travels from Out to In at 31,250 bits per second.
MIDI messages are (typically) just three Bytes in length and take a thousandth of a second to travel.
MIDI messages about notes contain the message type, On or Off, the note number, and the loudness of the playing of the note.
Questions.
Q. What happens when we play a chord of, say, three notes.
A. Three consecutive Note On messages are sent maybe C on, E on and G on.
And when we release, three consecutive Note Off messages.
Q. Does the fact that they don't get sent simultaneously matter?
A. Usually not, because actually, there is often a slight gap in how we play them, because of the different lengths of our fingers.
The difference of a thousandth of a second or so is usually unnoticeable.
AND, MIDI has a clever trick.
If the message type (Note On) of the second message is the same as the first, then there's no need to send the message type again.
We just send the note data and the note velocity, so we save one byte, and again for the third note.
So we get Note On C, E, G, rather than Note On C, Note On E, Note On G. Clever eh?
Controlling the sound.
Not only do we want to send "note data", we may also want to send control data.
Just what is meant by "Control" data?
Many instruments, including a piano, have pedals to control the way it sounds, often referred to as loud and soft pedals.
We might have similar pedals connected to our electronic keyboard, or one to control volume, sometimes referred to as a "swell" pedal, as on a church organ.
Many modern instruments have two rotary controls, or a joystick built in, to the left of the keys.
These can be used to change the sound in some way, often bringing in vibrato, or altering the pitch of the note being played, Pitch Bend.
These are also sent in just three bytes.
One to define the message type (a control message), the second to define which control it is, and the third to define the "value" of the control.
As we press the pedal a "pedal on" message is sent, and a "pedal off" when we release it.
With a volume pedal, a whole series of messages may be sent, one after another, to mimic the current pedal position.
The Pitch Bend control has a message type all of its own.
Because human hearing is very sensitive to changes in pitch, we need more than just 128 numbers to represent the change in pitch.
So we use one byte for the message type and two bytes for the value. (Still just three bytes in total.)
This gives us NOT 128 plus 128 values, but 128 times 128 or, more than 16 thousand values for pitch.
A very sensitive control.
Many modern keyboards have dozens of rotary knobs, faders and buttons, and as we move these so some sort of controller message may be transmitted from the keyboard to a MIDI attached sound module.
So, there are many more controller messages, but I'm not going to detail them all here, it's the gist of what is happening, as we play our keyboards, that I want you to grasp.
But a few final controls just to finish off.
Clearly, at the beginning of a song we need to tell the MIDI device what instrument sound is required, a piano or a saxophone or whatever.
In order to do this a "Program Change" message needs to be sent right at the start.
If we send no such message then the default will be a grand piano.
However, gone are the days when a keyboard had just 128 sounds within it.
Nowadays we might have close to a thousand to choose from.
This choice is effected by sending one or more "Bank Select" controller messages before the Program Change message(s) to choose the appropriate variation of sound that we require.
Bank Selects and Program Changes are all three Byte messages too.
A little more data.
Just to confuse matters a little, I haven't told you ALL about what is in a message.
In actual fact we only need half a byte to contain the "Message Type".
The other half is used for something known as the MIDI "Channel".
So what's a channel?
Often, with a keyboard, we can define a keyboard split.
So the lower, left hand side of the keyboard may play the bass and/or the chords with one instrument type, perhaps piano, and the upper, right hand side the melody with a different sound, maybe a flute.
To do this we need to send the note commands to a separate part of the sound module for each instrument type.
So we have, in advance, to send a program change for flute to channel 1, and one for piano to channel 2.
The note on messages for the chords will have channel 2 included in them, the melody notes, channel 1 included.
We can have a maximum of 16 channels per MIDI interface.
The drums (percussion) go on channel 10.
What about MIDI files?
MIDI files clearly record all these messages, PLUS, as it's stored data, we need to add timing information so the device or program playing back the messages knows exactly when to send the messages.
So, in between the messages "Delta Time" is inserted.
Delta time is not like a conventional clock, it is based on the speed and timing of the tune being played, hence its unusual name.
It is the time between the last message and the next one.
It allows the notes to be played back with great accuracy.
Clearly, the device playing the file, often a sequencing program, needs to know the tempo and various other bits of information in order to play back and display notation information accurately, so it will also contain Meta Data, some examples might be the tempo e.g. 110 b.p.m., what key the piece is in e.g. C#, and what time signature e.g. 3/4 time.
And that, together with the note on and off data plus control data constitutes the basic contents of a MIDI file.
Lastly, the standard.
All these things, and many more, had to be written down and agreed between the many musical instrument and computer manufacturers.
An organisation called the MIDI Manufacturers Association, the MMA, was created to do this.
They have a web presence on which much of the technical information can be found.
Warning! Be prepared to be baffled by technology if you visit it.
Hopefully, we now have an overview of what MIDI is.
There is a lot more, but it starts to get complicated!
If it seems complicated at first reading, try reading it again a bit more slowly.
Try a pause between each section.
If there are any questions don't be afraid to ask.
© John L. Garside, 2015.