Module file

Source
Expand description

The file module is for types and concepts strictly related to MIDI files. These are separated from types and concepts that are also used in realtime MIDI (core).

Structs§

Header
2.1 - Header Chunks The header chunk at the beginning of the file specifies some basic information about the data in the file. Here’s the syntax of the complete chunk: <Header Chunk> = <chunk type><length><format><ntrks><division>
MicrosecondsPerQuarter
In MIDI tempos are given as microseconds per quarter note. Tempo microseconds are given by a 6-byte integer, hence the weird upper-bound (16,777,215). The default tempo is 120 beats per minute, which is 500_000 microseconds per beat. The minimum value is 1 since 0 microseconds per beat would be an infinitely fast tempo.
QuarterNoteDivision
The allowable values for Division when using the quarter note method. It is a positive u14 and thus has the range 1 to 16,383. The default value is 1024.
QuartersPerMinute
A more convenient way to specify tempo, not part of the MIDI spec. This is closer to the way we think of tempo, e.g. “120 Beats per Minute”. This type is locked to quarter-notes so you will have to translate if your “beat” is not a quarter note. Any u8 greater than zero is valid.
SysexEvent
Caution: Sysex messages are not implemented and will error.
TimeSignatureValue
FF 58 04 nn dd cc bb Time Signature The time signature is expressed as four numbers. nn and dd represent the numerator and denominator of the time signature as it would be notated. The denominator is a negative power of two: 2 represents a quarter-note, 3 represents an eighth-note, etc. The cc parameter expresses the number of MIDI clocks in a metronome click. The bb parameter expresses the number of notated 32nd-notes in a MIDI quarter-note (24 MIDI clocks). This was added because there are already multiple programs which allow a user to specify that what MIDI thinks of as a quarter-note (24 clocks) is to be notated as, or related to in terms of, something else.
Track
2.3 - Track Chunks The track chunks (type MTrk) are where actual song data is stored. Each track chunk is simply a stream of MIDI events (and non-MIDI events), preceded by delta-time values. The format for Track Chunks (described below) is exactly the same for all three formats (0, 1, and 2: see “Header Chunk” above) of MIDI Files.
TrackEvent
=

Enums§

Division
Specifies the meaning of the delta-times. It has two formats, one for metrical time, and one for time-code-based time:
Event
= | |
Format
The first word, , specifies the overall organisation of the file. Only three values of <format> are specified:
MetaEvent
Meta Events seem to only exist in the MIDI File Spec. Here is what it says about them: A few meta-events are defined herein. It is not required for every program to support every meta-event.
SysexEventType
<sysex event> is used to specify a MIDI system exclusive message, either as one unit or in packets, or as an “escape” to specify any arbitrary bytes to be transmitted. See Appendix 1 - MIDI Messages. A normal complete system exclusive message is stored in a MIDI File in this way: