Midi
Midi
INTRODUCTION:
What are MIDI files exactly? We've all seen them at one point or
another. These files have the .mid extension and hold data to play
music, on a computer, through a sound card's Sound Synthesis
electronics. If the sound card is of atleast good quality, MIDI files can
play quite nicely. Not to mention that MIDI files hold the most amount of
music related information in the smallest size. This is often the reason
why they are used in games to hold musical sound tracks pertaining to
the game.
This first part of the series will cover some basic knowledge and
concept about MIDI and MIDI files which will serve as background
knowledge to build on in the other parts of the series. So let's get
started, we have alot of ground to cover. Basically, I'll be packing this
first part with as much information that you're gonna need in the next
part of the series. This series is for anyone interested in creating
specific MIDI related applications whether it's simple tools, to full
fledged software sequencers, to anything else that related to MIDI and
Software Development. To those of you I say: "You wanted the gory
details, the how tos and the what not? Here they are!".
WHAT IS MIDI:
M.I.D.I. stands for (Musical Instrument Digital Interface) and is
essentially a standard that was created when electronic music was first
created. When electronic music surfaced, back in the 70s, the need for
two instruments to communicate quickly became apparent. Likewise,
new instruments were created and obviously a need for a certain
standard so that instruments created by different manufacturers could
communicate in a networked environment so they could be controled
from other instruments as easily as possible was also becoming quite
mandatory.
Throughout the years, since the first MIDI standard was created, MIDI
demands and needs have grown and somewhat changed to
accomodate the growing needs of electronic MIDI music and their
manufacturers. So then, let's take a look at the four most wide spread
MIDI Standards.
Roland GS Standard:
Once the G.M. Level 2 was established, Roland created it's own
brand of sub standards (especially in System Exclusive data) And
NRPNs to be implemented in all new MIDI gear from then on out. In
essence, the Roland GS standard is G.M. Level 2 plus Roland
specific features and functionality. Since the Roland GS specification
isn't obvious to come by. It's best to go for G.M. Level 2 atleast until
Roland makes the Roland GS standard publically available to
everyone.
Yamaha XG Standard:
Like Roland, Yamaha also created their own set of specific NRPN
and Sysex features in order to give their MIDI gear their own blend of
Yamaha specific Features. Yamaha is very open in sharing their
specifications with anyone willing to have them. As such they have
made their XG specifications available right here. Feel free to get
this to see exactly what XG implements from G.M. Level 2 and adds
to it too.
o Right after are the four following bytes [00 00 00 06] and this
will always be the same. It represents the four byte size of the
header.
o Next we have 2 bytes [FF FF] which represent the file format.
There are three such formats. They are:
0 => single-track
1 => multiple tracks, synchronous
2 => multiple tracks, asynchronous
o Finally, the last two bytes [dd dd] is the number of delta-time
ticks per quarter note. In other words it's the resolution (in time
precision) that a note can be played at in a time span. More on
this later.
o The first four bytes [4D 54 72 6B], like the header chunk,
represent "MTrk" and is a header for the track itself.
o The last four bytes [xx xx xx xx], represent the length of the
track in bytes.
After these eight bytes is a series of MIDI events. These events are
identical to the actual data sent and received by MIDI ports on a synth
with one addition. A midi event is preceded by a delta-time. A delta
time is the number of ticks after which the midi event is to be
executed. A MIDI event has a structure, let's review that structure
right now.
The status and channel Bytes are merged into one byte (00-FF)
Because these messages have an MSB (Most Significant Byte) of 1 the
command statuses actually begin at 80 hexadecimal (128 and up to
255) The LSB (Least Significant Byte takes a value of 0-F Hexadecimal
(0 to 15) to specify which MIDI channel the command will be sent to. A
command message tells the MIDI gear to perform certain types of
things like play a note, change the volume, add effects, and other types
of things. This table shows the different command status and what they
do.
Status Comment
F8 Clock
F9 (undefined)
FA Start
FB Continue
FC Stop
FD (undefined)
FE Active Sensing
FF System Reset
The contents of the SysEx message can be anything the MIDI gear
can do. It can be a whole bunch of different things too that would be
needed to set the keyboard into the right configuration to play the song
for example. Could be asking the keyboard to dump it's current SysEx
setup so that it can be used later as another example. SysEx, in itself,
becomes more than useful quite quickly when you really want to
control, at the finest detail, the performance of a song on a given MIDI
gear.
There are four SysEx messages that are known as Universal SysEx
Messages. This means that they do not apply to any specific
manufacturer. Instead they server to help the whole MIDI system (or the
computer) get information about the MIDI gear that is connected to the
MIDI system. Here are these Universal SysEx messages.
Master Volume:
This Universal SysEx message adjusts a device's master volume.
Remember that in a multitimbral device, the Volume controller
messages are used to control the volumes of the individual Parts. So,
we need some message to control Master Volume. Here it is.
0xF0 SysEx
0x7F Realtime
0x7F The SysEx channel. Could be from 0x00 to 0x7F.
Here we set it to "disregard channel".
0x04 Sub-ID -- Device Control
0x01 Sub-ID2 -- Master Volume
0xLL Bits 0 to 6 of a 14-bit volume
0xMM Bits 7 to 13 of a 14-bit volume
0xF7 End of SysEx
Identity Request:
Sometimes, a piece of MIDI equipment might wish to know what other
devices are connected to it. For example, a Patch Editor software
running on a computer may wish to know what devices are connected
to the computer's MIDI port, so that the software can configure itself
to accept dumps from those devices. The Identity Request Universal
Sysex message can be sent by the Patch Editor software. When this
message is received by some device connected to the computer, that
device will respond by sending an Identity Reply Universal Sysex
message back to the computer. The Patch Editor can then examine
the information in the Identity Reply message to determine what
make and model device is connected to the computer. Each device
that understands the Identity Request will reply with its own Identity
Reply message.
The SDS standard is a fairly complex system that doesn't simple use
a message like the other three Universal SysEx. Instead it has
different sets of commands to get different types of information or
send different types of information to the Sample Based MIDI gear.
To find out what these messages are you can read this to get the full
details.
IN CONCLUSION:
Well I think I've packed enough information for a first part of a series.
After you've digested this information there's no doubt in my mind that
you'll know alot more about MIDI files than you do now. This is really
only the beginning. After you read this once, you should just consider
this as a reference to what lies ahead in the series. There's no need to
remember every single piece of information (unless you really want to)
as you can just refer to this page whenever you like. There was alot of
ground to cover and I think we did just that.
In the next part of the series, we'll start putting all this information to
good use by creating a program that can read a MIDI file, parse it's
contents and put them in a structure we'll define in order to view them
and manipulate them as we see fit. So brace yourself, there's plenty of
coding up ahead in your future. As I mentioned, there's alot of
information here. If anything isn't quite clear, you might want to email
me your questions and we'll see to it that all becomes as clear as it can
be. Until next time. Happy reading, understanding and coding!.
MystikShadows
Stéphane Richard