home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / bmd-1.0beta.tar.Z / bmd-1.0beta.tar / bmd-1.0beta / app / midifile / midi-files < prev    next >
Text File  |  1990-12-12  |  26KB  |  623 lines

  1.  
  2. [This document is Dave Oppenheim's current version of the MIDI file 
  3. specification, as sent to those who have participated in its 
  4. development.  The consensus seems to be to submit this to the MIDI 
  5. Manufacturers' Association as version 1.0.  I apologize for any loss of 
  6. clarity that might have occurred in the conversion from a Microsoft Word 
  7. document to this pure text file.  I have removed some of the discussion 
  8. about recent changes to the specification in order to keep the file size 
  9. reasonable.--Doug Wyatt]
  10.  
  11. Standard MIDI Files 0.06    March 1, 1988
  12.  
  13.  
  14. 0  Introduction
  15.  
  16. This describes a proposed standard MIDI file format.  MIDI files contain 
  17. one or more MIDI streams, with time information for each event.  Song, 
  18. sequence, and track structures, tempo and time signature information, 
  19. are all supported.  Track names and other descriptive information may be 
  20. stored with the MIDI data.  This format supports multiple tracks and 
  21. multiple sequences so that if the user of a program which supports 
  22. multiple tracks intends to move a file to another one, this format can 
  23. allow that to happen.
  24.  
  25. This spec defines the 8-bit binary data stream used in the file.  The 
  26. data can be stored in a binary file, nibbleized, 7-bit-ized for 
  27. efficient MIDI transmission, converted to Hex ASCII, or translated 
  28. symbolically to a printable text file.  This spec addresses what's in 
  29. the 8-bit stream.
  30.  
  31.  
  32. 1  Sequences, Tracks, Chunks:  File Block Structure
  33.  
  34. Sequence files are made up of chunks.  Each chunk has a 4-character type 
  35. and a 32-bit length, which is the number of bytes in the chunk.  On the 
  36. Macintosh, data is passed either in the data fork of a file, or on the 
  37. Clipboard.  (The file type on the Macintosh for a file in this format 
  38. will be "Midi".)  On any other computer, the data is simply the contents 
  39. of the file.  This structure allows future chunk types to be designed 
  40. which may easily be ignored if encountered by a program written before 
  41. the chunk type is introduced.   Your programs should expect alien chunks 
  42. and treat them as if they weren't there.
  43.  
  44. This proposal defines two types of chunks:  a header chunk and a track 
  45. chunk.  A header chunk provides a minimal amount of information 
  46. pertaining to the entire MIDI file.  A track chunk contains a sequential 
  47. stream of MIDI data which may contain information for up to 16 MIDI 
  48. channels.  The concepts of multiple tracks, multiple MIDI outputs, 
  49. patterns, sequences, and songs may all be implemented using several 
  50. track chunks.
  51.  
  52. A MIDI file always starts with a header chunk, and is followed by one or 
  53. more track chunks.
  54.  
  55. MThd  <length of header data>
  56. <header data>
  57. MTrk  <length of track data>
  58. <track data>
  59. MTrk  <length of track data>
  60. <track data>
  61.  ...
  62.  
  63. Track Data Format (MTrk chunk type)
  64.  
  65. The MTrk chunk type is where actual song data is stored.  It is simply a 
  66. stream of MIDI events (and non-MIDI events), preceded by delta-time 
  67. values.
  68.  
  69. Some numbers in MTrk chunks are represented in a form called a variable-
  70. length quantity. These numbers are represented 7 bits per byte, most 
  71. significant bits first.  All bytes except the last have bit 7 set, and 
  72. the last byte has bit 7 clear.  If the number is between 0 and 127,  it 
  73. is thus represented exactly as one byte.  
  74.  
  75. Here are some examples of numbers represented as variable-length 
  76. quantities:
  77.  
  78.     Number (hex)    Representation (hex)
  79.     00000000    00
  80.     00000040    40
  81.     0000007F    7F
  82.     00000080    81 00
  83.     00002000    C0 00
  84.     00003FFF    FF 7F
  85.     00004000    81 80 00
  86.     00100000    C0 80 00
  87.     001FFFFF    FF FF 7F
  88.     00200000    81 80 80 00
  89.     08000000    C0 80 80 00
  90.     0FFFFFFF    FF FF FF 7F
  91.     
  92.  
  93. The largest number which is allowed is 0FFFFFFF so that the variable-
  94. length representation must fit in 32 bits in a routine to write 
  95. variable-length numbers.  Theoretically, larger numbers are possible, 
  96. but 2 x 108 96ths of a beat at a fast tempo of 500 beats per minute is 
  97. four days, long enough for any delta-time!
  98.  
  99. Here is the syntax of an MTrk chunk:
  100.  
  101. <track data> = <MTrk event>+
  102.  
  103. <MTrk event> = <delta-time> <event>
  104.  
  105. <delta-time> is stored as a variable-length quantity.  It represents the 
  106. amount of time before the following event.  If the first event in a 
  107. track occurs at the very beginning of a track, or if two events occur 
  108. simultaneously, a delta-time of zero is used.  Delta-times are always 
  109. present.  (Not storing delta-times of 0 requires at least two bytes for 
  110. any other value, and most delta-times aren't zero.)  Delta-time is in 
  111. some fraction of a beat (or a second, for recording a track with SMPTE 
  112. times), as specified in the header chunk.  
  113.  
  114. <event> = <MIDI event> | <sysex event> | <meta-event>
  115.  
  116. <MIDI event> is any MIDI channel message.  Running status is used: 
  117. status bytes may be omitted after the first byte.  The first event in a 
  118. file must specify status.  Delta-time is not  considered an event 
  119. itself:  it is an integral part of the specification.  Notice that 
  120. running status occurs across delta-times.  
  121.  
  122. <meta-event> specifies non-MIDI information useful to this format or to 
  123. sequencers, with this syntax:
  124.  
  125.     FF <type> <length> <bytes>
  126.  
  127. All meta-events begin with FF, then have an event type byte (which is 
  128. always less than 128), and then have the length of the data stored as a 
  129. variable-length quantity, and then the data itself.  If there is no 
  130. data, the length is 0.  As with sysex events, running status is not 
  131. allowed.  As with chunks, future meta-events may be designed which may 
  132. not be known to existing programs, so programs must properly ignore 
  133. meta-events which they do not recognize, and indeed, should expect to 
  134. see them.  New for 0.06:  programs must never ignore the length of a 
  135. meta-event which they do recognize, and they shouldn't be surprised if 
  136. it's bigger than they expected.  If so, they must ignore everything past 
  137. what they know about.  However, they must not add anything of their own 
  138. to the end of a meta-event.
  139.  
  140. <sysex event> is used to specify a MIDI system exclusive message, or as 
  141. an "escape" to specify any arbitrary bytes to be transmitted.  
  142. Unfortunately, some synthesizer manufacturers specify that their system 
  143. exclusive messages are to be transmitted as little packets.  Each packet 
  144. is only part of an entire syntactical system exclusive message, but the 
  145. times they are transmitted at are important.  Examples of this are the 
  146. bytes sent in a CZ patch dump, or the FB-01's "system exclusive mode" in 
  147. which microtonal data can be transmitted.  To be able to handle 
  148. situations like these, two forms of  <sysex event> are provided:
  149.  
  150.     F0 <length> <bytes to be transmitted after F0>
  151.     F7 <length> <all bytes to be transmitted>
  152.  
  153. In both cases, <length> is stored as a variable-length quantity.  It is 
  154. equal to the number of bytes following it, not including itself or the 
  155. message type (F0 or F7), but all the bytes which follow, including any 
  156. F7 at the end which is intended to be transmitted.  The first form, with 
  157. the F0 code, is used for syntactically complete system exclusive 
  158. messages, or the first packet an a series Q that is, messages in which 
  159. the F0 should be transmitted.  The second form is used for the remainder 
  160. of the packets within a syntactic sysex message, which do not begin with 
  161. F0.  Of course, the F7 is not considered part of the system exclusive 
  162. message.  Of course, just as in MIDI, running status is not allowed, in 
  163. this case because the length is stored as a variable-length quantity 
  164. which may or may not start with bit 7 set.
  165.  
  166. (New to 0.06)  A syntactic system exclusive message must always end with 
  167. an F7, even if the real-life device didn't send one, so that you know 
  168. when you've reached the end of an entire sysex message without looking 
  169. ahead to the next event in the MIDI file.  This principle is repeated 
  170. and illustrated in the paragraphs below.
  171.  
  172. The vast majority of system exclusive messages will just use the F0 
  173. format.  For instance, the transmitted message F0 43 12 00 07 F7 would 
  174. be stored in a MIDI file as F0 05 43 12 00 07 F7.  As mentioned above, 
  175. it is required to include the F7 at the end so that the reader of the 
  176. MIDI file knows that it has read the entire message.
  177.  
  178. For special situations when a single system exclusive message is split 
  179. up, with parts of it being transmitted at different times, such as in a 
  180. Casio CZ patch transfer, or the FB-01's "system exclusive mode", the F7 
  181. form of sysex event is used for each packet except the first.  None of 
  182. the packets would end with an F7 except the last one, which must end 
  183. with an F7.  There also must not be any transmittable MIDI events in-
  184. between the packets of a multi-packet system exclusive message.  Here is 
  185. an example:  suppose the bytes F0 43 12 00 were to be sent, followed by 
  186. a 200-tick delay, followed by the bytes  43 12 00 43 12 00, followed by 
  187. a 100-tick delay, followed by the bytes  43 12 00 F7, this would be in 
  188. the MIDI File:
  189.  
  190.     F0 03 43 12 00
  191.     81 48                    200-tick delta-time
  192.     F7 06 43 12 00 43 12 00
  193.     64                    100-tick delta-time
  194.     F7 04 43 12 00 F7
  195.  
  196. The F7 event may also be used as an "escape" to transmit any bytes 
  197. whatsoever, including real-time bytes, song pointer, or MIDI Time Code, 
  198. which are not permitted normally in this specification.  No effort 
  199. should be made to interpret the bytes used in this way.  Since a system 
  200. exclusive message is not being transmitted, it is not necessary or 
  201. appropriate to end the F7 event with an F7 in this case. 
  202.  
  203.  
  204. 2    Header Chunk
  205.  
  206. The header chunk at the beginning of the file specifies some basic 
  207. information about the data in the file.  The data section contains three 
  208. 16-bit words, stored high byte first (of course).  Here's the syntax of 
  209. the complete chunk:
  210.  
  211.     <chunk type> <length> <format> <ntrks> <division> 
  212.  
  213. As described above, <chunk type> is the four ASCII characters 'MThd'; 
  214. <length> is a 32-bit representation of the number 6 (high byte first).  
  215. The first word, format, specifies the overall organization of the file.  
  216. Only three values of format are specified:
  217.  
  218.     0    the file contains a single multi-channel track
  219.     1    the file contains one or more simultaneous tracks (or MIDI 
  220. outputs) of a sequence
  221.     2    the file contains one or more sequentially independent 
  222. single-track patterns
  223.  
  224. The next word, ntrks, is the number of track chunks in the file.  The 
  225. third word, division,  is the division of a quarter-note represented by 
  226. the delta-times in the file.  (If division is negative, it represents 
  227. the division of a second represented by the delta-times in the file, so 
  228. that the track can represent events occurring in actual time instead of 
  229. metrical time.  It is represented in the following way:  the upper byte 
  230. is one of the four values -24, -25, -29, or -30, corresponding to the 
  231. four standard SMPTE and MIDI time code formats, and represents the 
  232. number of frames per second.  The second byte (stored positive) is the 
  233. resolution within a frame:  typical values may be 4 (MIDI time code 
  234. resolution), 8, 10, 80 (bit resolution), or 100.  This system allows 
  235. exact specification of time-code-based tracks, but also allows 
  236. millisecond-based tracks by specifying 25 frames/sec and a resolution of 
  237. 40 units per frame.)    
  238.  
  239. Format 0, that is, one multi-channel track, is the most interchangeable 
  240. representation of data.  One application of MIDI files is a simple 
  241. single-track player in a program which needs to make synthesizers make 
  242. sounds, but which is primarily concerned with something else such as 
  243. mixers or sound effect boxes.  It is very desirable to be able to 
  244. produce such a format, even if your program is track-based, in order to 
  245. work with these simple programs.  On the other hand, perhaps someone 
  246. will write a format conversion from format 1 to format 0 which might be 
  247. so easy to use in some setting that it would save you the trouble of 
  248. putting it into your program.
  249.  
  250. Programs which support several simultaneous tracks should be able to 
  251. save and read data in format 1, a vertically one-dimensional form, that 
  252. is, as a collection of tracks.  Programs which support several 
  253. independent patterns should be able to save and read data in format 2, a 
  254. horizontally one-dimensional form.  Providing these minimum capabilities 
  255. will ensure maximum interchangeability.
  256.  
  257. MIDI files can express tempo and time signature, and they have been 
  258. chosen to do so for transferring tempo maps from one device to another.  
  259. For a format 0 file, the tempo will be scattered through the track and 
  260. the tempo map reader should ignore the intervening events; for a format 
  261. 1 file, the tempo map must (starting in 0.04) be stored as the first 
  262. track.  It is polite to a tempo map reader to offer your user the 
  263. ability to make a format 0 file with just the tempo, unless you can use 
  264. format 1.
  265.  
  266. All MIDI files should specify tempo and time signature.  If they don't, 
  267. the time signature is assumed to be 4/4, and the tempo 120 beats per 
  268. minute.  In format 0, these meta-events should occur at least at the 
  269. beginning of the single multi-channel track.  In format 1, these meta-
  270. events should be contained in the first track.  In format 2, each of the 
  271. temporally independent patterns should contain at least initial time 
  272. signature and tempo information.
  273.  
  274. We may decide to define other format IDs to support other structures.  A 
  275. program reading an unfamiliar format ID should return an error to the 
  276. user rather than trying to read further.
  277.  
  278. 3    Meta-Events
  279.  
  280. A few meta-events are defined herein.  It is not required for every 
  281. program to support every meta-event.  Meta-events initially defined 
  282. include:
  283.  
  284. FF 00 02 ssss    Sequence Number
  285. This optional event, which must occur at the beginning of a track, 
  286. before any nonzero delta-times, and before any transmittable MIDI 
  287. events, specifies the number of a sequence.  The number in this track 
  288. corresponds to the sequence number in the new Cue message discussed at 
  289. the summer 1987 MMA meeting.  In a format 2 MIDI file, it is used to 
  290. identify each "pattern" so that a "song" sequence using the Cue message 
  291. to refer to the patterns.  If the ID numbers are omitted, the sequences' 
  292. locations in order in the file are used as defaults.  In a format 0 or 1 
  293. MIDI file, which only contain one sequence, this number should be 
  294. contained in the first (or only) track.  If transfer of several 
  295. multitrack sequences is required, this must be done as a group of format 
  296. 1 files, each with a different sequence number.
  297.  
  298. FF 01 len text    Text Event
  299. Any amount of text describing anything.  It is a good idea to put a text 
  300. event right at the beginning of a track, with the name of the track, a 
  301. description of its intended orchestration, and any other information 
  302. which the user wants to put there.  Text events may also occur at other 
  303. times in a track, to be used as lyrics, or descriptions of cue points.  
  304. The text in this event should be printable ASCII characters for maximum 
  305. interchange.  However, other character codes using the high-order bit 
  306. may be used for interchange of files between different programs on the 
  307. same computer which supports an extended character set.  Programs on a 
  308. computer which does not support non-ASCII characters should ignore those 
  309. characters.
  310.  
  311. (New for 0.06 ).  Meta event types 01 through 0F are reserved for 
  312. various types of text events, each of which meets the specification of 
  313. text events(above) but is used for a different purpose: 
  314.  
  315. FF 02 len text    Copyright Notice
  316. Contains a copyright notice as printable ASCII text.  The notice should 
  317. contain the characters (C), the year of the copyright, and the owner of 
  318. the copyright.  If several pieces of music are in the same MIDI file, 
  319. all of the copyright notices should be placed together in this event so 
  320. that it will be at the beginning of the file.  This event should be the 
  321. first event in the first track chunk, at time 0.
  322.  
  323.  
  324. FF 03 len text    Sequence/Track Name
  325. If in a format 0 track, or the first track in a format 1 file, the name 
  326. of the sequence.  Otherwise, the name of the track.
  327.  
  328. FF 04 len text    Instrument Name
  329. A description of the type of instrumentation to be used in that track.  
  330. May be used with the MIDI Prefix meta-event to specify which MIDI 
  331. channel the description applies to, or the channel may be specified as 
  332. text in the event itself.
  333.  
  334. FF 05 len text    Lyric
  335. A lyric to be sung.  Generally, each syllable will be a separate lyric 
  336. event which begins at the event's time.
  337.  
  338. FF 06 len text    Marker
  339. Normally in a format 0 track, or the first track in a format 1 file.  
  340. The name of that point in the sequence, such as a rehearsal letter or 
  341. section name ("First Verse", etc.). 
  342.  
  343.  
  344. FF 07 len text    Cue Point
  345. A description of something happening on a film or video screen or stage 
  346. at that point in the musical score ("Car crashes into house", "curtain 
  347. opens", "she slaps his face", etc.)
  348.  
  349. FF 2F 00    End of Track
  350. This event is not optional.  It is included so that an exact ending 
  351. point may be specified for the track, so that it has an exact length, 
  352. which is necessary for tracks which are looped or concatenated.  
  353.  
  354. FF 51 03 tttttt        Set Tempo, in microseconds per MIDI quarter-note
  355. This event indicates a tempo change.  Another way of putting 
  356. "microseconds per quarter-note" is "24ths of a microsecond per MIDI 
  357. clock".  Representing tempos as time per beat instead of beat per time 
  358. allows absolutely exact long-term synchronization with a time-based sync 
  359. protocol such as SMPTE time code or MIDI time code.  This amount of 
  360. accuracy provided by this tempo resolution allows a four-minute piece at 
  361. 120 beats per minute to be accurate within 500 usec at the end of the 
  362. piece.  Ideally, these events should only occur where MIDI clocks would 
  363. be located Q this convention is intended to guarantee, or at least 
  364. increase the likelihood, of compatibility with other synchronization 
  365. devices so that a time signature/tempo map stored in this format may 
  366. easily be transferred to another device. 
  367.  
  368. FF 54 05 hr mn se fr ff    SMPTE Offset  (New in 0.06 - SMPTE Format 
  369. specification)
  370. This event, if present, designates the SMPTE time at which the track 
  371. chunk is supposed to start.  It should be present at the beginning of 
  372. the track, that is, before any nonzero delta-times, and before any 
  373. transmittable MIDI events.  The hour must be encoded with the SMPTE 
  374. format, just as it is in MIDI Time Code.  In a format 1 file, the SMPTE 
  375. Offset must be stored with the tempo map, and has no meaning in any of 
  376. the other tracks.  The ff field contains fractional frames, in 100ths of 
  377. a frame, even in SMPTE-based tracks which specify a different frame 
  378. subdivision for delta-times.
  379.  
  380. FF 58 04 nn dd cc bb    Time Signature 
  381. The time signature is expressed as four numbers.  nn and dd represent 
  382. the numerator and denominator of the time signature as it would be 
  383. notated.  The denominator is a negative power of two:  2 represents a 
  384. quarter-note, 3 represents an eighth-note, etc.  The cc parameter 
  385. expresses the number of MIDI clocks in a metronome click.  The bb 
  386. parameter expresses the number of notated 32nd-notes in a MIDI quarter-
  387. note (24 MIDI Clocks).  This was added because there are already 
  388. multiple programs which allow the user to specify that what MIDI thinks 
  389. of as a quarter-note (24 clocks) is to be notated as, or related to in 
  390. terms of, something else. 
  391.  
  392. Therefore, the complete event for 6/8 time, where the metronome clicks 
  393. every three eighth-notes, but there are 24 clocks per quarter-note, 72 
  394. to the bar, would be (in hex):
  395.  
  396.     FF 58 04 06 03 24 08
  397.  
  398. That is, 6/8 time (8 is 2 to the 3rd power, so this is 06 03), 32 MIDI 
  399. clocks per dotted-quarter (24 hex!), and eight notated 32nd-notes per 
  400. MIDI quarter note.
  401.  
  402. FF 59 02 sf mi    Key Signature
  403.         sf = -7:  7 flats
  404.         sf = -1:  1 flat
  405.         sf = 0:  key of C
  406.         sf = 1:  1 sharp
  407.         sf = 7: 7 sharps
  408.         
  409.         mi = 0:  major key
  410.         mi = 1:  minor key
  411.         
  412. FF 7F len data    Sequencer-Specific Meta-Event
  413.  
  414.         Special requirements for particular sequencers may use this 
  415. event type:  the first byte or bytes of data is a manufacturer ID.  
  416. However, as this is an interchange format, growth of the spec proper is 
  417. preferred to use of this event type.  This type of event may be used by 
  418. a sequencer which elects to use this as its only file format;  
  419. sequencers with their established feature-specific formats should 
  420. probably stick to the standard features when using this format.
  421.  
  422. 4   Program Fragments and Example MIDI Files
  423.  
  424. Here are some of the routines to read and write variable-length numbers 
  425. in MIDI Files.  These routines are in C, and use getc and putc, which 
  426. read and write single 8-bit characters from/to the files infile and 
  427. outfile.  
  428.  
  429. WriteVarLen (value)
  430. register long value;
  431. {
  432.     register long buffer;
  433.  
  434.     buffer = value & 0x7f;
  435.     while ((value >>= 7) > 0)
  436.     {
  437.         buffer <<= 8;
  438.         buffer |= 0x80;
  439.         buffer += (value & 0x7f);
  440.     }
  441.  
  442.     while (TRUE)
  443.     {
  444.         putc(buffer,outfile);
  445.         if (buffer & 0x80)
  446.             buffer >>= 8;
  447.         else
  448.             break;
  449.     } 
  450. }
  451.     
  452. doubleword ReadVarLen ()
  453. {
  454.      register doubleword value;
  455.     register byte c;
  456.     
  457.     if ((value = getc(infile)) & 0x80)
  458.     {
  459.         value &= 0x7f;
  460.         do
  461.         {
  462.             value = (value << 7) + ((c = getc(infile)) & 0x7f);
  463.         } while (c & 0x80);
  464.     }
  465.     return (value);
  466. }
  467.  
  468. As an example, MIDI Files for the following excerpt are shown below.  
  469. First, a format 0 file is shown, with all information intermingled; 
  470. then, a format 1 file is shown with all data separated into four tracks:  
  471. one for tempo and time signature, and three for the notes.  A resolution 
  472. of 96 "ticks" per quarter note is used.  A time signature of 4/4 and a 
  473. tempo of 120, though implied, are explicitly stated.
  474.  
  475.  
  476.  
  477.  
  478. The contents of the MIDI stream represented by this example are broken 
  479. down here:
  480.  
  481. Delta Time(decimal)  Event Code (hex)   Other Bytes (decimal)    
  482.     Comment
  483.     0    FF 58    04 04 02 24 08    4 bytes: 4/4 time, 24 MIDI 
  484. clocks/click, 
  485.                 8 32nd notes/24 MIDI clocks
  486.     0    FF 51    03 500000    3 bytes: 500,000 5sec per quarter-note
  487.     0    C0    5    Ch. 1, Program Change 5
  488.     0    C0    5    Ch. 1, Program Change 5
  489.     0    C1    46    Ch. 2, Program Change 46
  490.     0    C2    70    Ch. 3, Program Change 70
  491.     0    92    48  96    Ch. 3 Note On C2, forte
  492.     0    92    60  96    Ch. 3 Note On C3, forte
  493.     96    91    67  64    Ch. 2 Note On G3, mezzo-forte
  494.     96    90    76  32    Ch. 1 Note On E4, piano
  495.     192    82    48  64    Ch. 3 Note Off C2, standard
  496.     0    82    60  64    Ch. 3 Note Off C3, standard
  497.     0    81    67  64    Ch. 2 Note Off G3, standard
  498.     0    80    76  64    Ch. 1 Note Off E4, standard
  499.     0    FF 2F    00    Track End
  500.  
  501. The entire format 0 MIDI file contents in hex follow.  First, the header 
  502. chunk:
  503.  
  504.         4D 54 68 64     MThd
  505.         00 00 00 06    chunk length
  506.         00 00     format 0
  507.         00 01    one track
  508.         00 60     96 per quarter-note
  509.  
  510. Then, the track chunk.  Its header, followed by the events (notice that 
  511. running status is used in places):
  512.  
  513.         4D 54 72 6B    MTrk
  514.         00 00 00 3B    chunk length (59)
  515.  
  516.     Delta-time    Event    Comments
  517.     00    FF 58 04 04 02 18 08     time signature
  518.     00    FF 51 03 07 A1 20    tempo
  519.     00    C0 05
  520.     00    C1 2E
  521.     00    C2 46
  522.     00    92 30 60 
  523.     00    3C 60    running status
  524.     60    91 43 40
  525.     60    90 4C 20
  526.     81 40    82 30 40    two-byte delta-time
  527.     00    3C 40    running status
  528.     00    81 43 40
  529.     00    80 4C 40
  530.     00    FF 2F 00    end of track
  531.  
  532. A format 1 representation of the file is slightly different.  Its header 
  533. chunk:
  534.  
  535.         4D 54 68 64     MThd
  536.         00 00 00 06    chunk length
  537.         00 01     format 1
  538.         00 04    four tracks
  539.         00 60     96 per quarter-note
  540.  
  541. First, the track chunk for the time signature/tempo track.  Its header, 
  542. followed by the events:
  543.  
  544.         4D 54 72 6B    MTrk
  545.         00 00 00 14    chunk length (20)
  546.  
  547.     Delta-time    Event    Comments
  548.     00    FF 58 04 04 02 18 08     time signature
  549.     00    FF 51 03 07 A1 20    tempo
  550.     83 00    FF 2F 00    end of track
  551.  
  552. Then, the track chunk for the first music track.  The MIDI convention 
  553. for note on/off running status is used in this example:
  554.  
  555.         4D 54 72 6B    MTrk
  556.         00 00 00 10    chunk length (16)
  557.  
  558.     Delta-time    Event    Comments
  559.     00    C0 05
  560.     81 40    90 4C 20
  561.     81 40    4C 00    Running status: note on, vel = 0
  562.     00    FF 2F 00    end of track
  563.  
  564. Then, the track chunk for the second music track:
  565.  
  566.         4D 54 72 6B    MTrk
  567.         00 00 00 0F    chunk length (15)
  568.  
  569.     Delta-time    Event    Comments
  570.     00    C1 2E
  571.     60    91 43 40
  572.     82 20    43 00    running status
  573.     00    FF 2F 00    end of track
  574.  
  575. Then, the track chunk for the third music track:
  576.  
  577.         4D 54 72 6B    MTrk
  578.         00 00 00 15    chunk length (21)
  579.  
  580.     Delta-time    Event    Comments
  581.     00    C2 46
  582.     00    92 30 60 
  583.     00    3C 60    running status
  584.     83 00    30 00    two-byte delta-time, running status
  585.     00    3C 00    running status
  586.     00    FF 2F 00    end of track
  587.  
  588. 5   MIDI Transmission of MIDI Files
  589.  
  590. Since it is inconvenient to exchange disks between different computers, 
  591. and since many computers which will use this format will have a MIDI 
  592. interface anyway, MIDI seems like a perfect way to send these files from 
  593. one computer to another.  And, while we're going through all the trouble 
  594. to make a way of sending MIDI Files, it would be nice if they could send 
  595. any files (like sampled sound files, text files, etc.)
  596.  
  597. Goals
  598. The transmission protocol for MIDI files should be reasonably efficient, 
  599. should support fast transmission for computers which are capable of it, 
  600. and slower transmission for less powerful ones.  It should not be 
  601. impossible to convert a MIDI File to or from an arbitrary internal 
  602. representation on the fly as it is transmitted, but, as long as it is 
  603. not too difficult, it is very desirable to use a generic method so that 
  604. any file type could be accommodated.
  605.  
  606. To make the protocol efficient, the MIDI transmission of these files 
  607. will take groups of seven 8-bit bytes and transmit them as eight 7-bit 
  608. MIDI data bytes.  This is certainly in the spirit of the rest of this 
  609. format (keep it small, because it's not that hard to do).  To 
  610. accommodate a wide range of transmission speeds, files will be 
  611. transmitted in packets with acknowledge -- this allows data to be stored 
  612. to disk as it is received.  If the sender does not receive a response 
  613. from a reader in a certain amount of time, it can assume an open-loop 
  614. situation, and then just continue.  
  615.  
  616. The last edition of MIDI Files contained a specialized protocol for 
  617. sending just MIDI Files.  To meet a deadline, unfortunately I don't have 
  618. time right now to propose a new generalized protocol.  This will be done 
  619. within the next couple of months.  I would welcome any proposals anyone 
  620. else has, and would direct your attention to the proposal from Ralph 
  621. Muha of Kurzweil, available in a recent MMA bulletin, and also directly 
  622. from him.
  623.