summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-07-05 13:19:35 +0000
committerpeter1138 <peter1138@openttd.org>2007-07-05 13:19:35 +0000
commitb9534939303c9b76438a538b37c90dddfbe0e225 (patch)
tree77cee89452dfa24654ffe876d0b53ed59ba2b673 /src
parentc4aff8b0a4c8ef184eeed18a700b3222fe7003c6 (diff)
downloadopenttd-b9534939303c9b76438a538b37c90dddfbe0e225.tar.xz
(svn r10446) -Codechange: Move extmidi's global data into its class.
Diffstat (limited to 'src')
-rw-r--r--src/music/extmidi.cpp48
-rw-r--r--src/music/extmidi.h7
2 files changed, 27 insertions, 28 deletions
diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp
index 063b2cef6..fdc9923f0 100644
--- 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 @@ void MusicDriver_ExtMidi::SetVolume(byte vol)
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 @@ static void DoPlay()
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 @@ static void DoPlay()
/* 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__ */
diff --git a/src/music/extmidi.h b/src/music/extmidi.h
index df1472d34..4f62641b4 100644
--- a/src/music/extmidi.h
+++ b/src/music/extmidi.h
@@ -6,6 +6,13 @@
#include "music_driver.hpp"
class MusicDriver_ExtMidi: public MusicDriver {
+private:
+ char song[MAX_PATH];
+ pid_t pid;
+
+ void DoPlay();
+ void DoStop();
+
public:
/* virtual */ bool CanProbe() { return true; }