aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/mididrv.cpp2
-rw-r--r--sound/mididrv.h2
-rw-r--r--sound/midiplugin.h31
-rw-r--r--sound/null.cpp44
-rw-r--r--sound/softsynth/adlib.cpp46
-rw-r--r--sound/softsynth/fluidsynth.cpp46
-rw-r--r--sound/softsynth/mt32.cpp45
-rw-r--r--sound/softsynth/ym2612.cpp43
8 files changed, 234 insertions, 25 deletions
diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp
index 52cf5d0e65..358d42d751 100644
--- a/sound/mididrv.cpp
+++ b/sound/mididrv.cpp
@@ -216,7 +216,7 @@ int MidiDriver::detectMusicDriver(int flags) {
MidiDriver *MidiDriver::createMidi(int midiDriver) {
switch (midiDriver) {
- case MD_NULL: return MidiDriver_NULL_create();
+ case MD_NULL: return MidiDriver_NULL_create(g_system->getMixer());
case MD_ADLIB: return MidiDriver_ADLIB_create(g_system->getMixer());
diff --git a/sound/mididrv.h b/sound/mididrv.h
index 77b10518bc..12513268a8 100644
--- a/sound/mididrv.h
+++ b/sound/mididrv.h
@@ -268,7 +268,7 @@ public:
// Factory functions, for faster compile
-extern MidiDriver *MidiDriver_NULL_create();
+extern MidiDriver *MidiDriver_NULL_create(Audio::Mixer *mixer);
extern MidiDriver *MidiDriver_ADLIB_create(Audio::Mixer *mixer);
extern MidiDriver *MidiDriver_WIN_create(Audio::Mixer *mixer);
extern MidiDriver *MidiDriver_SEQ_create(Audio::Mixer *mixer);
diff --git a/sound/midiplugin.h b/sound/midiplugin.h
index f36aa2c822..c3b407a142 100644
--- a/sound/midiplugin.h
+++ b/sound/midiplugin.h
@@ -37,6 +37,18 @@ public:
virtual ~MidiPluginObject() {}
/**
+ * Returns a unique string identifier which will be used to save the
+ * selected MIDI driver to the config file.
+ */
+ virtual const char *getId() const = 0;
+
+ /**
+ * Returns the type kind of music supported by this driver, as specified
+ * by the MidiDriverFlags enum.
+ */
+ virtual int getCapabilities() const = 0;
+
+ /**
* Returns a list of the available devices. The empty string means the
* default device.
*/
@@ -59,4 +71,23 @@ public:
virtual PluginError createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const = 0;
};
+
+// MIDI plugins
+
+typedef PluginSubclass<MidiPluginObject> MidiPlugin;
+
+/**
+ * Singleton class which manages all MIDI plugins.
+ */
+class MidiManager : public Common::Singleton<MidiManager> {
+private:
+ friend class Common::Singleton<SingletonBaseType>;
+
+public:
+ const MidiPlugin::list &getPlugins() const;
+};
+
+/** Convenience shortcut for accessing the MIDI manager. */
+#define MidiMan MidiManager::instance()
+
#endif
diff --git a/sound/null.cpp b/sound/null.cpp
index 49c57052f9..9bb3a76344 100644
--- a/sound/null.cpp
+++ b/sound/null.cpp
@@ -22,6 +22,7 @@
* $Id$
*/
+#include "sound/midiplugin.h"
#include "sound/mpu401.h"
/* NULL driver */
@@ -31,12 +32,49 @@ public:
void send(uint32 b) { }
};
-MidiDriver *MidiDriver_NULL_create() {
- return new MidiDriver_NULL();
+
+// Plugin interface
+
+class NullMidiPlugin : public MidiPluginObject {
+public:
+ virtual const char *getName() const {
+ return "No music";
+ }
+
+ virtual const char *getId() const {
+ return "null";
+ }
+
+ virtual int getCapabilities() const {
+ return MDT_MIDI | MDT_PCSPK | MDT_ADLIB | MDT_TOWNS;
+ }
+
+ virtual PluginError createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const;
+};
+
+PluginError NullMidiPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
+ *mididriver = new MidiDriver_NULL();
+
+ return kNoError;
+}
+
+MidiDriver *MidiDriver_NULL_create(Audio::Mixer *mixer) {
+ MidiDriver *mididriver;
+
+ NullMidiPlugin p;
+ p.createInstance(mixer, &mididriver);
+
+ return mididriver;
}
#ifdef DISABLE_ADLIB
MidiDriver *MidiDriver_ADLIB_create(Audio::Mixer *mixer) {
- return new MidiDriver_NULL();
+ return MidiDriver_NULL_create(mixer);
}
#endif
+
+//#if PLUGIN_ENABLED_DYNAMIC(NULL)
+ //REGISTER_PLUGIN_DYNAMIC(NULL, PLUGIN_TYPE_MIDI, NullMidiPlugin);
+//#else
+ REGISTER_PLUGIN_STATIC(NULL, PLUGIN_TYPE_MIDI, NullMidiPlugin);
+//#endif
diff --git a/sound/softsynth/adlib.cpp b/sound/softsynth/adlib.cpp
index 1cf4c2b179..3936843f52 100644
--- a/sound/softsynth/adlib.cpp
+++ b/sound/softsynth/adlib.cpp
@@ -25,6 +25,7 @@
#include "sound/softsynth/emumidi.h"
#include "common/util.h"
#include "sound/fmopl.h"
+#include "sound/midiplugin.h"
#ifdef DEBUG_ADLIB
static int tick;
@@ -970,10 +971,6 @@ MidiChannel *MidiDriver_ADLIB::allocateChannel() {
return NULL;
}
-MidiDriver *MidiDriver_ADLIB_create(Audio::Mixer *mixer) {
- return new MidiDriver_ADLIB(mixer);
-}
-
// All the code brought over from IMuseAdlib
void MidiDriver_ADLIB::adlib_write(byte port, byte value) {
@@ -1517,3 +1514,44 @@ void MidiDriver_ADLIB::adlib_note_on(int chan, byte note, int mod) {
curnote_table[chan] = code;
adlib_playnote(chan, (int16) channel_table_2[chan] + code);
}
+
+
+// Plugin interface
+
+class AdlibMidiPlugin : public MidiPluginObject {
+public:
+ virtual const char *getName() const {
+ return "AdLib Emulator";
+ }
+
+ virtual const char *getId() const {
+ return "adlib";
+ }
+
+ virtual int getCapabilities() const {
+ return MDT_ADLIB;
+ }
+
+ virtual PluginError createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const;
+};
+
+PluginError AdlibMidiPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
+ *mididriver = new MidiDriver_ADLIB(mixer);
+
+ return kNoError;
+}
+
+MidiDriver *MidiDriver_ADLIB_create(Audio::Mixer *mixer) {
+ MidiDriver *mididriver;
+
+ AdlibMidiPlugin p;
+ p.createInstance(mixer, &mididriver);
+
+ return mididriver;
+}
+
+//#if PLUGIN_ENABLED_DYNAMIC(ADLIB)
+ //REGISTER_PLUGIN_DYNAMIC(ADLIB, PLUGIN_TYPE_MIDI, AdlibMidiPlugin);
+//#else
+ REGISTER_PLUGIN_STATIC(ADLIB, PLUGIN_TYPE_MIDI, AdlibMidiPlugin);
+//#endif
diff --git a/sound/softsynth/fluidsynth.cpp b/sound/softsynth/fluidsynth.cpp
index 4a61cd023b..ae89a8df8a 100644
--- a/sound/softsynth/fluidsynth.cpp
+++ b/sound/softsynth/fluidsynth.cpp
@@ -27,6 +27,7 @@
#ifdef USE_FLUIDSYNTH
#include "common/config-manager.h"
+#include "sound/midiplugin.h"
#include "sound/mpu401.h"
#include "sound/softsynth/emumidi.h"
@@ -211,12 +212,49 @@ MidiChannel *MidiDriver_FluidSynth::getPercussionChannel() {
return &_midiChannels[9];
}
-MidiDriver *MidiDriver_FluidSynth_create(Audio::Mixer *mixer) {
- return new MidiDriver_FluidSynth(mixer);
-}
-
void MidiDriver_FluidSynth::generateSamples(int16 *data, int len) {
fluid_synth_write_s16(_synth, len, data, 0, 2, data, 1, 2);
}
+
+// Plugin interface
+
+class FluidSynthMidiPlugin : public MidiPluginObject {
+public:
+ virtual const char *getName() const {
+ return "FluidSynth";
+ }
+
+ virtual const char *getId() const {
+ return "fluidsynth";
+ }
+
+ virtual int getCapabilities() const {
+ return MDT_MIDI;
+ }
+
+ virtual PluginError createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const;
+};
+
+PluginError FluidSynthMidiPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
+ *mididriver = new MidiDriver_FluidSynth(mixer);
+
+ return kNoError;
+}
+
+MidiDriver *MidiDriver_FluidSynth_create(Audio::Mixer *mixer) {
+ MidiDriver *mididriver;
+
+ FluidSynthMidiPlugin p;
+ p.createInstance(mixer, &mididriver);
+
+ return mididriver;
+}
+
+//#if PLUGIN_ENABLED_DYNAMIC(FLUIDSYNTH)
+ //REGISTER_PLUGIN_DYNAMIC(FLUIDSYNTH, PLUGIN_TYPE_MIDI, FluidSynthMidiPlugin);
+//#else
+ REGISTER_PLUGIN_STATIC(FLUIDSYNTH, PLUGIN_TYPE_MIDI, FluidSynthMidiPlugin);
+//#endif
+
#endif
diff --git a/sound/softsynth/mt32.cpp b/sound/softsynth/mt32.cpp
index 706db826af..2c9c4f24be 100644
--- a/sound/softsynth/mt32.cpp
+++ b/sound/softsynth/mt32.cpp
@@ -29,6 +29,7 @@
#include "sound/softsynth/mt32/mt32emu.h"
#include "sound/softsynth/emumidi.h"
+#include "sound/midiplugin.h"
#include "sound/mpu401.h"
#include "common/config-manager.h"
@@ -479,17 +480,49 @@ void MidiDriver_ThreadedMT32::onTimer() {
}
#endif
-////////////////////////////////////////
-//
-// MidiDriver_MT32 factory
-//
-////////////////////////////////////////
+
+// Plugin interface
+
+class MT32MidiPlugin : public MidiPluginObject {
+public:
+ virtual const char *getName() const {
+ return "MT-32 Emulator";
+ }
+
+ virtual const char *getId() const {
+ return "mt32";
+ }
+
+ virtual int getCapabilities() const {
+ return MDT_MIDI;
+ }
+
+ virtual PluginError createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const;
+};
+
+PluginError MT32MidiPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
+ *mididriver = new MidiDriver_MT32(mixer);
+
+ return kNoError;
+}
MidiDriver *MidiDriver_MT32_create(Audio::Mixer *mixer) {
// HACK: It will stay here until engine plugin loader overhaul
if (ConfMan.hasKey("extrapath"))
Common::File::addDefaultDirectory(ConfMan.get("extrapath"));
- return new MidiDriver_MT32(mixer);
+
+ MidiDriver *mididriver;
+
+ MT32MidiPlugin p;
+ p.createInstance(mixer, &mididriver);
+
+ return mididriver;
}
+//#if PLUGIN_ENABLED_DYNAMIC(MT32)
+ //REGISTER_PLUGIN_DYNAMIC(MT32, PLUGIN_TYPE_MIDI, MT32MidiPlugin);
+//#else
+ REGISTER_PLUGIN_STATIC(MT32, PLUGIN_TYPE_MIDI, MT32MidiPlugin);
+//#endif
+
#endif
diff --git a/sound/softsynth/ym2612.cpp b/sound/softsynth/ym2612.cpp
index 1e985aeb1c..3fcc2c3fc4 100644
--- a/sound/softsynth/ym2612.cpp
+++ b/sound/softsynth/ym2612.cpp
@@ -26,6 +26,7 @@
#include "sound/softsynth/ym2612.h"
#include "common/util.h"
+#include "sound/midiplugin.h"
////////////////////////////////////////
//
@@ -751,13 +752,43 @@ void MidiDriver_YM2612::removeLookupTables() {
sintbl = powtbl = frequencyTable = keycodeTable = keyscaleTable = attackOut = 0;
}
-////////////////////////////////////////
-//
-// MidiDriver_YM2612 factory
-//
-////////////////////////////////////////
+
+// Plugin interface
+
+class TownsMidiPlugin : public MidiPluginObject {
+public:
+ virtual const char *getName() const {
+ return "FM Towns Emulator";
+ }
+
+ virtual const char *getId() const {
+ return "towns";
+ }
+
+ virtual int getCapabilities() const {
+ return MDT_TOWNS;
+ }
+
+ virtual PluginError createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const;
+};
+
+PluginError TownsMidiPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
+ *mididriver = new MidiDriver_YM2612(mixer);
+
+ return kNoError;
+}
MidiDriver *MidiDriver_YM2612_create(Audio::Mixer *mixer) {
- return new MidiDriver_YM2612(mixer);
+ MidiDriver *mididriver;
+
+ TownsMidiPlugin p;
+ p.createInstance(mixer, &mididriver);
+
+ return mididriver;
}
+//#if PLUGIN_ENABLED_DYNAMIC(TOWNS)
+ //REGISTER_PLUGIN_DYNAMIC(TOWNS, PLUGIN_TYPE_MIDI, TownsMidiPlugin);
+//#else
+ REGISTER_PLUGIN_STATIC(TOWNS, PLUGIN_TYPE_MIDI, TownsMidiPlugin);
+//#endif