12 #include "../stdafx.h" 13 #include "../openttd.h" 14 #include "../sound_type.h" 17 #include "midifile.hpp" 18 #include "../base_media_base.h" 20 #include <sys/types.h> 28 #include "../safeguards.h" 38 MidSongOptions options;
51 _midi.status = MIDI_STOPPED;
54 if (mid_init(param == NULL ? NULL : const_cast<char *>(param[0])) < 0) {
58 if (param != NULL || mid_init_no_config() < 0) {
59 return "error initializing timidity";
62 DEBUG(driver, 1,
"successfully initialised timidity");
64 _midi.options.rate = 44100;
65 _midi.options.format = MID_AUDIO_S16LSB;
66 _midi.options.channels = 2;
67 _midi.options.buffer_size =
_midi.options.rate;
83 if (filename.empty())
return;
85 _midi.stream = mid_istream_open_file(filename.c_str());
86 if (
_midi.stream == NULL) {
87 DEBUG(driver, 0,
"Could not open music file");
92 mid_istream_close(
_midi.stream);
93 _midi.song_length = mid_song_get_total_time(
_midi.song);
95 if (
_midi.song == NULL) {
96 DEBUG(driver, 1,
"Invalid MIDI file");
100 mid_song_start(
_midi.song);
101 _midi.status = MIDI_PLAYING;
106 _midi.status = MIDI_STOPPED;
108 if (
_midi.song != NULL) mid_song_free(
_midi.song);
114 if (
_midi.status == MIDI_PLAYING) {
115 _midi.song_position = mid_song_get_time(
_midi.song);
116 if (
_midi.song_position >=
_midi.song_length) {
117 _midi.status = MIDI_STOPPED;
118 _midi.song_position = 0;
122 return (
_midi.status == MIDI_PLAYING);
127 if (
_midi.song != NULL) mid_song_set_volume(
_midi.song, vol);
Metadata about a music track.
const char * Start(const char *const *param)
Start this driver.
bool IsSongPlaying()
Are we currently playing a song?
static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity
Factory for the libtimidity driver.
MidiState
The state of playing.
static struct @25 _midi
Metadata about the midi we're playing.
#define DEBUG(name, level,...)
Output a line of debugging information.
void SetVolume(byte vol)
Set the volume, if possible.
static std::string GetSMFFile(const MusicSongInfo &song)
Get the name of a Standard MIDI File for a given song.
Factory for the libtimidity driver.
void Stop()
Stop this driver.
void PlaySong(const MusicSongInfo &song)
Play a particular song.
Base for LibTimidity music playback.
void StopSong()
Stop playing the current song.