Magazine Archive

Home -> Magazines -> Issues -> Articles in this issue -> View

Adventures In MIDILand (Part 1)

Article from Sound On Sound, August 1990

Part 1: Martin Russ sets off on a wild and wacky expedition through the MIDI Programming Jungle.


One of the feedback comments which consistently arose during the 'System Exclusive' series, was "When are you going to do the same for ordinary MIDI?". My answer is in your hands at this moment!

INTRODUCTION



Before we set off into the land of MIDI, a few words of warning. We will be going where the natives have probably never seen the sort of crazy, mixed up, messed about with MIDI messages we will be using, so you need to be on your guard.

All sorts of unexpected things may happen, so always be ready to powerdown anything which locks up or starts throwing out loud noises. Despite the serious nature of this warning, remember that many earlier explorers have already passed through without suffering casualties. I myself have come face-to-face with some of the nastiest MIDI problems imaginable, and survived.

In the course of our exploration we will discover some unusual and interesting things, so be prepared to make further investigations on your own. This trip is designed to help you learn by showing you some of the more exotic denizens of the world of MIDI. You will find some useful tools on the toolkit disk: the rest of this series will explain how to use them.

BEFORE SETTING OFF...



Before setting off you will need the following equipment (in approximately descending order of importance):

  • An Atari ST (all the program examples are for the ST only).
  • Some knowledge of MIDI messages and computers.
  • A MIDI-equipped keyboard which we will use as a master keyboard. Velocity and Aftertouch (Channel Pressure) sensitivity are almost essential. If it has 'Local Off' control, then it may be used to replace an expander as the sound source.
  • A MIDI sound expander (or expanders) which will be used to generate the sounds. Ideally, these expander(s) should be multitimbral, ie. capable of playing several different sounds simultaneously.
  • A drum machine will be useful if you are interested in drums and synchronisation.
  • A Thru Box and MIDI Switcher might also prove useful.
  • Although not essential, HiSoft Power Basic will be needed if you intend to alter any of the programs for your own purposes.

PREPARATION



The basic connection of the MIDI equipment is very straightforward. The Out of the MIDI keyboard is connected to the In of the ST, and the Out of the ST is connected to the In of the expander (Figure 1).

Figure 1.


More advanced MIDI users may like to experiment with adding a Thru box and MIDI Switcher (Figure 2). This will help in setting up, and can also add increased functionality. It also helps integration into a conventional MIDI network.

Figure 2. One of the alphaSyntauri's eight voices.


SOFTWARE



There are going to be lots of programs used in this series — more than 30 in total. With a few exceptions, all the programs are short and simple, and they are designed to illustrate the important points but not necessarily provide everyday usage in a working MIDI studio. (See panel for details of where to obtain the floppy disk containing the example programs from this series.) If you are interested in taking any of the ideas further, then a professional sequencer is probably a good place to start looking for the relevant features. If a serious, high-specification sequencer cannot achieve the effects you want, then write to the manufacturer and ask why not — often they will have hints and tips for doing most things.

The more complex and serious programs in this series are designed to show what can be done by taking the basic ideas and developing them. The source code will be supplied only for the simpler programs, although the basic operation of all programs will be described to show the principles of how they work. In most cases, it will not be necessary to follow the programming examples to understand what is going on, but you will get more out of the series if you do.

Because the Atari ST will be fully occupied doing MIDI processing, it may be useful to find another ST owner and use the second ST to monitor the MIDI messages, or even run a sequencer. Such a combination is a very powerful creative tool for the serious MIDI explorer, and anyway, it is more fun investigating things with a friend! One of the major side-effects of MIDI is that it seems to produce musicians who hide away in home studios. I hope this series encourages you to share your investigations with other people — the result will be a much richer and more rewarding experience.

THE BEGINNING



Just about the only thing I will not be talking about are System Exclusive messages — anything else is fair game. I suggest that you make sure you are aware of the important points about MIDI before proceeding. Most of the exploration will focus on MIDI Channel Voice messages, with just a few System messages. In past issues, Sound On Sound has published some excellent articles covering the basics of MIDI, and some of the books in the SOS Bookshop (see p.77) are good references, too. From here on, things get tough!

The initial starting point for any investigation of how to manipulate MIDI messages involves looking at exactly what is happening. The 'System Exclusive' series [SOS April '89 to March '90] introduced two sophisticated programs which displayed MIDI messages in graphical form on-screen, but gave no clues as to what they were doing. This series will start out by revealing how the programs are working, although the MIDI Display program is much simpler, with a clear and concise text output only.

LOOKING AT MIDI



Incoming MIDI data appears at the ST's Port number 3, and outgoing data should therefore be presented to Port 3. This means that you can read the MIDI In port just as easily as the keyboard. So just as this program segment

Pause = INP(2)

makes the program pause until one of the ST's QWERTY keys is pressed, so this program segment

Pause = INP(3)

makes the program pause until a MIDI message is received at the ST's MIDI In socket. Because the ST is a 16-bit machine, it assumes that the incoming data from the MIDI port is also in 16-bit format, so you need to chop it down to 8-bit to produce ordinary MIDI data bytes:

MIDI_input = INP(3) AND &HFF

By using logical operations on the incoming MIDI data, it is possible to mask out the various parts which may be of interest:

Status = INP(3) AND &H80

This program segment sets the variable Status to $80 if the MIDI byte is a status byte — ie. if the most significant bit is 1 (or any bytes from $80 to $FF). Otherwise, Status is set to zero — so for MIDI data bytes the Status will be zero. Similarly, this program segment

MIDI_byte = INP(3)
IF (MIDI_byte AND &H80) = &H80 THEN
Channel = MIDI_byte AND &H0F
END IF
Channel = Channel + 1


checks that a Status byte has been received, then sets the variable Channel to the value of the MIDI channel and increments the value by one to give the normal representation. Remember that MIDI Channel 1 is represented by $0 in the actual MIDI messages.

By placing this sort of segment inside a loop, it is possible to make a simple MIDI Display program. The lowest level just displays the raw bytes:

start:
MIDI_byte = INP(3) AND &HFF
PRINT " ";HEX$(MIDI_byte);
escape$ = INKEY$
IF escape$ <> "" THEN GOTO leave
GOTO start
leave:
STOP -1


In this segment the program flow goes around a loop formed by the start label and the GOTO start statement. Inside the loop a MIDI byte is input and masked to eight bits, and is then printed out in hexadecimal. Exiting the loop is made possible by detecting the pressing of a key on the ST's QWERTY keyboard.

This loop will form the fundamental structure of almost all the program segments which follow. The two lines containing escape$ are included so that it is possible to leave the loop by pressing any key on the ST's keyboard. Notice that this will only work if the ST receives a MIDI message, since otherwise the INKEY$ statement is never executed. This is a common feature of all the programs which follow in this series. Normally, Active Sensing messages will mean that you can leave the loop at any time, but if these are not present then playing a note should also cause the loop to be exited, since the keyboard will then be read by the INKEY$ statement.

By using the already developed Status byte detector, it is possible to extend this loop segment so that it has a more meaningful display:

start:
MIDI_byte = INP(3) AND &HFF
Status_test = MIDI_byte AND &H80
escape$ = INKEY$
IF escape$ <>"" THEN GOTO leave
IF (Status_test = &H80) THEN PRINT
PRINT " ";HEX$(n);
GOTO start


This segment incorporates the test for a status byte and produces a new line in the printout. This means that the screen display shows the status byte followed by the data bytes, with each new status byte on a new line. Presenting the information in a clear way can make it much easier to interpret the MIDI data.

I have already mentioned Active Sensing, and if this MIDI message is active on your master keyboard, then you will see lots of $FE messages causing the display to scroll upwards. This can be rectified by removing any Active Sensing messages:

start:
n = INP(3) AND &HFF
a = n AND &H80
escape$ = INKEY$
IF escape$ <> "" THEN GOTO leave
IF (n=&HFE) THEN GOTO start
IF (a = &H80) THEN PRINT
PRINT " ";HEXS(n);
GOTO start

This program segment also replaces the variable MIDI_byte with the more manageable n, and similarly the variable a replaces Status. The new line, shown in bolder type, causes the program to go back to the 'start' label and so miss out the statements which print out the MIDI bytes — thereby filtering out just the Active Sensing bytes.

An expanded and extended version of this simple program, incorporating Active Sensing filtering which can be switched in and out by pressing the spacebar on the Atari ST, is our first program of this series. All the programs are given slightly cryptic filenames, because of the problems of fitting them into only eight characters, so this program is called MDISP01.TOS. Almost all of the programs should work in all three ST screen resolutions (low, medium, high), which is one reason why GEM and sophisticated graphics have not been used.

To run the MIDI Display program, just double-click on the program icon displayed on the ST's desktop and it will run. Pressing the 'Q' key on the ST's QWERTY keyboard will return you to the desktop, and pressing the spacebar will toggle the filtering on and off. This 'quick and dirty' style of user interface is more or less standard in all the programs — explorers must be able to put up with some hardships!

USING THE PROGRAM



So what does the program do? After double-clicking on the program's icon, the program will load and run. The screen will then clear and the program title and some other information will appear at the top of the screen. The program starts out in the mode where Active Sensing bytes are filtered out, so you will see nothing until you actually send some MIDI messages to the ST. Pressing a key on your master keyboard should produce a display like this:

90 3C 70

This is a MIDI Note-On message for note number 60 ($3C) on channel 1, at a velocity of 112 ($70). Releasing the key will produce the corresponding Note-Off message, which can be in one of two forms:

80 3C 40

or...

90 3C 00

The first message is a true Note-Off message from a keyboard which does not implement Release Velocity, and so the velocity defaults to 64 ($40). The second message is a Note-On message with a velocity of zero, which can also be used as the equivalent of a Note-Off message.

Moving the Pitch Bend or Modulation Wheels will produce a stream of messages beginning with either a $E0 or $B0 byte, assuming that the master keyboard is set to MIDI channel 1.

Pressing down on the key will produce a similar stream of messages beginning with $D0, or $A0 if the master keyboard provides Polyphonic Key Pressure (the latest Ensoniq keyboards do this).

By pressing the spacebar on the Atari ST's QWERTY keyboard, you can toggle the program into the Unfiltered mode, whereby the screen should gradually scroll upwards as the $FE Active Sensing bytes are displayed. Some master keyboards do not transmit this message at all, so do not be surprised if nothing appears different! Equally, some 'workstations' send out MIDI clocks ($F8) all the time, and this can also cause unwanted scrolling of the screen. As an exercise, try altering the program yourself so that it filters out MIDI clocks.

SUMMARY



In our first brief excursion into the land of MIDI, we have seen how to extract some useful information from a MIDI byte, how to display MIDI information in a useful way, and how to escape from a MIDI input loop. Simple stuff, I know, but this is the foundation on which we will be building. This basic program segment will be added to in next month's installment, which shows you how to deal with Running Status — something which confuses many MIDI programmers at first.

The MIDI Display program provides a way of testing your understanding of the way MIDI works. Try decoding the display on the screen and see how it matches what you send to the ST from your master keyboard. Most (but not all) of the standard MIDI messages have a three byte structure, so try to get used to looking at these and working out what each byte tells you. If you find something unusual happening in your MIDI system, then using MIDI Display may be a way of detecting what is happening.

The second part of this series will look at MIDI messages in more detail, and show you how to understand messages which are not three bytes long.

PROGRAM DISK



The MIDI Display program mentioned is available on a 3.5" (Atari ST format) floppy disk along with about 30 other related programs. Price £7.

SOS Software, (Contact Details).

HEX CONVENTIONS

Throughout this series, hexadecimal numbers will be shown as $nn in the text, and as &Hnn in any program listings. Note that MIDI messages (and MIDI Display outputs) will always be shown as nn, and will never be shown in decimal.


BASIC

If you recently bought your Atari ST computer then you will already have a cut-down version of HiSoft Power Basic, called First Basic. Older STs were provided with the much inferior ST-Basic, in two varieties (the oldest is the worst). ST-Basic is really not suitable for serious program development, but First Basic should be suitable for trying out most of the simpler examples given in this series.

HiSoft Power Basic and First Basic are modern structured computer languages which have few of the limitations of traditional Basics and lots of the powerful features of more modern languages. It is a compiled language, which means that at the cost of waiting for a few seconds whilst it compiles your program, you can have very fast running of the resulting code. This is very important in the case of MIDI programs, and means that there is no need to use lower level coding (like assembly language) in any of the examples given.

Dr.T's T-Basic could be used as an alternative to HiSoft Power Basic if you are already running Dr.T's multi-program environment (MPE) on your ST. If T-Basic is used, however, the examples and code shown will occasionally need some modifications before they will run. You will need to be fairly confident in your programming before doing this.


THE MAP

No explorer leaves home without his map, so here's a rough guide to the territory we will be investigating over the coming months:

1. MIDI Fundamentals, MIDI Display.
2. Running Status
3. Channels
4. Mapping
5. Clocks
6. De-briefing


MIDI FUNDAMENTALS

MIDI is an acronym for Musical Instrument Digital Interface, and it is a worldwide standard which specifies a method of communicating information between electronic musical instruments. Messages are sent from the Out socket of one device to the In socket of another, and are made up of packets of digital information: eight bits one after the other, thus forming a byte of data. Each byte is surrounded by Start and Stop bits, so that the receiving instrument can work out where each begins and ends. These messages convey what is happening, not the sound which you hear, so there are defined messages to indicate Note-Ons and Note-Offs, Pitch Bend, Program Changes, drum machine Start and Stop, and many other musical events.

Rather like tuning a TV into different stations or channels, there are 16 channels in MIDI, which can be used to keep different musical parts separate. As MIDI has become established, a rough ordering of the contents of the various channels has evolved, in much the same way that most people have their TVs tuned so that Channel 1 is BBC1, Channel 2 is BBC2, Channel 3 is ITV, and Channel 4 is Channel 4! For example, a drum machine would typically receive drum events on MIDI channel 10, whilst chord pads might be found on channel 2, and a melody could be played using channel 1.

There are two basic types of MIDI message:

CHANNEL messages are used to convey information in the 16 channels and consist of messages describing Note-Ons and Offs, Pressure, Pitch Bend, Program Changes, and special MIDI Controllers — all related to actual live performance data.

In contrast, SYSTEM messages are not associated with a particular channel, and so can be received by any piece of MIDI equipment connected to the data network — this global information deals with the overall timing and control aspects for MIDI: the timing clock and MIDI Time Code messages; Start, Stop, and Continue commands; Active Sensing and Tune Request messages.

Each MIDI message normally consists of a Status byte, usually followed by one or more data bytes. The Status bytes are indicated by setting the most significant bit of the byte to 1 — whilst for all data bytes the most significant bit of the byte is set to 0. This means that the basic interchange level of MIDI is really only seven bits, therefore all data values are restricted to a range between 0 and 127.

The Status bytes for Channel messages are split into two 4-bit nibbles — the high nibble indicates the type of Status message, whilst the low nibble indicates the MIDI channel for which the following data is intended. There are seven fundamental sorts of Channel message and these are assigned high nibble values from $8 to $E in hexadecimal notation. The $F high nibble value is reserved for the System messages.

CHANNEL MESSAGES

MIDI was originally designed for use with keyboard instruments, and this is reflected in the messages. The messages all begin with the Status byte, which is of the form $Mn, where the n indicates the channel number minus 1, since 0-15 is used to represent channels 1 to 16.

Status Byte Message

$8n Note-Off
$9n Note-On
$An Poly Pressure
$Bn Control Change
$Cn Program Change
$Dn Channel Pressure
$En Pitch Wheel
$Fn System Messages


Messages beginning with $8n indicate a Note-Off event, whilst $9n indicates a Note-On event. Both of these bytes are followed by a byte which indicates the pitch of the note or note number (from 0 to 127) being played: Middle C is note number 60. The next byte which follows shows the velocity with which the note was played, and is set to 64 if the MIDI instrument does not transmit velocity. If a Note-On message is sent with a velocity of zero, then it is treated as a Note-Off message and is used in a special compressed transmission mode called Running Status.

The $An 'Polyphonic Pressure' message sends information about the aftertouch pressure applied to each note individually, whilst the $Dn 'Channel Pressure' message sends a single value for the whole of the keyboard and is less expressive. Pitch Bend is sent with the $En message, where the two following bytes contain a 14-bit representation of the pitch bend value.

Selection of sounds is carried out by the $Cn 'Program Change' message, which can be used to select any of 128 programs on each of the 16 channels. Simple, cheap instruments are often limited in their choice of channels and the number of sounds which can be accessed.

The final Channel message is $Bn, which is used for MIDI Controllers — a sort of general case of the Pitch Bend or Pressure messages. There is provision for a large number of possible Controllers: more than 64,000 actually, but only a handful are typically used. The most common is the Modulation Wheel (Controller number 1), which is often found next to the Pitch Bend Wheel on the left-hand side of a synthesizer keyboard.

SYSTEM MESSAGES

System messages use the same two nibble split, but in this case, the high nibble is always $F and the low nibble is used to indicate the type of message — there are thus 16 possibilities and these are split into three parts. $F0 indicates a special purpose message called System Exclusive, which is used to send messages which are specific to just the products of one manufacturer.

$F1 to $F7 are the System Common messages, used for controlling and enhancing other functions. For example, the $F2 Song Position and $F3 Song Select messages are used to control drum machines and sequencers. MIDI Time Code sends its timing information as $F1 messages every quarter frame, plus additional information in the form of $F0 System Exclusive messages — all for film and video synchronisation purposes. Analogue synthesizer users might use the $F6 Tune Request to activate built-in oscillator tuning routines before playing. $F7 is used to indicate the end of a System Exclusive message.

The remaining System status bytes, from $F8 to $FF, are called the Real-Time messages and they deal with the synchronisation of the MIDI system. $F8 is the MIDI Timing Clock, a complete message in one byte — sent at the rate of 24 clocks per quarter-note. $FA, $FB, and $FC are the drum machine controls — providing remote Start, Stop, and Continue commands.

Active Sensing uses a single byte ($FE) repeated about three times per second to indicate if a remote keyboard or MIDI guitar is still active; it can also be used to mute sound expanders if the connection fails. Finally, $FF is the System Reset — a panic button designed for use only in cases of dire emergency, since it restores the equipment to its initial power-up state.


Series - "Adventures In MIDILand"

Read the next part in this series:


All parts in this series:

Part 1 (Viewing) | Part 2 | Part 3 | Part 4 | Part 5 | Part 6


More from these topics


Browse by Topic:

Computing

MIDI



Previous Article in this issue

King Korg and the Wave Monster!

Next article in this issue

Recording Techniques


Publisher: Sound On Sound - SOS Publications Ltd.
The contents of this magazine are re-published here with the kind permission of SOS Publications Ltd.


The current copyright owner/s of this content may differ from the originally published copyright notice.
More details on copyright ownership...

 

Sound On Sound - Aug 1990

Donated & scanned by: Mike Gorman

Topic:

Computing

MIDI


Series:

Adventures In MIDILand

Part 1 (Viewing) | Part 2 | Part 3 | Part 4 | Part 5 | Part 6


Feature by Martin Russ

Previous article in this issue:

> King Korg and the Wave Monst...

Next article in this issue:

> Recording Techniques


Help Support The Things You Love

mu:zines is the result of thousands of hours of effort, and will require many thousands more going forward to reach our goals of getting all this content online.

If you value this resource, you can support this project - it really helps!

Donations for September 2024
Issues donated this month: 0

New issues that have been donated or scanned for us this month.

Funds donated this month: £20.00

All donations and support are gratefully appreciated - thank you.


Magazines Needed - Can You Help?

Do you have any of these magazine issues?

> See all issues we need

If so, and you can donate, lend or scan them to help complete our archive, please get in touch via the Contribute page - thanks!

Please Contribute to mu:zines by supplying magazines, scanning or donating funds. Thanks!

Monetary donations go towards site running costs, and the occasional coffee for me if there's anything left over!
muzines_logo_02

Small Print

Terms of usePrivacy