Standard MIDI-File Format Spec. 1.1 ---
The International MIDI Association
5316 W. 57th St.
Los Angeles, CA 90056
0 - Introduction
The document outlines the specification for MIDI Files. The purpose of MIDI
Files is to provide a way of interchanging time-stamped MIDI data between
different programs on the same or different computers. One of the primary
design goals is compact representation, which makes it very appropriate for
disk-based file format, but which might make it inappropriate for storing
in memory for quick access by a sequencer program. (It can be easily
converted to a quickly-accessible format on the fly as files are read in or
written out.) It is not intended to replace the normal file format of any
program, though it could be used for this purpose if desired.
MIDI Files contain one or more MIDI streams, with time information for each
event. Song, sequence, and track structures, tempo and time signature
information, are all supported. Track names and other descriptive
information may be stored with the MIDI data. This format supports multiple
tracks and multiple sequences so that if the user of a program which
supports multiple tracks intends to move a file to another one, this format
can allow that to happen.
This spec defines the 8-bit binary data stream used in the file. The data
can be stored in a binary file, nibbilized, 7-bit-ized for efficient MIDI
transmission, converted to Hex ASCII, or translated symbolically to a
printable text file. This spec addresses what's in the 8-bit stream. It
does not address how a MIDI File will be transmitted over MIDI. It is the
general feeling that a MIDI transmission protocol will be developed for
files in general and MIDI Files will use this scheme.
1 - Sequences, Tracks, Chunks: File Block Structure
In this document, bit 0 means the least significant bit of a byte, and bit
7 is the most significant.
Some numbers in MIDI Files are represented is a form called VARIABLE-LENGTH
QUANTITY. These numbers are represented 7 bits per byte, most significant
bits first. All bytes except the last have bit 7 set, and the last byte has
bit 7 clear. If the number is between 0 and 127, it is thus represented
exactly as one byte.
Here are some examples of numbers represented as variable-length
00000080 81 00
00002000 C0 00
00003FFF FF 7F
00004000 81 80 00
00100000 C0 80 00
001FFFFF FF FF 7F
00200000 81 80 80 00
08000000 C0 80 80 00
0FFFFFFF FF FF FF 7F
The largest number which is allowed is 0FFFFFFF so that the variable-length
representations must fit in 32 bits in a routine to write variable-length
numbers. Theoretically, larger numbers are possible, but 2 x 10^8 96ths of
a beat at a fast tempo of 500 beats per minute is four days, long enough
for any delta-time!
To any file system, a MIDI File is simply a series of 8-bit bytes. On the
Macintosh, this byte stream is stored in the data fork of a file (with file
type 'MIDI'), or on the Clipboard (with data type 'MIDI'). Most other
computers store 8-bit byte streams in files -- naming or storage
conventions for those computers will be defined as required.
MIDI Files are made up of -chunks-. Each chunk has a 4-character type and a
32-bit length, which is the number of bytes in the chunk. This structure
allows future chunk types to be designed which may be easily be ignored if
encountered by a program written before teh chunk type is introduced. Your
programs should EXPECT alien chunks and treat them as if they weren't
Each chunk begins with a 4-character ASCII type. It is followed by a 32-bit
length, most significant byte first (a length of 6 is stored as 00 00 00
06). This length refers to the number of bytes of data which follow: the
eight bytes of type and length are not included. Therefore, a chunk with a
length of 6 would actually occupy 14 bytes in the disk file.
This chunk architecture is similar to that used by Electronic Arts' IFF
format, and the chunks described herin could easily be placed in an IFF
file. The MIDI File itself is not an IFF file: it contains no nested
chunks, and chunks are not constrained to be an even number of bytes long.
Converting it to an IFF file is as easy as padding odd length chunks, and
sticking the whole thing inside a FORM chunk.
MIDI Files contain two types of chunks: header chunks and track chunks. A
-header- chunk provides a minimal amount of information pertaining to the
entire MIDI file. A -track- chunk contains a sequential stream of MIDI data
which may contain information for up to 16 MIDI channels. The concepts of
multiple tracks, multiple MIDI outputs, patterns, sequences, and songs may
all be implemented using several track chunks.
A MIDI File always starts with a header chunk, and is followed by one or
more track chunks.
This page hosted by
Get your own Free Home Page
Back to main page
This page was last updated by Tore Nilsson on 1996-10-28