A MIDI track represents a collection of MIDI packets. Each MIDI track uses the channel information in its packets--the packets contain the actual MIDI messages. Within a track, packets are sorted in order of increasing time stamp. Only one track can be recorded at a time, but multiple tracks can be played back simultaneously.
A MIDI packet contains a MIDI message, time stamp, and status byte. All MIDI message types and structures are encapsulated by TMIDIPacket. For convenience, classes are derived from TMIDIPacket for interpreting specific MIDI message types.
The status byte facilitates sequence editing by allowing each message to be read individually--every packet contains a status byte that identifies the purpose of the data bytes that follow. Running status mode is never used. The time stamp provides an absolute offset from the beginning of a sequence--it consists of a TTime instance that is assigned when the message is received. The time stamp allows you to synchronize a sequence of packets to any available TSyncableClock instance. Therefore, you can synchronize MIDI sequences with external devices and other time media.
You use classes derived from TMIDISequence to convert to and from particular file formats. For example, you use TStandardMIDIFile to access standard MIDI files (MIDI format 0 and MIDI format 1). To support new or nonstandard file formats, you derive new classes from TMIDISequence.
MIDI track
MIDI packet
MIDI files
MIDI file formats | ||
A MIDI file contains one header chunk that is followed by one or more track chunks. Each chunk has a four-character type and a 32-bit length that indicates how many bytes of data follow. A header chunk provides basic information about the data in the file. | A track chunk contains a sequential stream of MIDI data that can contain information for up to 16 MIDI channels. Track chunks are where actual song data is stored--each track chunk is simply a stream of MIDI events, preceded by delta-time values. | Format 0 has only one track chunk, which can contain messages for multiple MIDI channels as well as the tempo data. Format 1 allows multiple track chunks, which represent tracks that can be played simultaneously. |
NOTE In the current release, you must call TStandardMIDIFile::SetModified(kTrue) for the data in memory to be written to the file when the destructor for the TStandardMIDIFile is called.