OpenTTD Source
20241121-master-g67a0fccfad
|
Decoder for "MPS MIDI" format data. More...
Data Structures | |
struct | Channel |
Starting parameter and playback status for one channel/track. More... | |
Public Types | |
enum | MpsMidiStatus { MPSMIDIST_SEGMENT_RETURN = 0xFD , MPSMIDIST_SEGMENT_CALL = 0xFE , MPSMIDIST_ENDSONG = 0xFF } |
Overridden MIDI status codes used in the data format. More... | |
Public Member Functions | |
MpsMachine (const uint8_t *data, size_t length, MidiFile &target) | |
Construct a TTD DOS music format decoder. More... | |
uint16_t | ReadVariableLength (uint32_t &pos) |
Read an SMF-style variable length value (note duration) from songdata. More... | |
void | RestartSong () |
Prepare for playback from the beginning. More... | |
uint16_t | PlayChannelFrame (MidiFile::DataBlock &outblock, int channel) |
Play one frame of data from one channel. | |
bool | PlayFrame (MidiFile::DataBlock &block) |
Play one frame of data into a block. | |
bool | PlayInto () |
Perform playback of whole song. | |
Static Public Member Functions | |
static void | AddMidiData (MidiFile::DataBlock &block, uint8_t b1, uint8_t b2) |
static void | AddMidiData (MidiFile::DataBlock &block, uint8_t b1, uint8_t b2, uint8_t b3) |
Data Fields | |
Channel | channels [16] |
playback status for each MIDI channel | |
std::vector< uint32_t > | segments |
pointers into songdata to repeatable data segments | |
int16_t | tempo_ticks |
ticker that increments when playing a frame, decrements before playing a frame | |
int16_t | current_tempo |
threshold for actually playing a frame | |
int16_t | initial_tempo |
starting tempo of song | |
bool | shouldplayflag |
not-end-of-song flag | |
const uint8_t * | songdata |
raw data array | |
size_t | songdatalen |
length of song data | |
MidiFile & | target |
recipient of data | |
Static Public Attributes | |
static const int | TEMPO_RATE = 148 |
Frames/ticks per second for music playback. | |
static const uint8_t | programvelocities [128] |
Base note velocities for various GM programs. More... | |
Decoder for "MPS MIDI" format data.
This format for MIDI music is also used in a few other Microprose games contemporary with Transport Tycoon.
The song data are usually packed inside a CAT file, with one CAT chunk per song. The song titles are used as names for the CAT chunks.
Unlike the Standard MIDI File format, which is based on the IFF structure, the MPS MIDI format is best described as two linked lists of sub-tracks, the first list contains a number of reusable "segments", and the second list contains the "master tracks". Each list is prefixed with a byte giving the number of elements in the list, and the actual list is just a byte count (BE16 format) for the segment/track followed by the actual data, there is no index as such, so the entire data must be seeked through to build an index.
The actual MIDI data inside each track is almost standard MIDI, prefixing every event with a delay, encoded using the same variable-length format used in SMF. A few status codes have changed meaning in MPS MIDI: 0xFE changes control from master track to a segment, 0xFD returns from a segment to the master track, and 0xFF is used to end the song. (In Standard MIDI all those values must only occur in real-time data.)
As implemented in the original decoder, there is no support for recursively calling segments from segments, i.e. code 0xFE must only occur in a master track, and code 0xFD must only occur in a segment. There are no checks made for this, it's assumed that the only input data will ever be the original game music, not music from other games, or new productions.
Additionally, some program change and controller events are given special meaning, see comments in the code.
Definition at line 497 of file midifile.cpp.
Overridden MIDI status codes used in the data format.
Definition at line 523 of file midifile.cpp.
|
inline |
Construct a TTD DOS music format decoder.
data | Buffer of song data from CAT file, ownership remains with caller |
length | Length of the data buffer in bytes |
target | MidiFile object to add decoded data to |
Definition at line 547 of file midifile.cpp.
|
inline |
Read an SMF-style variable length value (note duration) from songdata.
pos | Position to read from, updated to point to next byte after the value read |
Definition at line 586 of file midifile.cpp.
Referenced by RestartSong().
|
inline |
Prepare for playback from the beginning.
Resets the song pointer for every track to the beginning.
Definition at line 600 of file midifile.cpp.
References MpsMachine::Channel::delay, MpsMachine::Channel::playpos, ReadVariableLength(), and MpsMachine::Channel::startpos.
Referenced by PlayInto().
|
static |
Base note velocities for various GM programs.
Definition at line 516 of file midifile.cpp.