Mercurial > hg > openttd
changeset 7172:4f8826c95c52 draft
(svn r10446) -Codechange: Move extmidi's global data into its class.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Thu, 05 Jul 2007 13:19:35 +0000 |
parents | 971e9e044cc0 |
children | 8b43391dc0c2 |
files | src/music/extmidi.cpp src/music/extmidi.h |
diffstat | 2 files changed, 27 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/music/extmidi.cpp +++ b/src/music/extmidi.cpp @@ -16,47 +16,39 @@ #include <sys/stat.h> #include <errno.h> -static struct { - char song[MAX_PATH]; - pid_t pid; -} _midi; - -static void DoPlay(); -static void DoStop(); - static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi; const char* MusicDriver_ExtMidi::Start(const char* const * parm) { - _midi.song[0] = '\0'; - _midi.pid = -1; + this->song[0] = '\0'; + this->pid = -1; return NULL; } void MusicDriver_ExtMidi::Stop() { - _midi.song[0] = '\0'; - DoStop(); + this->song[0] = '\0'; + this->DoStop(); } void MusicDriver_ExtMidi::PlaySong(const char* filename) { - ttd_strlcpy(_midi.song, filename, lengthof(_midi.song)); - DoStop(); + ttd_strlcpy(this->song, filename, lengthof(this->song)); + this->DoStop(); } void MusicDriver_ExtMidi::StopSong() { - _midi.song[0] = '\0'; - DoStop(); + this->song[0] = '\0'; + this->DoStop(); } bool MusicDriver_ExtMidi::IsSongPlaying() { - if (_midi.pid != -1 && waitpid(_midi.pid, NULL, WNOHANG) == _midi.pid) - _midi.pid = -1; - if (_midi.pid == -1 && _midi.song[0] != '\0') DoPlay(); - return _midi.pid != -1; + if (this->pid != -1 && waitpid(this->pid, NULL, WNOHANG) == this->pid) + this->pid = -1; + if (this->pid == -1 && this->song[0] != '\0') this->DoPlay(); + return this->pid != -1; } void MusicDriver_ExtMidi::SetVolume(byte vol) @@ -64,10 +56,10 @@ DEBUG(driver, 1, "extmidi: set volume not implemented"); } -static void DoPlay() +void MusicDriver_ExtMidi::DoPlay() { - _midi.pid = fork(); - switch (_midi.pid) { + this->pid = fork(); + switch (this->pid) { case 0: { int d; @@ -75,9 +67,9 @@ d = open("/dev/null", O_RDONLY); if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) { #if defined(MIDI_ARG) - execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, (char*)0); + execlp(msf.extmidi, "extmidi", MIDI_ARG, this->song, (char*)0); #else - execlp(msf.extmidi, "extmidi", _midi.song, (char*)0); + execlp(msf.extmidi, "extmidi", this->song, (char*)0); #endif } _exit(1); @@ -88,14 +80,14 @@ /* FALLTHROUGH */ default: - _midi.song[0] = '\0'; + this->song[0] = '\0'; break; } } -static void DoStop() +void MusicDriver_ExtMidi::DoStop() { - if (_midi.pid != -1) kill(_midi.pid, SIGTERM); + if (this->pid != -1) kill(this->pid, SIGTERM); } #endif /* __MORPHOS__ */