aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-10-18 00:22:46 +0000
committerMax Horn2003-10-18 00:22:46 +0000
commit33f2fbff08573634e868c50d5cff3e4d2482a543 (patch)
tree8f2d54cc54085bd418743b5b2d4fbcbcb7882a63
parent0694eed27393ee7d1cbeccd20e8641fa261f5642 (diff)
downloadscummvm-rg350-33f2fbff08573634e868c50d5cff3e4d2482a543.tar.gz
scummvm-rg350-33f2fbff08573634e868c50d5cff3e4d2482a543.tar.bz2
scummvm-rg350-33f2fbff08573634e868c50d5cff3e4d2482a543.zip
We proudly present the latest installment of our hit series 'Untangle the mess': 'Help! Space Invaders refactored the music detector'... in other news, I obviously need to sleep now
svn-id: r10883
-rw-r--r--base/gameDetector.cpp119
-rw-r--r--base/gameDetector.h15
-rw-r--r--gui/options.cpp3
-rw-r--r--scumm/scummvm.cpp12
-rw-r--r--simon/simon.cpp2
-rw-r--r--sky/sky.cpp7
-rw-r--r--sound/mididrv.cpp18
-rw-r--r--sound/mididrv.h5
8 files changed, 90 insertions, 91 deletions
diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp
index b855a658cb..1d1fc39cea 100644
--- a/base/gameDetector.cpp
+++ b/base/gameDetector.cpp
@@ -178,7 +178,6 @@ GameDetector::GameDetector() {
ConfMan.registerDefault("confirm_exit", false);
_dumpScripts = false;
- _midi_driver = MD_AUTO;
_game.features = 0;
_plugin = 0;
@@ -492,23 +491,6 @@ int GameDetector::parseGraphicsMode(const String &str) {
return -1;
}
-int GameDetector::parseMusicDriver(const String &str) {
- if (str.isEmpty())
- return -1;
-
- const char *s = str.c_str();
- const MidiDriverDescription *md = getAvailableMidiDrivers();
-
- while (md->name) {
- if (!scumm_stricmp(md->name, s)) {
- return md->id;
- }
- md++;
- }
-
- return -1;
-}
-
bool GameDetector::detectGame() {
String realGame;
@@ -529,6 +511,53 @@ bool GameDetector::detectGame() {
}
}
+int GameDetector::detectMusicDriver(int midiFlags) {
+ int musicDriver = parseMusicDriver(ConfMan.get("music_driver"));
+ /* Use the adlib sound driver if auto mode is selected,
+ * and the game is one of those that want adlib as
+ * default, OR if the game is an older game that doesn't
+ * support anything else anyway. */
+ if (musicDriver == MD_AUTO || musicDriver < 0) {
+ if (midiFlags & MDT_PREFER_NATIVE) {
+ if (musicDriver == MD_AUTO) {
+ #if defined (WIN32) && !defined(_WIN32_WCE)
+ musicDriver = MD_WINDOWS; // MD_WINDOWS is default MidiDriver on windows targets
+ #elif defined(MACOSX)
+ musicDriver = MD_COREAUDIO;
+ #elif defined(__PALM_OS__) // must be before mac
+ musicDriver = MD_YPA1;
+ #elif defined(__MORPHOS__)
+ musicDriver = MD_ETUDE;
+ #elif defined (_WIN32_WCE) || defined(UNIX) || defined(X11_BACKEND)
+ // Always use MIDI emulation via adlib driver on CE and UNIX device
+
+ // TODO: We should, for the Unix targets, attempt to detect
+ // whether a sequencer is available, and use it instead.
+ musicDriver = MD_ADLIB;
+ #else
+ musicDriver = MD_NULL;
+ #endif
+ }
+ } else
+ musicDriver = MD_TOWNS;
+ }
+ bool nativeMidiDriver =
+ (musicDriver != MD_NULL && musicDriver != MD_ADLIB &&
+ musicDriver != MD_PCSPK && musicDriver != MD_PCJR &&
+ musicDriver != MD_TOWNS);
+
+ if (nativeMidiDriver && !(midiFlags & MDT_NATIVE))
+ musicDriver = MD_TOWNS;
+ if (musicDriver == MD_TOWNS && !(midiFlags & MDT_TOWNS))
+ musicDriver = MD_ADLIB;
+ if (musicDriver == MD_ADLIB && !(midiFlags & MDT_ADLIB))
+ musicDriver = MD_PCJR;
+ if ((musicDriver == MD_PCSPK || musicDriver == MD_PCJR) && !(midiFlags & MDT_PCSPK))
+ musicDriver = MD_NULL;
+
+ return musicDriver;
+}
+
bool GameDetector::detectMain() {
if (_targetName.isEmpty()) {
warning("No game was specified...");
@@ -540,30 +569,6 @@ bool GameDetector::detectMain() {
return false;
}
- /* Use the adlib sound driver if auto mode is selected,
- * and the game is one of those that want adlib as
- * default, OR if the game is an older game that doesn't
- * support anything else anyway. */
- _midi_driver = parseMusicDriver(ConfMan.get("music_driver"));
- if (_midi_driver == MD_AUTO || _midi_driver < 0) {
- if (_game.midi & MDT_PREFER_NATIVE)
- _midi_driver = getMidiDriverType();
- else
- _midi_driver = MD_TOWNS;
- }
- bool nativeMidiDriver =
- (_midi_driver != MD_NULL && _midi_driver != MD_ADLIB &&
- _midi_driver != MD_PCSPK && _midi_driver != MD_PCJR &&
- _midi_driver != MD_TOWNS);
- if (nativeMidiDriver && !(_game.midi & MDT_NATIVE))
- _midi_driver = MD_TOWNS;
- if (_midi_driver == MD_TOWNS && !(_game.midi & MDT_TOWNS))
- _midi_driver = MD_ADLIB;
- if (_midi_driver == MD_ADLIB && !(_game.midi & MDT_ADLIB))
- _midi_driver = MD_PCJR;
- if ((_midi_driver == MD_PCSPK || _midi_driver == MD_PCJR) && !(_game.midi & MDT_PCSPK))
- _midi_driver = MD_NULL;
-
String gameDataPath(ConfMan.get("path"));
if (gameDataPath.isEmpty()) {
warning("No path was provided. Assuming the data files are in the current directory");
@@ -611,38 +616,12 @@ Engine *GameDetector::createEngine(OSystem *sys) {
return _plugin->createInstance(this, sys);
}
-int GameDetector::getMidiDriverType() {
-
- if (_midi_driver != MD_AUTO) return _midi_driver;
-
-#if defined (WIN32) && !defined(_WIN32_WCE)
- return MD_WINDOWS; // MD_WINDOWS is default MidiDriver on windows targets
-#elif defined(MACOSX)
- return MD_COREAUDIO;
-#elif defined(__PALM_OS__) // must be before mac
- return MD_YPA1;
-#elif defined(macintosh)
- return MD_QTMUSIC;
-#elif defined(__MORPHOS__)
- return MD_ETUDE;
-#elif defined (_WIN32_WCE) || defined(UNIX) || defined(X11_BACKEND)
- // Always use MIDI emulation via adlib driver on CE and UNIX device
-
- // TODO: We should, for the Unix targets, attempt to detect
- // whether a sequencer is available, and use it instead.
- return MD_ADLIB;
-#endif
- return MD_NULL;
-}
-
SoundMixer *GameDetector::createMixer() {
return new SoundMixer();
}
-MidiDriver *GameDetector::createMidi() {
- int drv = getMidiDriverType();
-
- switch(drv) {
+MidiDriver *GameDetector::createMidi(int midiDriver) {
+ switch(midiDriver) {
case MD_NULL: return MidiDriver_NULL_create();
// In the case of Adlib, we won't specify anything.
diff --git a/base/gameDetector.h b/base/gameDetector.h
index d105e1d20a..f82237eaf9 100644
--- a/base/gameDetector.h
+++ b/base/gameDetector.h
@@ -71,20 +71,17 @@ public:
bool _dumpScripts;
- int _midi_driver;
-
public:
- OSystem *createSystem();
- Engine *createEngine(OSystem *system);
+ void setTarget(const String &name);
- SoundMixer *createMixer();
- MidiDriver *createMidi();
- int getMidiDriverType(); // FIXME: Try to get rid of this, only Sky frontend uses it
+ Engine *createEngine(OSystem *system);
- void setTarget(const String &name);
+ static OSystem *createSystem();
+ static SoundMixer *createMixer();
+ static MidiDriver *createMidi(int midiDriver);
static int parseGraphicsMode(const String &s); // Used in main()
- static int parseMusicDriver(const String &s);
+ static int detectMusicDriver(int midiFlags);
static GameSettings findGame(const String &gameName, const Plugin **plugin = NULL);
diff --git a/gui/options.cpp b/gui/options.cpp
index 475e478ce5..403afb4694 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -92,9 +92,10 @@ GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui, GameDetector &detector)
// Populate it
const MidiDriverDescription *md = getAvailableMidiDrivers();
+ const int midiDriver = parseMusicDriver(ConfMan.get("music_driver"));
while (md->name) {
_midiPopUp->appendEntry(md->description, md->id);
- if (md->id == detector._midi_driver)
+ if (md->id == midiDriver)
midiSelected = i;
i++;
md++;
diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp
index 86de4be748..38e398bc26 100644
--- a/scumm/scummvm.cpp
+++ b/scumm/scummvm.cpp
@@ -604,7 +604,7 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst)
// differing from the regular version(s) of that game.
_gameName = ConfMan.hasKey("basename") ? ConfMan.get("basename") : detector->_game.gameName;
- _midiDriver = detector->_midi_driver;
+ _midiDriver = GameDetector::detectMusicDriver(detector->_game.midi);
_demoMode = ConfMan.getBool("demo_mode");
_noSubtitles = ConfMan.getBool("nosubtitles");
@@ -654,11 +654,11 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst)
_silentDigitalImuse = false;
if (!_mixer->bindToSystem(syst)) {
warning("Sound mixer initialization failed");
- if (detector->_midi_driver == MD_ADLIB ||
- detector->_midi_driver == MD_PCSPK ||
- detector->_midi_driver == MD_PCJR)
+ if (_midiDriver == MD_ADLIB ||
+ _midiDriver == MD_PCSPK ||
+ _midiDriver == MD_PCJR)
{
- _midiDriver = detector->_midi_driver = MD_NULL;
+ _midiDriver = MD_NULL;
warning("MIDI driver depends on sound mixer, switching to null MIDI driver");
}
_silentDigitalImuse = true;
@@ -679,7 +679,7 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst)
} else if (((_midiDriver == MD_PCJR) || (_midiDriver == MD_PCSPK)) && ((_version > 2) && (_version < 5))) {
_musicEngine = new Player_V2(this, _midiDriver != MD_PCSPK);
} else if (_version > 2) {
- MidiDriver *driver = detector->createMidi();
+ MidiDriver *driver = detector->createMidi(_midiDriver);
if (driver && _native_mt32)
driver->property (MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
_musicEngine = _imuse = IMuse::create(syst, _mixer, driver);
diff --git a/simon/simon.cpp b/simon/simon.cpp
index 09e9a2eb56..b36dbaeb3c 100644
--- a/simon/simon.cpp
+++ b/simon/simon.cpp
@@ -506,7 +506,7 @@ SimonEngine::SimonEngine(GameDetector *detector, OSystem *syst)
set_volume(ConfMan.getInt("sfx_volume"));
// Setup midi driver
- MidiDriver *driver = detector->createMidi();
+ MidiDriver *driver = detector->createMidi(GameDetector::detectMusicDriver(detector->_game.midi));
if (!driver)
driver = MidiDriver_ADLIB_create(_mixer);
else if (ConfMan.getBool("native_mt32"))
diff --git a/sky/sky.cpp b/sky/sky.cpp
index ddec59eaa0..360ec6fd46 100644
--- a/sky/sky.cpp
+++ b/sky/sky.cpp
@@ -265,15 +265,16 @@ void SkyEngine::initialise(void) {
_systemVars.gameVersion = _skyDisk->determineGameVersion();
- if (_detector->getMidiDriverType() == MD_ADLIB) {
+ int midiDriver = GameDetector::detectMusicDriver(_detector->_game.midi);
+ if (midiDriver == MD_ADLIB) {
_systemVars.systemFlags |= SF_SBLASTER;
_skyMusic = new SkyAdlibMusic(_mixer, _skyDisk, _system);
} else {
_systemVars.systemFlags |= SF_ROLAND;
if (ConfMan.getBool("native_mt32"))
- _skyMusic = new SkyMT32Music(_detector->createMidi(), _skyDisk, _system);
+ _skyMusic = new SkyMT32Music(_detector->createMidi(midiDriver), _skyDisk, _system);
else
- _skyMusic = new SkyGmMusic(_detector->createMidi(), _skyDisk, _system);
+ _skyMusic = new SkyGmMusic(_detector->createMidi(midiDriver), _skyDisk, _system);
}
if (isCDVersion()) {
diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp
index d6ab13762c..437ea6333b 100644
--- a/sound/mididrv.cpp
+++ b/sound/mididrv.cpp
@@ -22,6 +22,7 @@
#include "stdafx.h"
#include "sound/mididrv.h"
+#include "common/str.h"
/** Internal list of all available 'midi' drivers. */
@@ -67,3 +68,20 @@ static const struct MidiDriverDescription midiDrivers[] = {
const MidiDriverDescription *getAvailableMidiDrivers() {
return midiDrivers;
}
+
+int parseMusicDriver(const Common::String &str) {
+ if (str.isEmpty())
+ return -1;
+
+ const char *s = str.c_str();
+ const MidiDriverDescription *md = getAvailableMidiDrivers();
+
+ while (md->name) {
+ if (!scumm_stricmp(md->name, s)) {
+ return md->id;
+ }
+ md++;
+ }
+
+ return -1;
+}
diff --git a/sound/mididrv.h b/sound/mididrv.h
index b82787b62d..e67643b36a 100644
--- a/sound/mididrv.h
+++ b/sound/mididrv.h
@@ -27,7 +27,7 @@
class MidiChannel;
class SoundMixer;
-
+namespace Common { class String; }
/** MIDI Driver Types */
enum {
@@ -48,6 +48,9 @@ enum {
MD_YPA1 = 14 // PalmOS
};
+/** Convert a string containing a music driver name into MIDI Driver type. */
+extern int parseMusicDriver(const Common::String &str);
+
/**
* Abstract description of a MIDI driver. Used by the config file and command
* line parsing code, and also to be able to give the user a list of available