Author Topic: MIDI file format (1989 article)  (Read 1595 times)

Offline chrisNova777

  • Administrator
  • Hero Member
  • Posts: 9164
  • "Vintage MIDI Sequencing + Audio Production"
    • | vintage audio production software + hardware info
MIDI file format (1989 article)
« on: February 06, 2019, 04:40:16 AM »

MIDI Files
by Anthony Widoff

The recent development of the MIDI standard is designed to enable you to transfer your sequences from one sequencer to another. Anthony Widoff files a report.

You've heard about them, read about them and now you need to know about them. Welcome to the wonderful world of MIDI files.

WHEN MIDI FILES were first introduced in 1986, the idea had originated in one American company - Opcode Systems. What followed qualifies as a minor miracle: not only did a large number of software manufacturers across several computer boundaries contribute to their growth, they went out on a limb and supported pre-"official" versions of the standard knowing that they would have to update their software as changes were made. Thanks to the selfless work and dedication of Opcode "MIDIphile" Dave Oppenheim and those companies, we now have an MMA approved MIDI File.

Today, almost all Macintosh music software supports MIDI Files, and other machines, such as the Atari, the Amiga, and even the IBM, are joining the MIDI File conga line.


ALTHOUGH THE CONCEPT had been explored in the past, it wasn't until the advent of MIDI that we saw so many featureless black boxes. MIDI has made it easy to separate the musical controller from sound generator(s). Today, not only can keyboardists draw on a vast library of new (and old) sounds, but guitarists, wind players, drummers, and percussionists may play with a virtually identical sound palette. One team of designers worries day and night about how to make its controller more responsive; while another is concerned with improving its sound generation algorithms, and never (well, rarely) the twain shall meet. They don't have to. They know how to talk to each other through MIDI. In addition, entirely new devices, such as MIDI processors, have entered the arena, treating new instrument performance possibilities.

As for computer compatibility, the Macintosh has long had a standard format for text and graphics ("text" and "PICT" formats). You can take text from a word processing program and embed it into graphics using your desktop publishing program

Now music software is moving towards a similar degree of flexibility. The few brave souls who have attempted to design sequencer packages with sophisticated editing facilities, comprehensive notation capabilities and a universal patch librarian have learned the hard way that no one program can do everything. The MIDI File format offers a viable alternative.

The Spec

JUST AS YOU don't have to know all about MIDI to use it, you don't really need to know all about MIDI Files to benefit from them. If you really want to know about MIDI Files you can get it direct from the IMA (International MIDI Assoc. 5316 West 57th St, Los Angeles, CA 90056, USA). As a digestible alternative, here's a simple explanation.

Essentially, a MIDI File is a sequence that has been translated into a linear, multitrack datafile that can be understood by different MIDI programs. The MIDI file spec currently supports all MIDI events (notes, controllers and so on).

There is also a provision for SysEx events and various types of "meta-events" (these include tempo, time signature, key signature markers, cue points, SMPTE offset, sequence/track/instrument names, copyright notice, lyrics, and so on). Many programs stick to basic MIDI events because that's all you really need. If your MIDI File contains time signature information but your sequencer ignores that information, it will still read all the musical data. The same is true when sending information the other way: if a program can read a time signature meta-event, but doesn't see one in the MIDI File, it will still accept the data it understands.

The data is broken up into "chunks". Typically, one track of information is one "chunk." Tempo information for a piece is saved as its own chunk (in fact, the first one in a MIDI file). Devices that have to exchange clocking information (such as SMPTE-to-MIDI converters and "hit point" programs) share timing information by sending a MIDI File around containing just this chunk. In general, any program can use or ignore any chunk or meta event it so chooses (like receiving MIDI itself).

There is a Macintosh program called Tab Converter which is very useful for understanding and manipulating basic MIDI Files. Tab Converter converts any Format 0 MIDI File (the simplest and most common kind) into a text file allowing you to view it as standard text in any word processing program. Tab Converter also allows you to change a text file into a MIDI File providing it follows the correct format. Tab Converter is free, available on PAN (Performing Arts Network) and is application No. 82 in the Mac Applications area of the Synth and MIDI Database.

For example, here in Tab Converter format, are the first six notes of a famous piece of music. Note this is Tab Converter format and not MIDI File format, MIDI Files are expressed differently, especially when it comes to timing. For example, in a MIDI File you have to write a note-off command for every note-on. In Tab Converter you need only write a duration for each note-on event.

1   1   0   382   B3   78
1   4   94   10   F#4   86
1   5   46   10   F#4   66
1   6   1   14   C#4   41
1   6   69   12   B3   59
1   6   90   80   A4   67

The first line is a meta-event for time signature. This piece is in 4/2 time. Notice that the denominator can only be a power of 2. Charles Ives may not have used MIDI Files, but most of us will never notice it. The second line (Base 96) specifies the "units" or number of divisions per beat. In this case there will be 96 divisions for each beat in the 4/2 measure.

The next six lines are the six notes. The first number is the MIDI channel. All these notes are on MIDI channel one. The second number is the beat and the third the unit of that beat. In this case, the second note occurs 94 units after the 4th beat, which is very close to the fifth beat (the fifth beat being the first beat of the second measure in 4/2 time). The next number is the duration, or length of the event, which is also expressed in units.

If you wanted to add something like pitch-bend, it's very easy. For example, a pitch-bend on MIDI channel 3, first beat, 48th unit, at a value of 56 would look like 3 1 48 Bend 56.

MIDI File Formats

BECAUSE SOME SOFTWARE packages started to use MIDI Files before the spec was frozen last June, you may have to do a little sorting out between old and new MIDI Files. For example, MIDI Files in Intelligent Music's Macintosh software are presented with the option of using either Simple or Standard MIDI Files. Simple MIDI Files are the old files you might have created using old versions of Jam Factory, M, UpBeat, or Opcode Sequencer. You can usually not bother with them because they're not coming back.

"Perhaps the most intriguing implication of the MIDI File-to-be is its impact on the working environment of the computer musician."

Standard MIDI Files currently come in three formats: Format 0, 1, and 2. Nobody uses Format 2 yet. The only application I'm aware of that uses Format 1 is Opcode's Sequencer 2.6.

Format 0 treats everything as one large track. Since different sequencers have different ways of dealing with repeats and looping (then there are MIDI channel and track assignments...), laying everything out end-to-end as if it has been played in real time is the simplest common denominator. All events are listed sequentially regardless of original track or MIDI channel.

Format 1 allows multiple track sequences to be maintained. This means that if you originally recorded two different tracks on the same MIDI channel, you can preserve the independence of those tracks.

Format 2 lets a multitrack file occur sequentially rather than simultaneously.

Higher level programs can read all three formats of MIDI Files; lower level machines cannot (by default) read higher level formats. Numerous utilities that convert between them can no doubt be counted on to appear, as can MIDI Files dealing with timing in both fractions of a quarter note or in SMPTE time. With a tempo map (the first chunk in the file) as pivot, it now becomes possible for programs that work in one world to read a file that came from the other one.

Capturing & Exporting

IT'S A PRETTY straightforward job to convert a sequencer file into a MIDI File because sequencer files essentially contain the same information as MIDI Files. All you need to do is to convert the sequencer file format into the MIDI File format. This is usually referred to as "exporting". Programs that document a performance as a series of actions instead of the actual MIDI messages must "film" every musical gesture you make, and every random decision the program makes, much like a tape recorder would capture a performance on a traditional instrument. Once a "movie" has been "filmed", it can be exported as a MIDI File. The resultant file is then saved on the computer's disk.

One problem with capturing files is that you're limited by the amount of free space in the computer's memory. There's not much you can do about this except get more memory. If you encounter this sort of problem and you are running a program which takes up a lot of memory, you might consider disabling it while you're capturing. I haven't run into too many situations where I ran out of memory with my Mac Plus (only 1Mb).

Transferring between computers

MIDI FILES ARE currently supported on a number of computers. Transfer of MIDI Files from one computer to another over MIDI should be very easy in the (near?) future thanks to a transmission protocol (still under discussion) which will allow the transfer of MIDI Files through MIDI interfaces. Although this is not standard yet, it is still easy to transfer MIDI Files using standard communications programs. It's analogous to sending text files saved in ASCII format from word processing program to word processing program.

Eric Ameres (of Intelligent Music) and I spent some time getting our Macintosh, Atari, and Amiga to talk to each other. We had 100% success in all combinations. Here's how we did it.

Assuming you're in the same room (as opposed to using a telecommunications network), the only thing you need in order to connect the computers is a Standard Null Modem cable (transmit and receive are reversed on both ends). If you are using the Macintosh, you will also need an RS232 (DB25)-to-Macintosh adaptor so that you can connect to those neat little modem jacks. To transfer a file all you really need to do is Xmodem the file from one to the other - and that's it.

Things get a little more complicated with the Macintosh because it puts a 128-byte header on all its files. This means that when you transmit a file, you have to get rid of the first 128 bytes, and when you receive, you have to create this 128-byte header. We found ways to accomplish both these operations from the Macintosh alone.

To get a MIDI File into the Mac, simply download the file as normal, and then change the file type to "Midi". ResEdit is one program that will let you change the file type. Select the file in the ResEdit window and then select Get Info from the File menu. Change the file type from 'Text" (or whatever its type field says) to "Midi". Save it, and you're in business.

To transfer a file from Mac to Atari or Amiga, disable MacBinary transmission in your communications program. This will leave out the Mac header. (As far as I can tell, all modem packages on the Mac can do this in one way or another - refer to your owner's manual.) Make sure, when uploading MIDI Files from your Macintosh to a network, that you used Xmodem transmission with MacBinary disabled so that other machines can download them easily.

Future Applications

ITS EASY TO come up with a "wish list" for MIDI Files and future applications. First, you should be able to transmit and receive MIDI Files over MIDI (that's already in the works). Also, it would be useful to be able to link MIDI Files. If you have a number of SysEx MIDI Files that you want to forever associate with a sequence, you'd want them all in one file (that is, when someone gets around to supporting SysEx events in their MIDI File playback). If manufacturers start to support Format 2 files, this could be very easy to do - just modify one header chunk and then string together all the track chunks). It might also be useful to be able to capture bulk dumps from other devices and convert them into MIDI Files.

There are plenty of other programs you could write using MIDI Files. How about a program which deals exclusively with timing and MIDI delays? No one has fully explored this idea in any program that I'm aware of.

But perhaps the most intriguing implication of the MIDI File-to-be is its impact on the working environment of the computer musician. MIDI Files allow us not only to tie up programs which perform different tasks, but also programs which provide different ways of creating and interacting with music.