OpenTTD Source  12.0-beta2
MidiFile Struct Reference

Data Structures

struct  DataBlock
 
struct  TempoChange
 

Public Member Functions

bool LoadFile (const char *filename)
 Load a standard MIDI file. More...
 
bool LoadMpsData (const byte *data, size_t length)
 Create MIDI data from song data for the original Microprose music drivers. More...
 
bool LoadSong (const MusicSongInfo &song)
 
void MoveFrom (MidiFile &other)
 Move data from other to this, and clears other. More...
 
bool WriteSMF (const char *filename)
 Write a Standard MIDI File containing the decoded music. More...
 

Static Public Member Functions

static std::string GetSMFFile (const MusicSongInfo &song)
 Get the name of a Standard MIDI File for a given song. More...
 
static bool ReadSMFHeader (const char *filename, SMFHeader &header)
 Read the header of a standard MIDI file. More...
 
static bool ReadSMFHeader (FILE *file, SMFHeader &header)
 Read the header of a standard MIDI file. More...
 

Data Fields

std::vector< DataBlockblocks
 sequential time-annotated data of file, merged to a single track
 
std::vector< TempoChangetempos
 list of tempo changes in file
 
uint16 tickdiv
 ticks per quarter note
 

Detailed Description

Definition at line 21 of file midifile.hpp.

Member Function Documentation

◆ GetSMFFile()

std::string MidiFile::GetSMFFile ( const MusicSongInfo song)
static

Get the name of a Standard MIDI File for a given song.

For songs already in SMF format, just returns the original. Otherwise the song is converted, written to a temporary-ish file, and the written filename is returned.

Parameters
songSong definition to query
Returns
Full filename string, empty string if failed

Definition at line 1047 of file midifile.cpp.

References BASESET_DIR, MusicSongInfo::filename, MusicSongInfo::filetype, FioFindFullPath(), MTT_MPSMIDI, MTT_STANDARDMIDI, and OLD_GM_DIR.

Referenced by MusicDriver_FluidSynth::PlaySong(), MusicDriver_OS2::PlaySong(), MusicDriver_BeMidi::PlaySong(), and MusicDriver_ExtMidi::PlaySong().

◆ LoadFile()

bool MidiFile::LoadFile ( const char *  filename)

Load a standard MIDI file.

Parameters
filenamename of the file to load
Returns
true if loaded was successful

Definition at line 457 of file midifile.cpp.

References BASESET_DIR, blocks, FioFCloseFile(), FioFOpenFile(), ReadSMFHeader(), tempos, and tickdiv.

◆ LoadMpsData()

bool MidiFile::LoadMpsData ( const byte *  data,
size_t  length 
)

Create MIDI data from song data for the original Microprose music drivers.

Parameters
datapointer to block of data
lengthsize of data in bytes
Returns
true if the data could be loaded

Definition at line 839 of file midifile.cpp.

References MpsMachine::PlayInto().

◆ MoveFrom()

void MidiFile::MoveFrom ( MidiFile other)

Move data from other to this, and clears other.

Parameters
otherobject containing loaded data to take over

Definition at line 873 of file midifile.cpp.

References blocks, tempos, and tickdiv.

◆ ReadSMFHeader() [1/2]

bool MidiFile::ReadSMFHeader ( const char *  filename,
SMFHeader header 
)
static

Read the header of a standard MIDI file.

Parameters
[in]filenamename of file to read from
[out]headerfilled with data read
Returns
true if the file could be opened and contained a header with correct format

Definition at line 415 of file midifile.cpp.

References BASESET_DIR, FioFCloseFile(), and FioFOpenFile().

Referenced by LoadFile().

◆ ReadSMFHeader() [2/2]

bool MidiFile::ReadSMFHeader ( FILE *  file,
SMFHeader header 
)
static

Read the header of a standard MIDI file.

The function will consume 14 bytes from the current file pointer position.

Parameters
[in]fileopen file to read from (should be in binary mode)
[out]headerfilled with data read
Returns
true if a header in correct format could be read from the file

Definition at line 431 of file midifile.cpp.

References MemCmpT().

◆ WriteSMF()

bool MidiFile::WriteSMF ( const char *  filename)

Write a Standard MIDI File containing the decoded music.

Parameters
filenameName of file to write to
Returns
True if the file was written to completion

Definition at line 917 of file midifile.cpp.

References FioFOpenFile(), and NO_DIRECTORY.


The documentation for this struct was generated from the following files: