Sweet,sweet music
|
Sound editing systems need the MIDI link to make
music.
Roger Howorth
Following on from last month's brief look at MIDI hardware,
this month I'll examine in more detail exactly what 'commands' are available
to the MIDI programmer. This will be followed next month by a short Basic
program that will allow any computer with a MIDI interface to send and receive
data via MIDI.
A message for MIDI
The MIDI interface uses a handful of software commands to control a whole
range of hardware devices such as synthesisers, mixing consoles and effects
units. These commands are often called 'MIDI messages' and consist of one
'status' byte, which is the actual instruction, usually followed by one or
two data bytes that provide information relating to that instruction.
In order that the status and data bytes can be distinguished from each other,
the most significant bit of each byte sent across the MIDI interface is used
as a flag which, if set, indicates that the byte is a status byte; and, if
not, indicates it to be a data byte. This, therefore, limits the maximum
value that a MIDI byte can hold to a range of 7 bits or 0-127 (Fig 1).
Midi byte: |
Status byte: |
Data byte: |
This first bit is always used to indicate whether byte is 'Status' or 'Data' | Lowest four bits used for MIDI channel number, leaving only three bits for actual instruction | As a data byte is always associated with the preceding Status byte, no channel number is needed, leaving seven bits free for actual data |
Midi Message: |
||
|
||
First byte is always 'Status' |
Usually followed by one or two 'Data' bytes |
|
Fig 1. Breakdown of the MIDI byte |
MIDI as a network
MIDI can be thought of as a local area
network in that it is used to
link various pieces of microprocessor-based musical equipment together. It
normally operates on a crude 'star' topology (see the networks article, 'Run
around the clock', PCW, February 1987) which means there is one controlling
device that sends messages to a number of receiving ones.
However, unlike more typical star networks where all the receiving devices
are linked directly to the controller by their own cable, most MIDI hardware
only allows devices to be daisychained together, so they all effectively
share the same cable (Fig 2). This means that if a message is to be sent
to only one device on the daisy-chain, some form of software address must
also be sent to tell all the other devices to ignore that message.
MIDI achieves this by a system of software 'channels', which involve each
hardware device and each message (well, all right, except one) being assigned
a channel number in the range 1-16. A particular device will only respond
to a message if these two numbers match. The channel number is sent in the
first four bits of each status byte (Fig 1).
It should be noted that although Fig 2 looks suspiciously like an open ring
network, the 'slave' devices cannot communicate with each other - only the
controller can send messages. It is, therefore, a star system.
Fig 2. Diagram of the 'star' topology and 'daisy chain' links of the MIDI network |
The commands
Just as computers are programmed by a series of machine code instructions,
so MIDI devices are controlled by a few simple 'messages' which can be combined
to perform quite complex tasks, such as playing a piece of Beethoven.
Fig 3 shows the MIDI instructions and the number of data bytes that must
follow them. The first seven instructions are quite straightforward, but
here's a quick guide to all of them:
NOTE OFF Tells a synthesiser to stop sounding a particular
note. It has two data bytes: the first tells the synthesiser which note is
to be stopped; the second is the velocity. Imagine someone is playing a note
on a violin. If they were to stop playing the note instantly, then the sound
would also stop pretty quickly. But, if they were to gently slow down the
bow until it came to a halt, say, half a second later, then this would produce
a completely different sound.
NOTE ON Complements the NOTE OFF command. and uses two
data bytes for similar purposes. This message can also simulate a NOTE OFF
message if its velocity byte has a value of zero.
POLYPHONIC KEY PRESSURE/ AFTER TOUCH Contains information
about how a particular note is being played. It uses two data bytes: the
first identifies an individual note and the second carries the pressure value.
Imagine someone playing a trumpet: the sound produced varies depending on
how hard the trumpeter blows at any point in time. So, the sound of a synthesiser
can be varied depending on the value in the second data byte; however, polyphonic
key pressure allows a different value to be used for each note to be played.
This form of key pressure is usually only implemented on the more expensive
synthesisers on the market.
REAL TIME CONTROLLER CHANGE Most synthesisers are equipped
with a variety of realtime controllers, such as a sustain pedal (also found
on pianos). The controllers are either on/off-type switches,or wheels and
knobs which can produce a range of values from 0-127.
This MIDI message alters the value of these controllers, and has two data
bytes: the first identifies the particular controller ; and the second contains
its new value.
CHANNEL MODE This message is quite complicated and
gives very different results, depending- on the value in the two data bytes.
These results all closely linked to the hardware configuration of a synthesiser
and are too complicated to explain here; suffice it to say that like all
MIDI commands, they are well- documented in the 'MIDI Specification' which
can usually be found in the back of a MIDI synthesiser's manual.
PROGRAM CHANGE If a musician wants a synthesiser to
make a different sound, he or she presses a button on the front of the
instrument. These buttons might be labelled 'Piano' 'Organ' and 'Flute'.
PROGRAM CHANGE has the same effect as pushing one of these buttons.
CHANNEL PRESSURE/AFTER TOUCH This is similar to POLYPHONIC
AFTER TOUCH except that one pressure value relates to an entire MIDI channel.
This means that rather than each note having its own pressure value, each
instrument shares one. This form of after-touch is found on many of the cheaper
MIDI synthesisers.
PITCH WHEEL CHANGE Most synthesisers have a special
real-time controller that alters the tuning or 'pitch' of the instrument.
This is called the Pitch Wheel and is special because it uses two data bytes
to convey the controller's new position. This gives the pitch wheel a range
of 14 bits or 0-16383, as opposed to other MIDI controllers which only have
a range of 0-127.
Command |
Number of Data bytes |
Title |
|
Bin |
Dec |
||
1000XXXX 1001XXXX 1010XXXX 1011XXXX 1100XXXX 1101XXXX 1110XXXX |
128+X 144+X 160+X 176+X 192+X 208+X 224+X |
2 2 2 2 1 1 2 |
Note Off Note On Key Pressure Control Change Program Change After Touch Pitch Bend |
11110000 11110sss 11111nnn |
240 240+s 240+n |
???? 0 to 2 0 |
System Exclusive System Common System Real Time |
XXXX is the MIDI channel number. sss and nnn are switches to extend the meaning of commands. |
Fig 3. The MIDI instructions and accompanying data bytes
System messages
The group of System Messages is an interesting one. 'System Common' and 'System
Real Time' are linked to sequencing applications (see 'Musical Interlude',
PCW, October 1987), so I won't discuss them further here.
As far as 'System Exclusive' is concerned, MIDI's designers realised that
they couldn't plan for every future requirement, so this command allows
programmers and manufacturers to expand the MIDI instruction set indefinitely.
System Exclusive is the only MIDI message whose length is undefined - that
is, the number of data bytes which should follow the System Exclusive status
byte is unknown. Furthermore, the data bytes' definition is unclear.
Only two things are certain about the System Exclusive message, and one is
how it should end with an 'End of System Exclusive' status byte. The other
is that the first data byte to follow the System exclusive command is a
manufacturer's identification code, which is a number in the range of 0-127.
As its name suggests, this number is unique to a particular MIDI device
manufacturer.
When a device receives the System Exclusive command, it checks the ID code.
If it doesn't match the manufacturer's code, the device will ignore the data
which follows it; if it does match, however, the device will receive and
act upon that data. The only rule about the data is that it can only be in
the range 0-127.
What makes the System Exclusive message so useful is that it allows manufacturers
to invent new MIDI instructions which take advantage of their particular
product. In this way. it is possible to make anything MIDI-controllable -
even a kettle.
In practice, this message is often used to send bulk data dumps, such as
the data which instructs a synthesiser to make certain sound.
In practice...
It's very easy to experiment with MIDI messages and your home computer because
with the exception of 'system exclusive', it is necessary to send only two
or three bytes to a synthesiser in order to coax it into action.
In next month's Musical Interlude I shall present a very short and simple
Basic program that will allow a MIDI- equipped computer to communicate with
any other kind of MIDI device. Using this program two or more computers can
be linked to form a simple network, or if you have a synthesiser you can
examine exactly how the MIDI messages are composed and sent as the instrument
is used, and experiment with its reactions to messages that you send from
your computer.
Note: In the original article there was some confusion
about where the most significant bit was in the header and data bytes
respectively. Probably because of this,the table of commands (Fig 3) listed
the decimal upper nibbles as 128,129,130,131,132,133 and 134,and this cannot
possibly be the case,partly because they do not correspond with the binary
equivalents and partly because I've programmed MIDI and those numbers would
be changing the Channel Number not the Command.Apparently Roger was not very
good at binary arithmetic (or he had his data lines wired back to front).
Roger's Atari must have had a hard time deciphering his coding,and so too
would anyone's computer who utilised Roger's decimal versions of the binary
command list. The one's listed in Fig 3 (128-224) are the correct numbers,and
if you don't believe me,you can check by either computing them from the binary
(check Hexadecimal for help) or actually send
them to a keyboard or computer and listen or see for yourself.More evidence
if any were needed of the poor maths skills of the general populace.You'd
think a programmer would know better! -LB |
Author
Roger Howorth is a freelance computer journalist and sound
recording engineer who owns and experiments musically with an Atari ST. If
you would like to share your musical experience with Roger or you would like
to pass on any interesting snippets, why not write to him care of PCW VNU
House, 32-34 Broadwick Street London W1. |
Chaos | Quantum | Logic | Cosmos | Conscious | Belief | Elect. | Art | Chem. | Maths |