home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / amfm / archives / amfm3.dms / amfm3.adf / text / smf.txt.pp / smf.txt
Text File  |  1991-11-05  |  27KB  |  625 lines

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