aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/mididrv.cpp393
-rw-r--r--sound/mididrv.h131
-rw-r--r--sound/musicplugin.cpp22
-rw-r--r--sound/musicplugin.h32
-rw-r--r--sound/null.cpp39
-rw-r--r--sound/softsynth/adlib.cpp16
-rw-r--r--sound/softsynth/fluidsynth.cpp13
-rw-r--r--sound/softsynth/mt32.cpp23
-rw-r--r--sound/softsynth/ym2612.cpp16
9 files changed, 281 insertions, 404 deletions
diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp
index c6e208ae47..51abed3aa1 100644
--- a/sound/mididrv.cpp
+++ b/sound/mididrv.cpp
@@ -27,96 +27,10 @@
#include "common/config-manager.h"
#include "common/str.h"
#include "common/system.h"
-#include "common/translation.h"
#include "common/util.h"
#include "sound/mididrv.h"
-
-static const uint32 GUIOMapping[] = {
- MDT_PCSPK, Common::GUIO_MIDIPCSPK,
- MDT_CMS, Common::GUIO_MIDICMS,
- MDT_PCJR, Common::GUIO_MIDIPCJR,
- MDT_ADLIB, Common::GUIO_MIDIADLIB,
- MDT_TOWNS, Common::GUIO_MIDITOWNS,
- MDT_MIDI, Common::GUIO_MIDI,
- 0, 0
-};
-
-uint32 MidiDriver::midiDriverFlags2GUIO(uint32 flags) {
- uint32 res = 0;
-
- for (int i = 0; GUIOMapping[i] || GUIOMapping[i + 1]; i += 2) {
- if (flags & GUIOMapping[i])
- res |= GUIOMapping[i + 1];
- }
-
- return res;
-}
-
-/** Internal list of all available 'midi' drivers. */
-static const MidiDriverDescription s_musicDrivers[] = {
-
- // The flags for the "auto" & "null" drivers indicate that they are anything
- // you want it to be.
- {"auto", _s("<default>"), MD_AUTO, MDT_MIDI | MDT_PCSPK | MDT_ADLIB | MDT_TOWNS},
- {"null", _s("No music"), MD_NULL, MDT_MIDI | MDT_PCSPK | MDT_ADLIB | MDT_TOWNS},
-
-#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
- {"windows", _s("Windows MIDI"), MD_WINDOWS, MDT_MIDI},
-#endif
-
-#if defined(UNIX) && defined(USE_ALSA)
- {"alsa", _s("ALSA"), MD_ALSA, MDT_MIDI},
-#endif
-
-#if defined(__MINT__)
- {"stmidi", _s("Atari ST MIDI"), MD_STMIDI, MDT_MIDI},
-#endif
-
-#if defined(UNIX) && !defined(__BEOS__) && !defined(MACOSX) && !defined(__MAEMO__) && !defined(__MINT__)
- {"seq", _s("SEQ"), MD_SEQ, MDT_MIDI},
-#endif
-
-#if defined(IRIX)
- {"dmedia", _s("DMedia"), MD_DMEDIA, MDT_MIDI},
-#endif
-
-#if defined(__amigaos4__)
- {"camd", _s("CAMD"), MD_CAMD, MDT_MIDI},
-#endif
-
-#if defined(MACOSX)
- {"core", _s("CoreAudio"), MD_COREAUDIO, MDT_MIDI},
-// {"coreaudio", "CoreAudio", MD_COREAUDIO, MDT_MIDI},
- {"coremidi", _s("CoreMIDI"), MD_COREMIDI, MDT_MIDI},
-#endif
-
-#if defined(PALMOS_MODE)
-# if defined(COMPILE_CLIE)
- {"ypa1", _s("Yamaha Pa1"), MD_YPA1, MDT_MIDI},
-# elif defined(COMPILE_ZODIAC) && (!defined(ENABLE_SCUMM) || !defined(PALMOS_ARM))
- {"zodiac", _s("Tapwave Zodiac"), MD_ZODIAC, MDT_MIDI},
-# endif
-#endif
-
-#ifdef USE_FLUIDSYNTH
- {"fluidsynth", _s("FluidSynth"), MD_FLUIDSYNTH, MDT_MIDI},
-#endif
-#ifdef USE_MT32EMU
- {"mt32", _s("MT-32 Emulation"), MD_MT32, MDT_MIDI},
-#endif
-
- // The flags for the "adlib" driver indicates that it can do AdLib and MIDI.
- {"adlib", _s("AdLib"), MD_ADLIB, MDT_ADLIB},
- {"pcspk", _s("PC Speaker"), MD_PCSPK, MDT_PCSPK},
- {"pcjr", _s("IBM PCjr"), MD_PCJR, MDT_PCSPK | MDT_PCJR},
- {"cms", _s("Creative Music System"), MD_CMS, MDT_CMS},
- {"towns", _s("FM Towns"), MD_TOWNS, MDT_TOWNS},
-#if defined(UNIX)
- {"timidity", _s("TiMidity"), MD_TIMIDITY, MDT_MIDI},
-#endif
-
- {0, 0, MD_NULL, MDT_NONE}
-};
+#include "sound/musicplugin.h"
+#include "common/translation.h"
const byte MidiDriver::_mt32ToGm[128] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
@@ -142,169 +56,190 @@ const byte MidiDriver::_gmToMt32[128] = {
101, 103, 100, 120, 117, 113, 99, 128, 128, 128, 128, 124, 123, 128, 128, 128, // 7x
};
-const MidiDriverDescription *MidiDriver::getAvailableMidiDrivers() {
- return s_musicDrivers;
-}
+static const uint32 GUIOMapping[] = {
+ MT_PCSPK, Common::GUIO_MIDIPCSPK,
+ /*MDT_CMS, Common::GUIO_MIDICMS,*/
+ MT_PCJR, Common::GUIO_MIDIPCJR,
+ MT_ADLIB, Common::GUIO_MIDIADLIB,
+ MT_TOWNS, Common::GUIO_MIDITOWNS,
+ MT_GM, Common::GUIO_MIDIGM,
+ MT_MT32, Common::GUIO_MIDIMT32,
+ 0, 0
+};
+
+uint32 MidiDriver::musicType2GUIO(uint32 musicType) {
+ uint32 res = 0;
-const MidiDriverDescription *MidiDriver::findMusicDriver(const Common::String &str) {
- if (str.empty())
- return 0;
+ for (int i = 0; GUIOMapping[i] || GUIOMapping[i + 1]; i += 2) {
+ if (musicType == GUIOMapping[i] || musicType == (uint32)-1)
+ res |= GUIOMapping[i + 1];
+ }
- const char *s = str.c_str();
- int len = 0;
- const MidiDriverDescription *md = s_musicDrivers;
+ return res;
+}
- // Scan for string end or a colon
- while (s[len] != 0 && s[len] != ':')
- len++;
+bool MidiDriver::_forceTypeMT32 = false;
- while (md->name) {
- // Compare the string passed to us with the current table entry.
- // We ignore any characters following an (optional) colon ':'
- // contained in str.
- if (!scumm_strnicmp(md->name, s, len)) {
- return md;
+MusicType MidiDriver::getMusicType(MidiDriver::DeviceHandle handle) {
+ if (_forceTypeMT32)
+ return MT_MT32;
+
+ if (handle) {
+ const MusicPlugin::List p = MusicMan.getPlugins();
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ MusicDevices i = (**m)->getDevices();
+ for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
+ if (handle == d->getHandle())
+ return d->getMusicType();
+ }
}
- md++;
}
-
- return 0;
+
+ return MT_NULL;
}
-static MidiDriverType getDefaultMIDIDriver() {
-#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
- return MD_WINDOWS;
-#elif defined(MACOSX)
- return MD_COREAUDIO;
-#elif defined(PALMOS_MODE)
- #if defined(COMPILE_CLIE)
- return MD_YPA1;
- #elif defined(COMPILE_ZODIAC)
- return MD_ZODIAC;
- #else
- return MD_NULL;
- #endif
-#else
- return MD_NULL;
-#endif
-}
+Common::String MidiDriver::getDeviceString(DeviceHandle handle, DeviceStringType type) {
+ if (handle) {
+ const MusicPlugin::List p = MusicMan.getPlugins();
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ MusicDevices i = (**m)->getDevices();
+ for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
+ if (handle == d->getHandle()) {
+ if (type == kDriverName)
+ return d->getMusicDriverName();
+ else if (type == kDriverId)
+ return d->getMusicDriverId();
+ else if (type == kDeviceId)
+ return d->getCompleteId();
+ else
+ return Common::String("auto");
+ }
+ }
+ }
+ }
-MidiDriverType MidiDriver::parseMusicDriver(const Common::String &str) {
- const MidiDriverDescription *md = findMusicDriver(str);
- if (md)
- return md->id;
- return MD_AUTO;
+ return Common::String("auto");
}
-MidiDriverType MidiDriver::detectMusicDriver(int flags) {
- MidiDriverType musicDriver;
+MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
+ // Query the selected music device (defaults to MT_AUTO device).
+ DeviceHandle hdl = getDeviceHandle(ConfMan.get("music_driver"));
- // Query the selected music driver (defaults to MD_AUTO).
- const MidiDriverDescription *md = findMusicDriver(ConfMan.get("music_driver"));
+ _forceTypeMT32 = false;
// Check whether the selected music driver is compatible with the
// given flags.
- if (!md || !(md->flags & flags))
- musicDriver = MD_AUTO;
- else
- musicDriver = md->id;
-
- // If the selected driver is MD_AUTO, we try to determine
- // a suitable and "optimal" music driver.
- if (musicDriver == MD_AUTO) {
-
- if (flags & MDT_PREFER_MIDI) {
- // A MIDI music driver is preferred. Of course this implies
- // that MIDI is actually listed in flags, so we verify that.
- assert(flags & MDT_MIDI);
+ switch (getMusicType(hdl)) {
+ case MT_PCSPK:
+ case MT_PCJR:
+ if (flags & MDT_PCSPK)
+ return hdl;
+ break;
+
+ case MT_ADLIB:
+ if (flags & MDT_ADLIB)
+ return hdl;
+ break;
+
+ case MT_TOWNS:
+ if (flags & MDT_TOWNS)
+ return hdl;
+ break;
+
+ case MT_GM:
+ case MT_GS:
+ case MT_MT32:
+ if (flags & MDT_MIDI)
+ return hdl;
+ case MT_NULL:
+ if (getDeviceString(hdl, MidiDriver::kDriverId).equals("null"))
+ return 0;
- // Query the default MIDI driver. It's possible that there
- // is none, in which case we revert to AUTO mode.
- musicDriver = getDefaultMIDIDriver();
- if (musicDriver == MD_NULL)
- musicDriver = MD_AUTO;
- }
-
- if (musicDriver == MD_AUTO) {
- // MIDI is not preferred, or no default MIDI device is available.
- // In this case we first try the alternate drivers before checking
- // for a 'real' MIDI driver.
+ default:
+ break;
+ }
- if (flags & MDT_TOWNS)
- musicDriver = MD_TOWNS;
- else if (flags & MDT_ADLIB)
- musicDriver = MD_ADLIB;
- else if (flags & MDT_PCSPK)
- musicDriver = MD_PCJR;
- else if (flags & MDT_MIDI)
- musicDriver = getDefaultMIDIDriver();
- else
- musicDriver = MD_NULL;
+ // If the selected driver did not match the flags setting,
+ // we try to determine a suitable and "optimal" music driver.
+ const MusicPlugin::List p = MusicMan.getPlugins();
+ // If only MDT_MIDI but not MDT_PREFER_MIDI is set we prefer the other devices (which will always be
+ // detected since they are hard coded and cannot be disabled.
+ for (int l = (flags & MDT_PREFER_MIDI) ? 1 : 0; l < 2; l++) {
+ if ((flags & MDT_MIDI) && (l == 1)) {
+ // If a preferred MT32 or GM device has been selected that device gets returned
+ hdl = getDeviceHandle(ConfMan.get((flags & MDT_PREFER_MT32) ? "mt32_device" : ((flags & MDT_PREFER_GM) ? "gm_device" : "auto"), Common::ConfigManager::kApplicationDomain));
+ if (getMusicType(hdl) != MT_NULL) {
+ if (flags & MDT_PREFER_MT32)
+ // If we have a preferred MT32 device we disable the gm/mt32 mapping (more about this in mididrv.h)
+ _forceTypeMT32 = true;
+
+ return hdl;
+ }
+
+ // If we have no specific device selected (neither in the scummvm nor in the game domain)
+ // and no preferred MT32 or GM device selected we arrive here.
+ // If MT32 is preferred we try for the first available device with music type 'MT_MT32' (usually the mt32 emulator)
+ if (flags & MDT_PREFER_MT32) {
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ MusicDevices i = (**m)->getDevices();
+ for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
+ if (getMusicType(hdl) == MT_MT32)
+ return hdl;
+ }
+ }
+ }
+
+ // Now we default to the first available device with music type 'MT_GM'
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ MusicDevices i = (**m)->getDevices();
+ for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
+ if (getMusicType(hdl) == MT_GM || getMusicType(hdl) == MT_GS)
+ return hdl;
+ }
+ }
+ }
+
+ MusicType tp = MT_NULL;
+ if (flags & MDT_TOWNS)
+ tp = MT_TOWNS;
+ else if (flags & MDT_ADLIB)
+ tp = MT_ADLIB;
+ else if (flags & MDT_PCSPK)
+ tp = MT_PCSPK;
+ else
+ tp = MT_NULL;
+
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ MusicDevices i = (**m)->getDevices();
+ for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
+ if (d->getMusicType() == tp)
+ return d->getHandle();
+ }
}
}
- return musicDriver;
+ return hdl;
}
-MidiDriver *MidiDriver::createMidi(MidiDriverType midiDriver) {
- switch (midiDriver) {
- case MD_NULL: return MidiDriver_NULL_create();
-
- case MD_ADLIB: return MidiDriver_ADLIB_create();
-
- case MD_TOWNS: return MidiDriver_YM2612_create();
-
- // Right now PC Speaker and PCjr are handled
- // outside the MidiDriver architecture, so
- // don't create anything for now.
- case MD_PCSPK:
- case MD_CMS:
- case MD_PCJR: return NULL;
-
-#ifdef USE_FLUIDSYNTH
- case MD_FLUIDSYNTH: return MidiDriver_FluidSynth_create();
-#endif
-
-#ifdef USE_MT32EMU
- case MD_MT32: return MidiDriver_MT32_create();
-#endif
-
-#if defined(PALMOS_MODE)
-#if defined(COMPILE_CLIE)
- case MD_YPA1: return MidiDriver_YamahaPa1_create();
-#elif defined(COMPILE_ZODIAC) && (!defined(ENABLE_SCUMM) || !defined(PALMOS_ARM))
- case MD_ZODIAC: return MidiDriver_Zodiac_create();
-#endif
-#endif
-
-#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
- case MD_WINDOWS: return MidiDriver_WIN_create();
-#endif
-#if defined(__MINT__)
- case MD_STMIDI: return MidiDriver_STMIDI_create();
-#endif
-#if defined(UNIX) && !defined(__BEOS__) && !defined(MACOSX) && !defined(__MAEMO__) && !defined(__MINT__)
- case MD_SEQ: return MidiDriver_SEQ_create();
-#endif
-#if defined(UNIX)
- case MD_TIMIDITY: return MidiDriver_TIMIDITY_create();
-#endif
-#if defined(IRIX)
- case MD_DMEDIA: return MidiDriver_DMEDIA_create();
-#endif
-#if defined(MACOSX)
- case MD_COREAUDIO: return MidiDriver_CORE_create();
- case MD_COREMIDI: return MidiDriver_CoreMIDI_create();
-#endif
-#if defined(UNIX) && defined(USE_ALSA)
- case MD_ALSA: return MidiDriver_ALSA_create();
-#endif
-#if defined(__amigaos4__)
- case MD_CAMD: return MidiDriver_CAMD_create();
-#endif
- default:
- error("Invalid midi driver selected");
+MidiDriver *MidiDriver::createMidi(MidiDriver::DeviceHandle handle) {
+ MidiDriver *driver = 0;
+ const MusicPlugin::List p = MusicMan.getPlugins();
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ if (getDeviceString(handle, MidiDriver::kDriverId).equals((**m)->getId()))
+ (**m)->createInstance(&driver, handle);
}
+ return driver;
+}
+
+MidiDriver::DeviceHandle MidiDriver::getDeviceHandle(const Common::String &identifier) {
+ const MusicPlugin::List p = MusicMan.getPlugins();
+ for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
+ MusicDevices i = (**m)->getDevices();
+ for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
+ if (identifier.equals(d->getCompleteId()) || identifier.equals(d->getCompleteName()))
+ return d->getHandle();
+ }
+ }
- return NULL;
+ return getDeviceHandle("auto");
}
diff --git a/sound/mididrv.h b/sound/mididrv.h
index 2931e2571e..ee8ef449f0 100644
--- a/sound/mididrv.h
+++ b/sound/mididrv.h
@@ -30,6 +30,8 @@
#include "common/timer.h"
class MidiChannel;
+class MusicDevice;
+
namespace Audio {
class Mixer;
}
@@ -43,56 +45,28 @@ namespace Common { class String; }
*
* @todo Rename MidiDriverType to MusicDriverType
*/
-enum MidiDriverType {
- // Pseudo drivers
- MD_AUTO,
- MD_NULL,
-
- // Windows
- MD_WINDOWS,
-
- // Atari ST
- MD_STMIDI,
-
- // Linux
- MD_ALSA,
- MD_SEQ,
-
- // Mac OS X
- MD_QTMUSIC,
- MD_COREAUDIO,
- MD_COREMIDI,
-
- // PalmOS
- MD_YPA1,
- MD_ZODIAC,
-
- // IRIX
- MD_DMEDIA,
-
- // AMIGAOS4
- MD_CAMD,
-
- // MIDI softsynths
- MD_FLUIDSYNTH,
- MD_MT32,
-
- // "Fake" MIDI devices
- MD_ADLIB,
- MD_PCSPK,
- MD_CMS,
- MD_PCJR,
- MD_TOWNS,
- MD_TIMIDITY
+
+/**
+ * Music types that music drivers can implement and engines can rely on.
+ */
+enum MusicType {
+ MT_NULL = 0, // Null / Auto
+ MT_PCSPK = 1, // PC Speaker
+ MT_PCJR = 2, // PCjr
+ MT_ADLIB = 3, // AdLib
+ MT_TOWNS = 4, // FM-TOWNS
+ MT_GM = 5, // General MIDI
+ MT_MT32 = 6, // MT-32
+ MT_GS = 7 // Roland GS
};
/**
- * A set of flags to be passed to detectMusicDriver() which can be used to
+ * A set of flags to be passed to detectDevice() which can be used to
* specify what kind of music driver is preferred / accepted.
*
* The flags (except for MDT_PREFER_MIDI) indicate whether a given driver
* type is acceptable. E.g. the TOWNS music driver could be returned by
- * detectMusicDriver if and only if MDT_TOWNS is specified.
+ * detectDevice if and only if MDT_TOWNS is specified.
*
* @todo Rename MidiDriverFlags to MusicDriverFlags
*/
@@ -104,7 +78,9 @@ enum MidiDriverFlags {
MDT_ADLIB = 1 << 3, // AdLib: Maps to MD_ADLIB
MDT_TOWNS = 1 << 4, // FM-TOWNS: Maps to MD_TOWNS
MDT_MIDI = 1 << 5, // Real MIDI
- MDT_PREFER_MIDI = 1 << 6 // Real MIDI output is preferred
+ MDT_PREFER_MIDI = 1 << 6, // Real MIDI output is preferred
+ MDT_PREFER_MT32 = 1 << 7, // MT-32 output is preferred
+ MDT_PREFER_GM = 1 << 8 // GM output is preferred
};
/**
@@ -114,12 +90,6 @@ enum MidiDriverFlags {
*
* @todo Rename MidiDriverType to MusicDriverType
*/
-struct MidiDriverDescription {
- const char *name;
- const char *description;
- MidiDriverType id; // A unique ID for each driver
- int flags; // Capabilities of this driver
-};
/**
* Abstract MIDI Driver Class
@@ -128,24 +98,41 @@ struct MidiDriverDescription {
*/
class MidiDriver {
public:
- /** Find the music driver matching the given driver name/description. */
- static const MidiDriverDescription *findMusicDriver(const Common::String &str);
+ typedef uint32 DeviceHandle;
- /** Get the id of the music driver matching the given driver name, or MD_AUTO if there is no match. */
- static MidiDriverType parseMusicDriver(const Common::String &str);
+ enum DeviceStringType {
+ kDriverName,
+ kDriverId,
+ kDeviceId
+ };
- static uint32 midiDriverFlags2GUIO(uint32 flags);
+ static uint32 musicType2GUIO(uint32 musicType);
+ /** Create music driver matching the given device handle, or MT_AUTO if there is no match. */
+ static MidiDriver *createMidi(DeviceHandle handle);
+
+ /** Returnd device handle based on the present devices and the flags parameter.
+ / * Returns NULl if the matching device is the null or auto device. */
+ static DeviceHandle detectDevice(int flags);
+
/**
- * Get a list of all available MidiDriver types.
- * @return list of all available midi drivers, terminated by a zero entry
+ * Find the music driver matching the given driver name/description.
*/
- static const MidiDriverDescription *getAvailableMidiDrivers();
+ static DeviceHandle getDeviceHandle(const Common::String &identifier);
- static MidiDriver *createMidi(MidiDriverType midiDriver);
+ /** Get the music type matching the given device handle, or MT_AUTO if there is no match. */
+ static MusicType getMusicType(DeviceHandle handle);
- static MidiDriverType detectMusicDriver(int flags);
+ /** Get the device string matching the given device handle and the given type. */
+ static Common::String getDeviceString(DeviceHandle handle, DeviceStringType type);
+private:
+ // If detectDevice() detects MT32 and we have a preferred MT32 device
+ // we use this to force getMusicType() to return MT_MT32 so that we don't
+ // have to rely on the 'True Roland MT-32' config manager setting (since nobody
+ // would possibly think about activating 'True Roland MT-32' when he has set
+ // 'Music Driver' to '>default>')
+ static bool _forceTypeMT32;
public:
virtual ~MidiDriver() { }
@@ -274,28 +261,4 @@ public:
virtual void sysEx_customInstrument(uint32 type, const byte *instr) = 0;
};
-
-// Factory functions, for faster compile
-extern MidiDriver *MidiDriver_NULL_create();
-extern MidiDriver *MidiDriver_ADLIB_create();
-extern MidiDriver *MidiDriver_WIN_create();
-extern MidiDriver *MidiDriver_STMIDI_create();
-extern MidiDriver *MidiDriver_SEQ_create();
-extern MidiDriver *MidiDriver_TIMIDITY_create();
-extern MidiDriver *MidiDriver_QT_create();
-extern MidiDriver *MidiDriver_CORE_create();
-extern MidiDriver *MidiDriver_CoreMIDI_create();
-extern MidiDriver *MidiDriver_ALSA_create();
-extern MidiDriver *MidiDriver_DMEDIA_create();
-extern MidiDriver *MidiDriver_CAMD_create();
-extern MidiDriver *MidiDriver_YM2612_create();
-#ifdef USE_FLUIDSYNTH
-extern MidiDriver *MidiDriver_FluidSynth_create();
-#endif
-#ifdef USE_MT32EMU
-extern MidiDriver *MidiDriver_MT32_create();
-#endif
-extern MidiDriver *MidiDriver_YamahaPa1_create();
-extern MidiDriver *MidiDriver_Zodiac_create();
-
#endif
diff --git a/sound/musicplugin.cpp b/sound/musicplugin.cpp
index b4754230da..7b5b6608ea 100644
--- a/sound/musicplugin.cpp
+++ b/sound/musicplugin.cpp
@@ -24,10 +24,12 @@
*/
#include "sound/musicplugin.h"
+#include "common/hash-str.h"
+#include "common/translation.h"
MusicDevice::MusicDevice(MusicPluginObject const *musicPlugin, Common::String name, MusicType mt) :
- _musicDriverName(musicPlugin->getName()), _musicDriverId(musicPlugin->getId()),
- _name(name), _type(mt) {
+ _musicDriverName(_(musicPlugin->getName())), _musicDriverId(musicPlugin->getId()),
+ _name(_(name)), _type(mt) {
}
Common::String MusicDevice::getCompleteName() {
@@ -46,3 +48,19 @@ Common::String MusicDevice::getCompleteName() {
return name;
}
+
+Common::String MusicDevice::getCompleteId() {
+ Common::String id = _musicDriverId;
+ if (!_name.empty()) {
+ id += "_";
+ id += _name;
+ }
+
+ return id;
+}
+
+MidiDriver::DeviceHandle MusicDevice::getHandle() {
+ if (_musicDriverId.equals("auto") || _musicDriverId.equals("null"))
+ return 0;
+ return (MidiDriver::DeviceHandle)Common::hashit(getCompleteId().c_str());
+}
diff --git a/sound/musicplugin.h b/sound/musicplugin.h
index df97494a90..3823f2fd3d 100644
--- a/sound/musicplugin.h
+++ b/sound/musicplugin.h
@@ -29,19 +29,6 @@
#include "sound/mididrv.h"
#include "common/list.h"
-/**
- * Music types that music drivers can implement and engines can rely on.
- */
-enum MusicType {
- MT_PCSPK = 1, // PC Speaker
- MT_PCJR = 2, // PCjr
- MT_ADLIB = 3, // AdLib
- MT_TOWNS = 4, // FM-TOWNS
- MT_GM = 5, // General MIDI
- MT_MT32 = 6, // MT-32
- MT_GS = 7 // Roland GS
-};
-
class MusicPluginObject;
/**
@@ -63,6 +50,14 @@ public:
* device name (if it isn't the default one) and the name of the driver.
*/
Common::String getCompleteName();
+
+ /**
+ * Returns a user readable string that contains the name of the current
+ * device name (if it isn't the default one) and the id of the driver.
+ */
+ Common::String getCompleteId();
+
+ MidiDriver::DeviceHandle getHandle();
private:
Common::String _name;
@@ -94,15 +89,18 @@ public:
virtual MusicDevices getDevices() const = 0;
/**
- * Tries to instantiate a MIDI Driver instance based on the settings of
- * the currently active ConfMan target. That is, the MusicPluginObject
- * should query the ConfMan singleton for the device name, port, etc.
+ * Tries to instantiate a MIDI Driver instance based on the device
+ * previously detected via MidiDriver::detectDevice()
*
* @param mididriver Pointer to a pointer which the MusicPluginObject sets
* to the newly create MidiDriver, or 0 in case of an error
+ *
+ * @param dev Pointer to a device to be used then creating the driver instance.
+ * Default value of zero for driver types without devices.
+ *
* @return a Common::Error describing the error which occurred, or kNoError
*/
- virtual Common::Error createInstance(MidiDriver **mididriver) const = 0;
+ virtual Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const = 0;
};
diff --git a/sound/null.cpp b/sound/null.cpp
index 00a5f5e488..775a0e2fcb 100644
--- a/sound/null.cpp
+++ b/sound/null.cpp
@@ -24,6 +24,7 @@
#include "sound/musicplugin.h"
#include "sound/mpu401.h"
+#include "common/translation.h"
/* NULL driver */
class MidiDriver_NULL : public MidiDriver_MPU401 {
@@ -37,19 +38,19 @@ public:
class NullMusicPlugin : public MusicPluginObject {
public:
- const char *getName() const {
- return "No music";
+ virtual const char *getName() const {
+ return _s("No music");
}
- const char *getId() const {
+ virtual const char *getId() const {
return "null";
}
- MusicDevices getDevices() const;
- Common::Error createInstance(MidiDriver **mididriver) const;
+ virtual MusicDevices getDevices() const;
+ virtual Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
};
-Common::Error NullMusicPlugin::createInstance(MidiDriver **mididriver) const {
+Common::Error NullMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
*mididriver = new MidiDriver_NULL();
return Common::kNoError;
@@ -57,28 +58,24 @@ Common::Error NullMusicPlugin::createInstance(MidiDriver **mididriver) const {
MusicDevices NullMusicPlugin::getDevices() const {
MusicDevices devices;
- // TODO: return a different music type?
- devices.push_back(MusicDevice(this, "", MT_GM));
+ devices.push_back(MusicDevice(this, _s(""), MT_NULL));
return devices;
}
-MidiDriver *MidiDriver_NULL_create() {
- MidiDriver *mididriver;
-
- NullMusicPlugin p;
- p.createInstance(&mididriver);
-
- return mididriver;
-}
+class AutoMusicPlugin : public NullMusicPlugin {
+public:
+ const char *getName() const {
+ return _s("<default>");
+ }
-#ifdef DISABLE_ADLIB
-MidiDriver *MidiDriver_ADLIB_create() {
- return MidiDriver_NULL_create();
-}
-#endif
+ const char *getId() const {
+ return "auto";
+ }
+};
//#if PLUGIN_ENABLED_DYNAMIC(NULL)
//REGISTER_PLUGIN_DYNAMIC(NULL, PLUGIN_TYPE_MUSIC, NullMusicPlugin);
//#else
+ REGISTER_PLUGIN_STATIC(AUTO, PLUGIN_TYPE_MUSIC, AutoMusicPlugin);
REGISTER_PLUGIN_STATIC(NULL, PLUGIN_TYPE_MUSIC, NullMusicPlugin);
//#endif
diff --git a/sound/softsynth/adlib.cpp b/sound/softsynth/adlib.cpp
index 6697cef646..ffb359e816 100644
--- a/sound/softsynth/adlib.cpp
+++ b/sound/softsynth/adlib.cpp
@@ -27,6 +27,7 @@
#include "common/util.h"
#include "sound/fmopl.h"
#include "sound/musicplugin.h"
+#include "common/translation.h"
#ifdef DEBUG_ADLIB
static int tick;
@@ -1586,7 +1587,7 @@ void MidiDriver_ADLIB::adlib_note_on(int chan, byte note, int mod) {
class AdLibEmuMusicPlugin : public MusicPluginObject {
public:
const char *getName() const {
- return "AdLib Emulator";
+ return _s("AdLib Emulator");
}
const char *getId() const {
@@ -1594,7 +1595,7 @@ public:
}
MusicDevices getDevices() const;
- Common::Error createInstance(MidiDriver **mididriver) const;
+ Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
};
MusicDevices AdLibEmuMusicPlugin::getDevices() const {
@@ -1603,21 +1604,12 @@ MusicDevices AdLibEmuMusicPlugin::getDevices() const {
return devices;
}
-Common::Error AdLibEmuMusicPlugin::createInstance(MidiDriver **mididriver) const {
+Common::Error AdLibEmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
*mididriver = new MidiDriver_ADLIB(g_system->getMixer());
return Common::kNoError;
}
-MidiDriver *MidiDriver_ADLIB_create() {
- MidiDriver *mididriver;
-
- AdLibEmuMusicPlugin p;
- p.createInstance(&mididriver);
-
- return mididriver;
-}
-
//#if PLUGIN_ENABLED_DYNAMIC(ADLIB)
//REGISTER_PLUGIN_DYNAMIC(ADLIB, PLUGIN_TYPE_MUSIC, AdLibEmuMusicPlugin);
//#else
diff --git a/sound/softsynth/fluidsynth.cpp b/sound/softsynth/fluidsynth.cpp
index c3bd782cc1..fcb4591a20 100644
--- a/sound/softsynth/fluidsynth.cpp
+++ b/sound/softsynth/fluidsynth.cpp
@@ -230,7 +230,7 @@ public:
}
MusicDevices getDevices() const;
- Common::Error createInstance(MidiDriver **mididriver) const;
+ Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
};
MusicDevices FluidSynthMusicPlugin::getDevices() const {
@@ -239,21 +239,12 @@ MusicDevices FluidSynthMusicPlugin::getDevices() const {
return devices;
}
-Common::Error FluidSynthMusicPlugin::createInstance(MidiDriver **mididriver) const {
+Common::Error FluidSynthMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
*mididriver = new MidiDriver_FluidSynth(g_system->getMixer());
return Common::kNoError;
}
-MidiDriver *MidiDriver_FluidSynth_create() {
- MidiDriver *mididriver;
-
- FluidSynthMusicPlugin p;
- p.createInstance(&mididriver);
-
- return mididriver;
-}
-
//#if PLUGIN_ENABLED_DYNAMIC(FLUIDSYNTH)
//REGISTER_PLUGIN_DYNAMIC(FLUIDSYNTH, PLUGIN_TYPE_MUSIC, FluidSynthMusicPlugin);
//#else
diff --git a/sound/softsynth/mt32.cpp b/sound/softsynth/mt32.cpp
index 612dce06b0..95263a040d 100644
--- a/sound/softsynth/mt32.cpp
+++ b/sound/softsynth/mt32.cpp
@@ -39,6 +39,7 @@
#include "common/system.h"
#include "common/util.h"
#include "common/archive.h"
+#include "common/translation.h"
#include "graphics/fontman.h"
#include "graphics/surface.h"
@@ -323,7 +324,7 @@ int MidiDriver_MT32::open() {
}
_initialising = true;
- drawMessage(-1, "Initialising MT-32 Emulator");
+ drawMessage(-1, _s("Initialising MT-32 Emulator"));
if (!_synth->open(prop))
return MERR_DEVICE_NOT_AVAILABLE;
_initialising = false;
@@ -537,7 +538,7 @@ void MidiDriver_ThreadedMT32::onTimer() {
class MT32EmuMusicPlugin : public MusicPluginObject {
public:
const char *getName() const {
- return "MT-32 Emulator";
+ return _s("MT-32 Emulator");
}
const char *getId() const {
@@ -545,7 +546,7 @@ public:
}
MusicDevices getDevices() const;
- Common::Error createInstance(MidiDriver **mididriver) const;
+ Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
};
MusicDevices MT32EmuMusicPlugin::getDevices() const {
@@ -554,23 +555,13 @@ MusicDevices MT32EmuMusicPlugin::getDevices() const {
return devices;
}
-Common::Error MT32EmuMusicPlugin::createInstance(MidiDriver **mididriver) const {
- *mididriver = new MidiDriver_MT32(g_system->getMixer());
-
- return Common::kNoError;
-}
-
-MidiDriver *MidiDriver_MT32_create() {
- // HACK: It will stay here until engine plugin loader overhaul
+Common::Error MT32EmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
if (ConfMan.hasKey("extrapath"))
SearchMan.addDirectory("extrapath", ConfMan.get("extrapath"));
- MidiDriver *mididriver;
-
- MT32EmuMusicPlugin p;
- p.createInstance(&mididriver);
+ *mididriver = new MidiDriver_MT32(g_system->getMixer());
- return mididriver;
+ return Common::kNoError;
}
//#if PLUGIN_ENABLED_DYNAMIC(MT32)
diff --git a/sound/softsynth/ym2612.cpp b/sound/softsynth/ym2612.cpp
index e337bc4ab9..08331c6244 100644
--- a/sound/softsynth/ym2612.cpp
+++ b/sound/softsynth/ym2612.cpp
@@ -27,6 +27,7 @@
#include "sound/softsynth/ym2612.h"
#include "common/util.h"
#include "sound/musicplugin.h"
+#include "common/translation.h"
////////////////////////////////////////
//
@@ -758,7 +759,7 @@ void MidiDriver_YM2612::removeLookupTables() {
class TownsEmuMusicPlugin : public MusicPluginObject {
public:
const char *getName() const {
- return "FM Towns Emulator";
+ return _s("FM Towns Emulator");
}
const char *getId() const {
@@ -766,7 +767,7 @@ public:
}
MusicDevices getDevices() const;
- Common::Error createInstance(MidiDriver **mididriver) const;
+ Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
};
MusicDevices TownsEmuMusicPlugin::getDevices() const {
@@ -775,21 +776,12 @@ MusicDevices TownsEmuMusicPlugin::getDevices() const {
return devices;
}
-Common::Error TownsEmuMusicPlugin::createInstance(MidiDriver **mididriver) const {
+Common::Error TownsEmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
*mididriver = new MidiDriver_YM2612(g_system->getMixer());
return Common::kNoError;
}
-MidiDriver *MidiDriver_YM2612_create() {
- MidiDriver *mididriver;
-
- TownsEmuMusicPlugin p;
- p.createInstance(&mididriver);
-
- return mididriver;
-}
-
//#if PLUGIN_ENABLED_DYNAMIC(TOWNS)
//REGISTER_PLUGIN_DYNAMIC(TOWNS, PLUGIN_TYPE_MUSIC, TownsEmuMusicPlugin);
//#else