summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-07-05 12:23:54 +0000
committerpeter1138 <peter1138@openttd.org>2007-07-05 12:23:54 +0000
commit5e85e8c5e03105e43cf9f2216e993c0596d7dfec (patch)
tree52e0cc5b1e4eb6cf9aed8556873ee6833662e11f /src/music
parent7884a07b43fd293a2ca5b39b64df98b700959874 (diff)
downloadopenttd-5e85e8c5e03105e43cf9f2216e993c0596d7dfec.tar.xz
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
Diffstat (limited to 'src/music')
-rw-r--r--src/music/bemidi.cpp23
-rw-r--r--src/music/bemidi.h26
-rw-r--r--src/music/dmusic.cpp21
-rw-r--r--src/music/dmusic.h26
-rw-r--r--src/music/extmidi.cpp23
-rw-r--r--src/music/extmidi.h26
-rw-r--r--src/music/libtimidity.cpp27
-rw-r--r--src/music/libtimidity.h26
-rw-r--r--src/music/music_driver.hpp35
-rw-r--r--src/music/null_m.cpp15
-rw-r--r--src/music/null_m.h26
-rw-r--r--src/music/os2_m.cpp23
-rw-r--r--src/music/os2_m.h26
-rw-r--r--src/music/qtmidi.cpp29
-rw-r--r--src/music/qtmidi.h26
-rw-r--r--src/music/win32_m.cpp23
-rw-r--r--src/music/win32_m.h26
17 files changed, 283 insertions, 144 deletions
diff --git a/src/music/bemidi.cpp b/src/music/bemidi.cpp
index 0cf500a50..ab5634cca 100644
--- a/src/music/bemidi.cpp
+++ b/src/music/bemidi.cpp
@@ -11,17 +11,19 @@
static BMidiSynthFile midiSynthFile;
-static const char *bemidi_start(const char * const *parm)
+static FMusicDriver_BeMidi iFMusicDriver_BeMidi;
+
+const char *MusicDriver_BeMidi::Start(const char * const *parm)
{
return NULL;
}
-static void bemidi_stop()
+void MusicDriver_BeMidi::Stop()
{
midiSynthFile.UnloadFile();
}
-static void bemidi_play_song(const char *filename)
+void MusicDriver_BeMidi::PlaySong(const char *filename)
{
bemidi_stop();
entry_ref midiRef;
@@ -30,26 +32,17 @@ static void bemidi_play_song(const char *filename)
midiSynthFile.Start();
}
-static void bemidi_stop_song()
+void MusicDriver_BeMidi::StopSong()
{
midiSynthFile.UnloadFile();
}
-static bool bemidi_is_playing()
+bool MusicDriver_BeMidi::IsSongPlaying()
{
return !midiSynthFile.IsFinished();
}
-static void bemidi_set_volume(byte vol)
+void MusicDriver_BeMidi::SetVolume(byte vol)
{
fprintf(stderr, "BeMidi: Set volume not implemented\n");
}
-
-const HalMusicDriver _bemidi_music_driver = {
- bemidi_start,
- bemidi_stop,
- bemidi_play_song,
- bemidi_stop_song,
- bemidi_is_playing,
- bemidi_set_volume,
-};
diff --git a/src/music/bemidi.h b/src/music/bemidi.h
index 1b3d4f3de..623d6398d 100644
--- a/src/music/bemidi.h
+++ b/src/music/bemidi.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_BEMIDI_H
#define MUSIC_BEMIDI_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _bemidi_music_driver;
+class MusicDriver_BeMidi: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_BeMidi: public MusicDriverFactory<FMusicDriver_BeMidi> {
+public:
+ /* virtual */ const char *GetName() { return "bemidi"; }
+ /* virtual */ const char *GetDescription() { return "BeOS MIDI Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_BeMidi(); }
+};
#endif /* MUSIC_BEMIDI_H */
diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp
index f0538c678..d9839cee9 100644
--- a/src/music/dmusic.cpp
+++ b/src/music/dmusic.cpp
@@ -47,7 +47,7 @@ struct ProcPtrs {
static ProcPtrs proc;
-static const char* DMusicMidiStart(const char* const* parm)
+const char *MusicDriver_DMusic::Start(const char * const *parm)
{
if (performance != NULL) return NULL;
@@ -109,7 +109,7 @@ static const char* DMusicMidiStart(const char* const* parm)
}
-static void DMusicMidiStop()
+void MusicDriver_DMusic::Stop()
{
seeking = false;
@@ -136,7 +136,7 @@ static void DMusicMidiStop()
}
-static void DMusicMidiPlaySong(const char* filename)
+void MusicDriver_DMusic::PlaySong(const char* filename)
{
/* set up the loader object info */
DMUS_OBJECTDESC obj_desc;
@@ -188,7 +188,7 @@ static void DMusicMidiPlaySong(const char* filename)
}
-static void DMusicMidiStopSong()
+void MusicDriver_DMusic::StopSong()
{
if (FAILED(performance->Stop(segment, NULL, 0, 0))) {
DEBUG(driver, 0, "DirectMusic: StopSegment failed");
@@ -197,7 +197,7 @@ static void DMusicMidiStopSong()
}
-static bool DMusicMidiIsSongPlaying()
+bool MusicDriver_DMusic::IsSongPlaying()
{
/* Not the nicest code, but there is a short delay before playing actually
* starts. OpenTTD makes no provision for this. */
@@ -210,20 +210,11 @@ static bool DMusicMidiIsSongPlaying()
}
-static void DMusicMidiSetVolume(byte vol)
+void MusicDriver_DMusic::SetVolume(byte vol)
{
long db = vol * 2000 / 127 - 2000; ///< 0 - 127 -> -2000 - 0
performance->SetGlobalParam(GUID_PerfMasterVolume, &db, sizeof(db));
}
-const HalMusicDriver _dmusic_midi_driver = {
- DMusicMidiStart,
- DMusicMidiStop,
- DMusicMidiPlaySong,
- DMusicMidiStopSong,
- DMusicMidiIsSongPlaying,
- DMusicMidiSetVolume,
-};
-
#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */
diff --git a/src/music/dmusic.h b/src/music/dmusic.h
index a01269e1d..9bfb1bb1c 100644
--- a/src/music/dmusic.h
+++ b/src/music/dmusic.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_DMUSIC_H
#define MUSIC_DMUSIC_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _dmusic_midi_driver;
+class MusicDriver_DMusic: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_DMusic: public MusicDriverFactory<FMusicDriver_DMusic> {
+public:
+ /* virtual */ const char *GetName() { return "dmusic"; }
+ /* virtual */ const char *GetDescription() { return "DirectMusic MIDI Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_DMusic(); }
+};
#endif /* MUSIC_DMUSIC_H */
diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp
index 4c2f2f1e2..063b2cef6 100644
--- a/src/music/extmidi.cpp
+++ b/src/music/extmidi.cpp
@@ -24,32 +24,34 @@ static struct {
static void DoPlay();
static void DoStop();
-static const char* ExtMidiStart(const char* const * parm)
+static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
+
+const char* MusicDriver_ExtMidi::Start(const char* const * parm)
{
_midi.song[0] = '\0';
_midi.pid = -1;
return NULL;
}
-static void ExtMidiStop()
+void MusicDriver_ExtMidi::Stop()
{
_midi.song[0] = '\0';
DoStop();
}
-static void ExtMidiPlaySong(const char* filename)
+void MusicDriver_ExtMidi::PlaySong(const char* filename)
{
ttd_strlcpy(_midi.song, filename, lengthof(_midi.song));
DoStop();
}
-static void ExtMidiStopSong()
+void MusicDriver_ExtMidi::StopSong()
{
_midi.song[0] = '\0';
DoStop();
}
-static bool ExtMidiIsPlaying()
+bool MusicDriver_ExtMidi::IsSongPlaying()
{
if (_midi.pid != -1 && waitpid(_midi.pid, NULL, WNOHANG) == _midi.pid)
_midi.pid = -1;
@@ -57,7 +59,7 @@ static bool ExtMidiIsPlaying()
return _midi.pid != -1;
}
-static void ExtMidiSetVolume(byte vol)
+void MusicDriver_ExtMidi::SetVolume(byte vol)
{
DEBUG(driver, 1, "extmidi: set volume not implemented");
}
@@ -96,13 +98,4 @@ static void DoStop()
if (_midi.pid != -1) kill(_midi.pid, SIGTERM);
}
-const HalMusicDriver _extmidi_music_driver = {
- ExtMidiStart,
- ExtMidiStop,
- ExtMidiPlaySong,
- ExtMidiStopSong,
- ExtMidiIsPlaying,
- ExtMidiSetVolume,
-};
-
#endif /* __MORPHOS__ */
diff --git a/src/music/extmidi.h b/src/music/extmidi.h
index f118f933a..df1472d34 100644
--- a/src/music/extmidi.h
+++ b/src/music/extmidi.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_EXTERNAL_H
#define MUSIC_EXTERNAL_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _extmidi_music_driver;
+class MusicDriver_ExtMidi: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_ExtMidi: public MusicDriverFactory<FMusicDriver_ExtMidi> {
+public:
+ /* virtual */ const char *GetName() { return "extmidi"; }
+ /* virtual */ const char *GetDescription() { return "External MIDI Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_ExtMidi(); }
+};
#endif /* MUSIC_EXTERNAL_H */
diff --git a/src/music/libtimidity.cpp b/src/music/libtimidity.cpp
index f25b0bfff..5368bbd68 100644
--- a/src/music/libtimidity.cpp
+++ b/src/music/libtimidity.cpp
@@ -44,7 +44,9 @@ static void AudioOutCallback(void *buf, unsigned int _reqn, void *userdata)
}
#endif /* PSP */
-static const char *LibtimidityMidiStart(const char *const *param)
+static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity;
+
+const char *MusicDriver_LibTimidity::Start(const char *const *param)
{
_midi.status = MIDI_STOPPED;
@@ -53,8 +55,7 @@ static const char *LibtimidityMidiStart(const char *const *param)
* If it was not forced via param, try to load it without a
* configuration. Who knows that works. */
if (param != NULL || mid_init_no_config() < 0) {
- DEBUG(driver, 0, "error initializing timidity");
- return NULL;
+ return "error initializing timidity";
}
}
DEBUG(driver, 1, "successfully initialised timidity");
@@ -77,7 +78,7 @@ static const char *LibtimidityMidiStart(const char *const *param)
return NULL;
}
-static void LibtimidityMidiStop()
+void MusicDriver_LibTimidity::Stop()
{
if (_midi.status == MIDI_PLAYING) {
_midi.status = MIDI_STOPPED;
@@ -86,7 +87,7 @@ static void LibtimidityMidiStop()
mid_exit();
}
-static void LibtimidityMidiPlaySong(const char *filename)
+void MusicDriver_LibTimidity::PlaySong(const char *filename)
{
_midi.stream = mid_istream_open_file(filename);
if (_midi.stream == NULL) {
@@ -107,13 +108,13 @@ static void LibtimidityMidiPlaySong(const char *filename)
_midi.status = MIDI_PLAYING;
}
-static void LibtimidityMidiStopSong()
+void MusicDriver_LibTimidity::StopSong()
{
_midi.status = MIDI_STOPPED;
mid_song_free(_midi.song);
}
-static bool LibtimidityMidiIsPlaying()
+bool MusicDriver_LibTimidity::IsSongPlaying()
{
if (_midi.status == MIDI_PLAYING) {
_midi.song_position = mid_song_get_time(_midi.song);
@@ -126,18 +127,8 @@ static bool LibtimidityMidiIsPlaying()
return (_midi.status == MIDI_PLAYING);
}
-static void LibtimidityMidiSetVolume(byte vol)
+void MusicDriver_LibTimidity::SetVolume(byte vol)
{
if (_midi.song != NULL)
mid_song_set_volume(_midi.song, vol);
}
-
-const HalMusicDriver _libtimidity_music_driver = {
- LibtimidityMidiStart,
- LibtimidityMidiStop,
- LibtimidityMidiPlaySong,
- LibtimidityMidiStopSong,
- LibtimidityMidiIsPlaying,
- LibtimidityMidiSetVolume,
-};
-
diff --git a/src/music/libtimidity.h b/src/music/libtimidity.h
index df8b7de1c..2915841f7 100644
--- a/src/music/libtimidity.h
+++ b/src/music/libtimidity.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_LIBTIMIDITY_H
#define MUSIC_LIBTIMIDITY_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _libtimidity_music_driver;
+class MusicDriver_LibTimidity: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_LibTimidity: public MusicDriverFactory<FMusicDriver_LibTimidity> {
+public:
+ /* virtual */ const char *GetName() { return "libtimidity"; }
+ /* virtual */ const char *GetDescription() { return "LibTimidity MIDI Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_LibTimidity(); }
+};
#endif /* MUSIC_LIBTIMIDITY_H */
diff --git a/src/music/music_driver.hpp b/src/music/music_driver.hpp
new file mode 100644
index 000000000..b4486ef94
--- /dev/null
+++ b/src/music/music_driver.hpp
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+#ifndef MUSIC_MUSIC_DRIVER_HPP
+#define MUSIC_MUSIC_DRIVER_HPP
+
+#include "../driver.h"
+
+class MusicDriver: public Driver {
+public:
+ virtual void PlaySong(const char *filename) = 0;
+
+ virtual void StopSong() = 0;
+
+ virtual bool IsSongPlaying() = 0;
+
+ virtual void SetVolume(byte vol) = 0;
+};
+
+class MusicDriverFactoryBase: public DriverFactoryBase {
+};
+
+template <class T>
+class MusicDriverFactory: public MusicDriverFactoryBase {
+public:
+ MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC); }
+
+ /**
+ * Get the long, human readable, name for the Driver-class.
+ */
+ const char *GetName();
+};
+
+extern MusicDriver *_music_driver;
+
+#endif /* MUSIC_MUSIC_DRIVER_HPP */
diff --git a/src/music/null_m.cpp b/src/music/null_m.cpp
index 01f7a401e..063ad2e10 100644
--- a/src/music/null_m.cpp
+++ b/src/music/null_m.cpp
@@ -3,18 +3,5 @@
#include "../stdafx.h"
#include "null_m.h"
-static const char* NullMidiStart(const char* const* parm) { return NULL; }
-static void NullMidiStop() {}
-static void NullMidiPlaySong(const char *filename) {}
-static void NullMidiStopSong() {}
-static bool NullMidiIsSongPlaying() { return true; }
-static void NullMidiSetVolume(byte vol) {}
+static FMusicDriver_Null iFMusicDriver_Null;
-const HalMusicDriver _null_music_driver = {
- NullMidiStart,
- NullMidiStop,
- NullMidiPlaySong,
- NullMidiStopSong,
- NullMidiIsSongPlaying,
- NullMidiSetVolume,
-};
diff --git a/src/music/null_m.h b/src/music/null_m.h
index d6edfb71d..2b7be7581 100644
--- a/src/music/null_m.h
+++ b/src/music/null_m.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_NULL_H
#define MUSIC_NULL_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _null_music_driver;
+class MusicDriver_Null: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return false; }
+
+ /* virtual */ const char *Start(const char * const *param) { return NULL; }
+
+ /* virtual */ void Stop() { }
+
+ /* virtual */ void PlaySong(const char *filename) { }
+
+ /* virtual */ void StopSong() { }
+
+ /* virtual */ bool IsSongPlaying() { return true; }
+
+ /* virtual */ void SetVolume(byte vol) { }
+};
+
+class FMusicDriver_Null: public MusicDriverFactory<FMusicDriver_Null> {
+public:
+ /* virtual */ const char *GetName() { return "null"; }
+ /* virtual */ const char *GetDescription() { return "Null Music Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_Null(); }
+};
#endif /* MUSIC_NULL_H */
diff --git a/src/music/os2_m.cpp b/src/music/os2_m.cpp
index c067e8d53..04add6e95 100644
--- a/src/music/os2_m.cpp
+++ b/src/music/os2_m.cpp
@@ -30,7 +30,9 @@ static long CDECL MidiSendCommand(const char *cmd, ...)
return mciSendString(buf, NULL, 0, NULL, 0);
}
-static void OS2MidiPlaySong(const char *filename)
+static FMusicDriver_OS2 iFMusicDriver_OS2;
+
+void MusicDriver_OS2::PlaySong(const char *filename)
{
MidiSendCommand("close all");
@@ -40,38 +42,29 @@ static void OS2MidiPlaySong(const char *filename)
MidiSendCommand("play song from 0");
}
-static void OS2MidiStopSong()
+void MusicDriver_OS2::StopSong()
{
MidiSendCommand("close all");
}
-static void OS2MidiSetVolume(byte vol)
+void MusicDriver_OS2::SetVolume(byte vol)
{
MidiSendCommand("set song audio volume %d", ((vol/127)*100));
}
-static bool OS2MidiIsSongPlaying()
+bool MusicDriver_OS2::IsSongPlaying()
{
char buf[16];
mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
}
-static const char *OS2MidiStart(const char * const *parm)
+const char *MusicDriver_OS2::Start(const char * const *parm)
{
return 0;
}
-static void OS2MidiStop()
+void MusicDriver_OS2::Stop()
{
MidiSendCommand("close all");
}
-
-const HalMusicDriver _os2_music_driver = {
- OS2MidiStart,
- OS2MidiStop,
- OS2MidiPlaySong,
- OS2MidiStopSong,
- OS2MidiIsSongPlaying,
- OS2MidiSetVolume,
-};
diff --git a/src/music/os2_m.h b/src/music/os2_m.h
index fef15b91f..b0f4d71ce 100644
--- a/src/music/os2_m.h
+++ b/src/music/os2_m.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_OS2_H
#define MUSIC_OS2_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _os2_music_driver;
+class MusicDriver_OS2: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_OS2: public MusicDriverFactory<FMusicDriver_OS2> {
+public:
+ /* virtual */ const char *GetName() { return "os2"; }
+ /* virtual */ const char *GetDescription() { return "OS/2 Music Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_OS2(); }
+};
#endif /* MUSIC_OS2_H */
diff --git a/src/music/qtmidi.cpp b/src/music/qtmidi.cpp
index c36dbcddc..cad83d59e 100644
--- a/src/music/qtmidi.cpp
+++ b/src/music/qtmidi.cpp
@@ -47,6 +47,8 @@
// we need to include debug.h after CoreServices because defining DEBUG will break CoreServices in OSX 10.2
#include "../debug.h"
+static FMusicDriver_QtMidi iFMusicDriver_QtMidi;
+
enum {
midiType = 'Midi' /**< OSType code for MIDI songs. */
@@ -207,9 +209,6 @@ static int _quicktime_state = QT_STATE_IDLE; /**< Current player state. */
#define VOLUME ((short)((0x00FF & _quicktime_volume) << 1))
-static void StopSong();
-
-
/**
* Initialized the MIDI player, including QuickTime initialization.
*
@@ -217,7 +216,7 @@ static void StopSong();
* @c Gestalt() and @c EnterMovies(). Needs changes in
* #InitQuickTimeIfNeeded.
*/
-static const char* StartDriver(const char * const *parm)
+const char *MusicDriver_QtMidi::Start(const char * const *parm)
{
InitQuickTimeIfNeeded();
return (_quicktime_started) ? NULL : "can't initialize QuickTime";
@@ -230,7 +229,7 @@ static const char* StartDriver(const char * const *parm)
* This function is called at regular intervals from OpenTTD's main loop, so
* we call @c MoviesTask() from here to let QuickTime do its work.
*/
-static bool SongIsPlaying()
+bool MusicDriver_QtMidi::IsSongPlaying()
{
if (!_quicktime_started) return true;
@@ -258,7 +257,7 @@ static bool SongIsPlaying()
* Stops playing and frees any used resources before returning. As it
* deinitilizes QuickTime, the #_quicktime_started flag is set to @c false.
*/
-static void StopDriver()
+void MusicDriver_QtMidi::Stop()
{
if (!_quicktime_started) return;
@@ -284,7 +283,7 @@ static void StopDriver()
*
* @param filename Path to a MIDI file.
*/
-static void PlaySong(const char *filename)
+void MusicDriver_QtMidi::PlaySong(const char *filename)
{
if (!_quicktime_started) return;
@@ -312,7 +311,7 @@ static void PlaySong(const char *filename)
/**
* Stops playing the current song, if the player is active.
*/
-static void StopSong()
+void MusicDriver_QtMidi::StopSong()
{
if (!_quicktime_started) return;
@@ -340,7 +339,7 @@ static void StopSong()
*
* @param vol The desired volume, range of the value is @c 0-127
*/
-static void SetVolume(byte vol)
+void MusicDriver_QtMidi::SetVolume(byte vol)
{
if (!_quicktime_started) return;
@@ -357,15 +356,3 @@ static void SetVolume(byte vol)
}
}
-
-/**
- * Table of callbacks that implement the QuickTime MIDI player.
- */
-const HalMusicDriver _qtime_music_driver = {
- StartDriver,
- StopDriver,
- PlaySong,
- StopSong,
- SongIsPlaying,
- SetVolume,
-};
diff --git a/src/music/qtmidi.h b/src/music/qtmidi.h
index 0b9e5ff2e..7ffa02fe0 100644
--- a/src/music/qtmidi.h
+++ b/src/music/qtmidi.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_MACOSX_QUICKTIME_H
#define MUSIC_MACOSX_QUICKTIME_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _qtime_music_driver;
+class MusicDriver_QtMidi: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_QtMidi: public MusicDriverFactory<FMusicDriver_QtMidi> {
+public:
+ /* virtual */ const char *GetName() { return "qt"; }
+ /* virtual */ const char *GetDescription() { return "QuickTime MIDI Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_QtMidi(); }
+};
#endif /* MUSIC_MACOSX_QUICKTIME_H */
diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp
index 7ec9a945e..470572254 100644
--- a/src/music/win32_m.cpp
+++ b/src/music/win32_m.cpp
@@ -15,7 +15,9 @@ static struct {
char start_song[260];
} _midi;
-static void Win32MidiPlaySong(const char *filename)
+static FMusicDriver_Win32 iFMusicDriver_Win32;
+
+void MusicDriver_Win32::PlaySong(const char *filename)
{
strcpy(_midi.start_song, filename);
_midi.playing = true;
@@ -23,7 +25,7 @@ static void Win32MidiPlaySong(const char *filename)
SetEvent(_midi.wait_obj);
}
-static void Win32MidiStopSong()
+void MusicDriver_Win32::StopSong()
{
if (_midi.playing) {
_midi.stop_song = true;
@@ -32,12 +34,12 @@ static void Win32MidiStopSong()
}
}
-static bool Win32MidiIsSongPlaying()
+bool MusicDriver_Win32::IsSongPlaying()
{
return _midi.playing;
}
-static void Win32MidiSetVolume(byte vol)
+void MusicDriver_Win32::SetVolume(byte vol)
{
_midi.new_vol = vol;
SetEvent(_midi.wait_obj);
@@ -118,7 +120,7 @@ static DWORD WINAPI MidiThread(LPVOID arg)
return 0;
}
-static const char *Win32MidiStart(const char * const *parm)
+const char *MusicDriver_Win32::Start(const char * const *parm)
{
MIDIOUTCAPS midicaps;
DWORD threadId;
@@ -146,17 +148,8 @@ static const char *Win32MidiStart(const char * const *parm)
return NULL;
}
-static void Win32MidiStop()
+void MusicDriver_Win32::Stop()
{
_midi.terminate = true;
SetEvent(_midi.wait_obj);
}
-
-const HalMusicDriver _win32_music_driver = {
- Win32MidiStart,
- Win32MidiStop,
- Win32MidiPlaySong,
- Win32MidiStopSong,
- Win32MidiIsSongPlaying,
- Win32MidiSetVolume,
-};
diff --git a/src/music/win32_m.h b/src/music/win32_m.h
index 162be9d97..bef62bd66 100644
--- a/src/music/win32_m.h
+++ b/src/music/win32_m.h
@@ -3,8 +3,30 @@
#ifndef MUSIC_WIN32_H
#define MUSIC_WIN32_H
-#include "../hal.h"
+#include "music_driver.hpp"
-extern const HalMusicDriver _win32_music_driver;
+class MusicDriver_Win32: public MusicDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+
+ /* virtual */ void PlaySong(const char *filename);
+
+ /* virtual */ void StopSong();
+
+ /* virtual */ bool IsSongPlaying();
+
+ /* virtual */ void SetVolume(byte vol);
+};
+
+class FMusicDriver_Win32: public MusicDriverFactory<FMusicDriver_Win32> {
+public:
+ /* virtual */ const char *GetName() { return "win32"; }
+ /* virtual */ const char *GetDescription() { return "Win32 Music Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new MusicDriver_Win32(); }
+};
#endif /* MUSIC_WIN32_H */