User Tools

Site Tools


midi_file_format

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
midi_file_format [2011/11/10 02:00] javapimpmidi_file_format [2023/08/18 18:15] (current) – external edit 127.0.0.1
Line 25: Line 25:
 The next field is a 16-bit value specifying the number of tracks in the file (''nn nn'' above). For single-track this value is 1. For multiple track files this can be up to 65535. The next field is a 16-bit value specifying the number of tracks in the file (''nn nn'' above). For single-track this value is 1. For multiple track files this can be up to 65535.
  
-The last field is a 16-bit value specifying the number of delta-time ticks per quarter note (''dd dd'' above) or frames per second. If the most significant bit is 0 the remaining bits specify the delta-time ticks per beat. If the most significant bit is 1 the remaining bits spacify the delta-time in frames per second. For ticks per beat, common values range from 48 to 960.+The last field is a 16-bit value specifying the number of delta-time ticks per quarter note (''dd dd'' above) or frames per second. If the most significant bit is 0 the remaining bits specify the delta-time ticks per beat. If the most significant bit is 1 the remaining bits specify the delta-time in frames per second. For ticks per beat, common values range from 48 to 960.
  
 Frames per second is defined by breaking the remaining 15 bits into two values. The top 7 bits define a value for the number of SMPTE frames and can be 24, 25, 29 (for 29.97 fps) or 30. The remaining 8 bits define how many ticks there are per frame.  Frames per second is defined by breaking the remaining 15 bits into two values. The top 7 bits define a value for the number of SMPTE frames and can be 24, 25, 29 (for 29.97 fps) or 30. The remaining 8 bits define how many ticks there are per frame. 
Line 93: Line 93:
 Each command byte has 2 parts. The left nibble (4 bits) contains the actual command, and the right nibble (''xxxx'') contains the midi channel number on which the command will be executed. There are 16 midi channels and 8 midi commands. The data bytes that follow the command will have a most significant bit of 0. Each command byte has 2 parts. The left nibble (4 bits) contains the actual command, and the right nibble (''xxxx'') contains the midi channel number on which the command will be executed. There are 16 midi channels and 8 midi commands. The data bytes that follow the command will have a most significant bit of 0.
  
-^ Hex    ^ Binary       ^ Data      ^ Description ^ +^ Hex    ^ Binary       ^ Data            ^ Description ^ 
-| ''8x'' | ''1000xxxx'' | ''nn vv'' | Note off event. This message is sent when a note is released (ended).\\ \\ ''nn'' = note number \\ ''vv'' = velocity | +| ''8x'' | ''1000xxxx'' | ''nn vv''       | Note off event. This message is sent when a note is released (ended).\\ \\ ''nn'' = note number \\ ''vv'' = velocity | 
-| ''9x'' | ''1001xxxx'' | ''nn vv'' | Note on event. This message is sent when a note is depressed (start). A "note on" event with a velocity of zero is equivalent to a "note off" event.\\ \\ ''nn'' = note number \\ ''vv'' = velocity | +| ''9x'' | ''1001xxxx'' | ''nn vv''       | Note on event. This message is sent when a note is depressed (start). A "note on" event with a velocity of zero is equivalent to a "note off" event.\\ \\ ''nn'' = note number \\ ''vv'' = velocity | 
-| ''Ax'' | ''1010xxxx'' | ''nn vv'' | Polyphonic Key Pressure (After-touch). This message is sent when the pressure (velocity) of a previously triggered note changes.\\ \\ ''nn'' = note number \\ ''vv'' = velocity | +| ''Ax'' | ''1010xxxx'' | ''nn vv''       | Polyphonic Key Pressure (After-touch). This message is sent when the pressure (velocity) of a previously triggered note changes.\\ \\ ''nn'' = note number \\ ''vv'' = velocity | 
-| ''Bx'' | ''1011xxxx'' | ''cc vv'' | This message is sent when a controller value changes.  Controllers include devices such as pedals and levers. Certain controller numbers are reserved for specific purposes. See Channel Mode Messages.\\ \\ ''cc'' = controller number \\ ''vv'' = new value | +| ''Bx'' | ''1011xxxx'' | ''cc vv''       | This message is sent when a controller value changes.  Controllers include devices such as pedals and levers. Certain controller numbers are reserved for specific purposes. See Channel Mode Messages.\\ \\ ''cc'' = controller number \\ ''vv'' = new value | 
-| ''Cx'' | ''1100xxxx'' | ''pp''    | Program (patch) change. This message sent when the patch number changes. \\ ''pp'' = new program number | +| ''Cx'' | ''1100xxxx'' | ''pp''          | Program (patch) change. This message sent when the patch number changes. \\ ''pp'' = new program number | 
-| ''Dx'' | ''1101xxxx'' | ''cc''    | Channel Pressure (After-touch). This message is sent when the channel pressure changes. Some velocity-sensing keyboards do not support polyphonic after-touch. Use this message to send the single greatest velocity.\\ \\ ''cc'' = channel number | +| ''Dx'' | ''1101xxxx'' | ''cc''          | Channel Pressure (After-touch). This message is sent when the channel pressure changes. Some velocity-sensing keyboards do not support polyphonic after-touch. Use this message to send the single greatest velocity.\\ \\ ''cc'' = channel number | 
-| ''Ex'' | ''1110xxxx'' | ''bb tt'' | Pitch wheel change. This message is sent to indicate a change in the pitch wheel.  The pitch wheel is measured by a fourteen bit value. Center (no pitch change) is 2000H.  Sensitivity is a function of the transmitter.\\ \\ ''bb'' = bottom (least sig) 7 bits of value \\ ''tt'' = top (most sig) 7 bits of value |+| ''Ex'' | ''1110xxxx'' | ''bb tt''       | Pitch wheel change. This message is sent to indicate a change in the pitch wheel.  The pitch wheel is measured by a fourteen bit value. Center (no pitch change) is 2000H.  Sensitivity is a function of the transmitter.\\ \\ ''bb'' = bottom (least sig) 7 bits of value \\ ''tt'' = top (most sig) 7 bits of value 
 +| ''FF'' | ''11111111'' | ''xx nn dd ..'' | Meta-event. This message indicates a meta-event which is described below. |
  
-The following table lists the numbers corresponding to notes for use in note  on and note off commands.+=== Channel Mode Messages ===
  
-Octave                              Notes                         |||||||||||+Hex    Binary       ^ Data      ^ Description 
-       C   C#  D   | D#  | E   | F   | F#  | G   | G#  | A   | A#  | B   | +''Bx'' ''1011xxxx'' ''cc vv'' This the same code as the Control Change (above), but implements Mode control by using reserved controller numbers.  The numbers are: \\ \\ **Local Control.**\\ When Local Control is Off, all devices on a given channel will respond only to data received over MIDI.  Played data, etc. will be ignored.  Local Control On restores the functions of the normal controllers.\\ \\ ''cc'' = 122, ''vv''0: Local Control Off\\ ''cc''122, ''vv'' = 127: Local Control On\\ \\ **All Notes Off.**\\ When an All Notes Off is received, all oscillators will turn off.\\ \\ ''cc''123, ''vv'' = 0: All Notes Off\\ \\ (See text for description of actual mode commands.)\\ ''cc''124, ''vv'' = 0: Omni Mode Off\\ ''cc''125, ''vv'' = 0: Omni Mode On\\ ''cc''126, ''vv'' = ''M'': Mono Mode On (Poly Off) where ''M'' is the number of channels (Omni Off) or 0 (Omni On)\\ ''cc''127, ''vv'' = 0: Poly Mode On (Mono Off)\\ (Note: These four messages also cause All Notes Off) |
-|      |   0 |   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10 | 11  | +
-|    1    12 |  13 |  14 |  15 |  16 |  17 |  18 |  19 |  20 |  21 |  22 | 23  | +
-|    2    24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  32 |  33 |  34 | 35  | +
-|    3    36 |  37 |  38 |  39 |  40 |  41 |  42 |  43 |  44 |  45 |  46 | 47  | +
-|    4    48 |  49 |  50 |  51 |  52 |  53 |  54 |  55 |  56 |  57 |  58 | 59  | +
-|    5    60 |  61 |  62 |  63 |  64 |  65 |  66 |  67 |  68 |  69 |  70 | 71  | +
-|    6    72 |  73 |  74 |  75 |  76 |  77 |  78 |  79 |  80 |  81 |  82 | 83  | +
-|    7    84 |  85 |  86 |  87 |  88 |  89 |  90 |  91 |  92 |  93 |  94 | 95  | +
-|    8    96 |  97 |  98 |  99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | +
-|    9   | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | +
-|   10   | 120 | 121 | 122 123 124 125 126 127 |+
  
 ==== Meta-Events ==== ==== Meta-Events ====
Line 136: Line 126:
 | ''07'' | ''00000111'' | ''nn tt ...''         | Cue point. Marks the start of some type of new sound or action.\\ \\ ''nn tt'' = same as text event. | | ''07'' | ''00000111'' | ''nn tt ...''         | Cue point. Marks the start of some type of new sound or action.\\ \\ ''nn tt'' = same as text event. |
 | ''20'' | ''00100000'' | ''??''                | MIDI channel prefix assignment. | | ''20'' | ''00100000'' | ''??''                | MIDI channel prefix assignment. |
-| ''21'' | ''00100001'' | ''pp''                | Has been used, though unofficially, for a MIDI port or cable number. (deprecated) |+| ''21'' | ''00100001'' | ''01 pp''             | Has been used, though unofficially, for a MIDI port or cable number. (deprecated) |
 | ''2F'' | ''00101111'' | ''00''                | End of Track. This event must come at the end of each track. | | ''2F'' | ''00101111'' | ''00''                | End of Track. This event must come at the end of each track. |
-| ''51'' | ''01010001'' | ''03 tttttt''         | Set tempo\\ \\ ''tttttt'' = microseconds/quarter note. (microseconds/beat)\\ \\ MICROSECONDS_PER_MINUTE = 60000000\\ \\ BPM = MICROSECONDS_PER_MINUTE / MPQN\\ MPQN = MICROSECONDS_PER_MINUTE / BPM\\ \\ TODO: How does this relate to delta-time ticks per quarter note specified in the header chunk? |+| ''51'' | ''01010001'' | ''03 tttttt''         | Set tempo\\ \\ ''tttttt'' = microseconds/quarter note. (microseconds/beat)\\ \\ MICROSECONDS_PER_MINUTE = 60000000\\ \\ BPM = MICROSECONDS_PER_MINUTE / MPQN\\ MPQN = MICROSECONDS_PER_MINUTE / BPM\\ \\ If no tempo is specified, the default is 120 beats-per-minute. (500,000 microseconds/beat)\\ \\ TODO: How does this relate to delta-time ticks per quarter note specified in the header chunk? |
 | ''54'' | ''01010100'' | ''05 hh mm ss ff sf'' | SMPTE offset. SMPTE starting point from the beginning of the track. ''hh'' = hours (0-23), ''mm'' = minutes (0-59), ''ss'' = seconds (0-59), ''ff'' = frames (0-30) and ''sf'' = sub-frames (0-99) (always 100 sub-frames per frame, no matter what sub-division is specified in the MIDI header chunk).\\ \\ The byte used to specify the hour offset also specifies the frame rate in the following format: ''0rrhhhhh'' where ''rr'' is two bits for the frame rate where 00 = 24 fps, 01 = 25 fps, 10 = 30 fps (drop frame), 11 = 30 fps and ''hhhhh'' is 5 bits for the hour (0-23). The hour byte's top bit is always 0. The frame byte's possible range depends on the encoded frame rate in the hour byte. A 25 fps frame rate means that a maximum value of 24 may be set for the frame byte.  | | ''54'' | ''01010100'' | ''05 hh mm ss ff sf'' | SMPTE offset. SMPTE starting point from the beginning of the track. ''hh'' = hours (0-23), ''mm'' = minutes (0-59), ''ss'' = seconds (0-59), ''ff'' = frames (0-30) and ''sf'' = sub-frames (0-99) (always 100 sub-frames per frame, no matter what sub-division is specified in the MIDI header chunk).\\ \\ The byte used to specify the hour offset also specifies the frame rate in the following format: ''0rrhhhhh'' where ''rr'' is two bits for the frame rate where 00 = 24 fps, 01 = 25 fps, 10 = 30 fps (drop frame), 11 = 30 fps and ''hhhhh'' is 5 bits for the hour (0-23). The hour byte's top bit is always 0. The frame byte's possible range depends on the encoded frame rate in the hour byte. A 25 fps frame rate means that a maximum value of 24 may be set for the frame byte.  |
 | ''58'' | ''01011000'' | ''04 nn dd cc bb''    | Time Signature\\ \\ ''nn'' = numerator of time sig. \\ ''dd'' = denominator of time sig. 2 = quarter 3 = eighth, etc.\\ ''cc'' = number of MIDI clocks in metronome click. (MIDI clocks per beat) \\ ''bb'' = number of 32nd notes to the quarter note\\ \\ MIDI clock bytes are used to synchronize playback of multiple MIDI devices. The MIDI clock ticks 24 times per quarter note. For example, 6/8 time with a metronome click every 3 eighth notes and 24 clocks per quarter note, the ''cc'' value would be set to 36 MIDI clocks per beat. | | ''58'' | ''01011000'' | ''04 nn dd cc bb''    | Time Signature\\ \\ ''nn'' = numerator of time sig. \\ ''dd'' = denominator of time sig. 2 = quarter 3 = eighth, etc.\\ ''cc'' = number of MIDI clocks in metronome click. (MIDI clocks per beat) \\ ''bb'' = number of 32nd notes to the quarter note\\ \\ MIDI clock bytes are used to synchronize playback of multiple MIDI devices. The MIDI clock ticks 24 times per quarter note. For example, 6/8 time with a metronome click every 3 eighth notes and 24 clocks per quarter note, the ''cc'' value would be set to 36 MIDI clocks per beat. |
Line 159: Line 149:
 </code> </code>
      
-===== Channel Mode Messages ===== 
- 
-^ Hex    ^ Binary       ^ Data      ^ Description ^ 
-| ''Bx'' | ''1011xxxx'' | ''cc vv'' | This the same code as the Control Change (above), but implements Mode control by using reserved controller numbers.  The numbers are: \\ \\ **Local Control.**\\ When Local Control is Off, all devices on a given channel will respond only to data received over MIDI.  Played data, etc. will be ignored.  Local Control On restores the functions of the normal controllers.\\ \\ ''cc'' = 122, ''vv'' = 0: Local Control Off\\ ''cc'' = 122, ''vv'' = 127: Local Control On\\ \\ **All Notes Off.**\\ When an All Notes Off is received, all oscillators will turn off.\\ \\ ''cc'' = 123, ''vv'' = 0: All Notes Off\\ \\ (See text for description of actual mode commands.)\\ ''cc'' = 124, ''vv'' = 0: Omni Mode Off\\ ''cc'' = 125, ''vv'' = 0: Omni Mode On\\ ''cc'' = 126, ''vv'' = ''M'': Mono Mode On (Poly Off) where ''M'' is the number of channels (Omni Off) or 0 (Omni On)\\ ''cc'' = 127, ''vv'' = 0: Poly Mode On (Mono Off)\\ (Note: These four messages also cause All Notes Off) | 
- 
 ===== System Messages ===== ===== System Messages =====
  
-The following table lists system messages which control the entire system. These have no midi channel number. (these will generally only apply to controlling a midi keyboard, etc.)+The following are system messages which control the entire system. These commands are used to control physical MIDI devices and are not typically found in MIDI files. They have no midi channel number. (They will generally only apply to controlling a midi keyboard, etc.)
  
 ==== System Common Messages ==== ==== System Common Messages ====
Line 180: Line 165:
 | ''F7'' | ''11110111'' |                     | End of Exclusive. Used to terminate a System Exclusive dump (see above). | | ''F7'' | ''11110111'' |                     | End of Exclusive. Used to terminate a System Exclusive dump (see above). |
  
-=== Divided System Exclusive Events ===+==== Divided System Exclusive Events ====
  
 A large amount of System Exclusive data in a Normal System Exclusive Event could cause following MIDI Channel Events to be transmitted after the time they should be played. This will cause an unwanted delay in play back of the following events. The second type of System Exclusive Events solve this problem by allowing a large amount of System Exclusive data to be divided into smaller blocks, transmitted with a delay between each division to allow the transmission of other MIDI events in order to prevent congesting of the limited MIDI bandwidth. The initial Divided System Exclusive Event follows the same format as a Normal System Exclusive Event with the exception that the last data byte is not 0xF7. This indicates the the System Exclusive data is not finished and will be continued in an upcoming Divided System Exclusive Event. Any following Divided System Exclusive Events before the final one use the a similar format as the first, only the start byte is 0xF7 instead of 0xF0 to signal continuation of System Exclusive data. The final block follows the same format as the continuation blocks, except the last data byte is 0xF7 to signal the completion of the divided System Exclusive data. A large amount of System Exclusive data in a Normal System Exclusive Event could cause following MIDI Channel Events to be transmitted after the time they should be played. This will cause an unwanted delay in play back of the following events. The second type of System Exclusive Events solve this problem by allowing a large amount of System Exclusive data to be divided into smaller blocks, transmitted with a delay between each division to allow the transmission of other MIDI events in order to prevent congesting of the limited MIDI bandwidth. The initial Divided System Exclusive Event follows the same format as a Normal System Exclusive Event with the exception that the last data byte is not 0xF7. This indicates the the System Exclusive data is not finished and will be continued in an upcoming Divided System Exclusive Event. Any following Divided System Exclusive Events before the final one use the a similar format as the first, only the start byte is 0xF7 instead of 0xF0 to signal continuation of System Exclusive data. The final block follows the same format as the continuation blocks, except the last data byte is 0xF7 to signal the completion of the divided System Exclusive data.
  
-=== Authorization System Exclusive Events ===+==== Authorization System Exclusive Events ====
  
 The last type of System Exclusive Event authorizes and enables the transmission of special messages such as Song Position Pointer, MIDI Time Code and Song Select messages. These System Exclusive Events use the event type value 0xF7. The last type of System Exclusive Event authorizes and enables the transmission of special messages such as Song Position Pointer, MIDI Time Code and Song Select messages. These System Exclusive Events use the event type value 0xF7.
Line 198: Line 183:
 | ''FD'' | ''11111101'' |      | Undefined. | | ''FD'' | ''11111101'' |      | Undefined. |
 | ''FE'' | ''11111110'' |      | Active Sensing. Use of this message is optional. When initially sent, the receiver will expect to receive another Active Sensing message each 300ms (max), or it will be assume that the connection has been terminated. At termination, the receiver will turn off all voices and return to normal (non-active sensing) operation. | | ''FE'' | ''11111110'' |      | Active Sensing. Use of this message is optional. When initially sent, the receiver will expect to receive another Active Sensing message each 300ms (max), or it will be assume that the connection has been terminated. At termination, the receiver will turn off all voices and return to normal (non-active sensing) operation. |
-| ''FF'' | ''11111111'' |      | Reset. Reset all receivers in the system to power-up status. This should be used sparingly, preferably under manual control. In particular, it should not be sent on power-up. |+| ''FF'' | ''11111111'' |      | Reset. In terms  of MIDI devices, this command is to reset all receivers in the system to power-up status. This should be used sparingly, preferably under manual control. In particular, it should not be sent on power-up. The MIDI file format redefines this command for meta-events as described above.|
  
 ===== Controller Codes ===== ===== Controller Codes =====
 +
 +This table lists the controller codes used in the controller setting change command above.
  
 ^ Hex    ^ Decimal       ^ Description                                            ^        ^      ^ ^ Hex    ^ Decimal       ^ Description                                            ^        ^      ^
Line 306: Line 293:
 | ''65'' | ''101'' | Registered Parameter Number MSB                              |        ?    || | ''65'' | ''101'' | Registered Parameter Number MSB                              |        ?    ||
 | ''66'' | ''102'' | Undefined                                                    |        ?    || | ''66'' | ''102'' | Undefined                                                    |        ?    ||
-| ''67'' | ''103'' | Undefined                                                    |        ?    || 
-| ''67'' | ''103'' | Undefined                                                    |        ?    || 
-| ''67'' | ''103'' | Undefined                                                    |        ?    || 
-| ''67'' | ''103'' | Undefined                                                    |        ?    || 
 | ''67'' | ''103'' | Undefined                                                    |        ?    || | ''67'' | ''103'' | Undefined                                                    |        ?    ||
 | ''68'' | ''104'' | Undefined                                                    |        ?    || | ''68'' | ''104'' | Undefined                                                    |        ?    ||
Line 337: Line 320:
  
 *Note: This equals the number of channels, or zero if the number of channels equals the number of voices in the receiver. *Note: This equals the number of channels, or zero if the number of channels equals the number of voices in the receiver.
 +
 +===== Note Index =====
 +
 +The following table lists the numbers corresponding to notes for use in note  on and note off commands.
 +
 +^ Octave ^                              Notes                         |||||||||||^
 +|        | C   | C#  | D   | D#  | E   | F   | F#  | G   | G#  | A   | A#  | B   |
 +|    0     0 |   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10 | 11  |
 +|    1    12 |  13 |  14 |  15 |  16 |  17 |  18 |  19 |  20 |  21 |  22 | 23  |
 +|    2    24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  32 |  33 |  34 | 35  |
 +|    3    36 |  37 |  38 |  39 |  40 |  41 |  42 |  43 |  44 |  45 |  46 | 47  |
 +|    4    48 |  49 |  50 |  51 |  52 |  53 |  54 |  55 |  56 |  57 |  58 | 59  |
 +|    5    60 |  61 |  62 |  63 |  64 |  65 |  66 |  67 |  68 |  69 |  70 | 71  |
 +|    6    72 |  73 |  74 |  75 |  76 |  77 |  78 |  79 |  80 |  81 |  82 | 83  |
 +|    7    84 |  85 |  86 |  87 |  88 |  89 |  90 |  91 |  92 |  93 |  94 | 95  |
 +|    8    96 |  97 |  98 |  99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
 +|    9   | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 |
 +|   10   | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
  
 ===== General MIDI Instrument Patch Map ===== ===== General MIDI Instrument Patch Map =====
Line 423: Line 424:
 General MIDI also includes a __Percusssion Key Map__. This mapping derives from the Roland/Sequential mapping used on early drum machines. As with the Instrument Map, it doesn't cover every percussive instrument in the world, but it's more than adequate as a basic set. General MIDI also includes a __Percusssion Key Map__. This mapping derives from the Roland/Sequential mapping used on early drum machines. As with the Instrument Map, it doesn't cover every percussive instrument in the world, but it's more than adequate as a basic set.
  
-To avoid concerns with channels, GM restricts percussion to MIDI Channel 10. Theoretically, the lower nine channels are for the instruments, but the GM spec states that a sound module must respond to all sixteen MIDI channels, with dynamic voice allocation and a minimum of 24 voices.+To avoid concerns with channels, GM restricts percussion to MIDI Channel 9. Theoretically, the lower nine channels (0 - 8) are for the instruments, but the GM spec states that a sound module must respond to all sixteen MIDI channels, with dynamic voice allocation and a minimum of 24 voices.
  
 ^ MIDI key ^ Drum Sound         ^ MIDI key ^ Drum Sound     ^ ^ MIDI key ^ Drum Sound         ^ MIDI key ^ Drum Sound     ^
Line 456: Line 457:
   * "[[Standard MIDI File Format]]" - Dustin Caldwell   * "[[Standard MIDI File Format]]" - Dustin Caldwell
   * "[[http://www.sonicspot.com/guide/midifiles.html|MIDI File Format]]"   * "[[http://www.sonicspot.com/guide/midifiles.html|MIDI File Format]]"
 +  * "[[http://home.roadrunner.com/~jgglatt/|MIDI Technical Fanatic's Brainwashing Center]]"
   * "[[The USENET MIDI Primer]]" - Bob McQueer   * "[[The USENET MIDI Primer]]" - Bob McQueer
  
midi_file_format.1320890411.txt.gz · Last modified: 2023/08/18 18:15 (external edit)