Anonymous

Changes

From Final Fantasy Inside

MIDI format

6 bytes added, 20:54, 19 March 2005
m
Very minor formatting changes, e.g. making use of special code tags
Here's what a chunk's header looks like if you defined it in C:
<prec>
struct CHUNK_HEADER
{
unsigned long Length;
};
</prec>
<B><FONT COLOR=RED>NOTE:</FONT></B> The <B>Length</B> does not include the 8 byte chunk
header. It simply tells you how many bytes of data are in the chunk <U>following this header</U>.
And here's an example chunk header (with bytes expressed in hex) if you examined it with a hex editor:
4D 54 68 64 00 00 00 06
Note that the first 4 bytes make up the ascii ID of <B>MThd</B> (ie, the first four
The last two bytes indicate how many Pulses (i.e. clocks) Per Quarter Note (abbreviated as PPQN) resolution the time-stamps are based upon, <B>Division</B>. For example, if your sequencer has 96 ppqn, this field would be (in hex):
00 60
<B><FONT COLOR=RED>NOTE:</FONT></B> The 4 bytes that make up the <B>Length</B> are stored in (Motorola) "Big Endian" byte order, not (Intel) "Little Endian" reverse byte order. (ie, The 06 is the fourth byte instead
Here's what an MThd chunk looks like if you defined it in C:
<prec>
struct MTHD_CHUNK
{
unsigned short Division;
};
</prec>
And here's an example of a complete MThd chunk (with header) if you examined it in a hex editor:
Here's what an MTrk chunk looks like if you defined it in C:
<prec>
struct MTRK_CHUNK
{
unsigned char Data[]; /* Its actual size is Data[Length] */
};
</prec>
reaches the last byte of a variable length quantity, and returns a 32-bit value.
<prec>
void WriteVarLen(register unsigned long value)
{
return(value);
}
</prec>
<B><FONT COLOR=RED>NOTE:</FONT></B> The concept of variable length quantities (ie, breaking up a
For example, consider the following SYSEX MIDI message:
F0 7F 7F 04 01 7F 7F F7
This would be stored in a MIDI file as the following series of bytes (minus the delta-time
bytes which would precede it):
F0 07 7F 7F 04 01 7F 7F F7
The 07 above is the variable length quantity (which happens to fit in just one byte for this
----
===== Sequence Number =====
FF 00 02 <I><FONT COLOR=RED><B>ss ss</B></FONT></I>
or...
FF 00 00
This optional event must occur at the beginning of a MTrk (ie, before any non-zero
----
===== Text =====
FF 01 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
Any amount of text (amount of bytes = <I><FONT COLOR=GREEN><B>len</B></FONT></I>) for any
----
===== Copyright =====
FF 02 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
A copyright message. It's best to put this event at the beginning of an MTrk.
----
===== Sequence/Track Name =====
FF 03 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
The name of the sequence or track. It's best to put this event at the beginning of an
----
===== Instrument =====
FF 04 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
The name of the instrument (ie, MIDI module) being used to play the track. This may be
----
===== Lyric =====
FF 05 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
A song lyric which occurs on a given beat. A single Lyric
===== Marker =====
FF 06 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
The text for a marker which occurs on a given beat. Marker events might be used to denote a loop start and loop end (ie, where the sequence loops back to a previous event).
----
===== Cue Point=====
FF 07 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
The text for a cue point which occurs on a given beat. A Cue Point might be used to denote
----
===== Program (Patch) Name =====
FF 08 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
The name of the program (ie, patch) used to play the MTrk. This may be
----
===== Device (Port) Name =====
FF 09 <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>text</B></FONT></I>
The name of the MIDI device (port) where the track is routed. This replaces the "MIDI Port"
----
===== End of Track =====
FF 2F 00
This event is <u>not</u> optional. It must be the last event in every MTrk. It's used as a definitive marking of the end of an MTrk. Only 1 per MTrk.
----
===== Tempo =====
FF 51 03 <I><FONT COLOR=RED><B>tt tt tt</B></FONT></I>
Indicates a tempo change. The 3 data bytes of <B>tt tt tt</B> are the tempo in microseconds per quarter note. In other
----
===== SMPTE Offset =====
FF 54 05 <I><FONT COLOR=RED><B>hr mn se fr ff</B></FONT></I>
Designates the SMPTE start time (hours, minutes, seconds, frames, subframes) of the MTrk. It should
----
===== Time Signature =====
FF 58 04 <I><FONT COLOR=RED><B>nn dd cc bb</B></FONT></I>
Time signature is expressed as 4 numbers. <I><FONT COLOR=RED><B>nn</B></FONT></I>
event:
FF 58 04 06 03 18 08
<B><FONT COLOR=RED>NOTE:</FONT></B> If there are no time signature events in a MIDI file,
----
===== Key Signature =====
FF 59 02 <I><FONT COLOR=RED><B>sf mi</B></FONT></I>
<I><FONT COLOR=RED><B>sf</B></FONT></I> = -7 for 7 flats, -1 for 1 flat, etc, 0 for key of c, 1 for 1 sharp, etc.
----
===== Proprietary Event =====
FF 7F <I><FONT COLOR=GREEN><B>len</B></FONT></I> <I><FONT COLOR=RED><B>data</B></FONT></I>
This can be used by a program to store proprietary data. The first byte(s) should be a unique ID
Anonymous user