aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-03-26 13:52:43 +0000
committerMax Horn2009-03-26 13:52:43 +0000
commite5e16152808bfc44681a5ea217685fb474339064 (patch)
tree8dd91ea357007552e67222c59d66deac572fc13f
parentc21110f36ee9618fd94f306eba39fe9208eb887d (diff)
downloadscummvm-rg350-e5e16152808bfc44681a5ea217685fb474339064.tar.gz
scummvm-rg350-e5e16152808bfc44681a5ea217685fb474339064.tar.bz2
scummvm-rg350-e5e16152808bfc44681a5ea217685fb474339064.zip
MidiDriver cleanup: findMusicDriver now returns a pointer (makes it possible to distinguish 'no match found' from other results); updated parseMusicDriver accordingly; some methods now return MidiDriverType instead of int
svn-id: r39702
-rw-r--r--base/commandLine.cpp2
-rw-r--r--gui/options.cpp13
-rw-r--r--sound/mididrv.cpp32
-rw-r--r--sound/mididrv.h8
4 files changed, 26 insertions, 29 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 998c96dedf..420e51b29b 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -346,7 +346,7 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
END_OPTION
DO_OPTION('e', "music-driver")
- if (MidiDriver::parseMusicDriver(option) < 0)
+ if (MidiDriver::findMusicDriver(option) == 0)
usage("Unrecognized music driver '%s'", option);
END_OPTION
diff --git a/gui/options.cpp b/gui/options.cpp
index 3e11161aa6..956c0d8cf6 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -177,17 +177,8 @@ void OptionsDialog::open() {
// Audio options
if (_midiPopUp) {
// Music driver
- const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();
- int i = 0;
- const int midiDriver =
- ConfMan.hasKey("music_driver", _domain)
- ? MidiDriver::parseMusicDriver(ConfMan.get("music_driver", _domain))
- : MD_AUTO;
- while (md->name && md->id != midiDriver) {
- i++;
- md++;
- }
- _midiPopUp->setSelected(md->name ? i : 0);
+ MidiDriverType id = MidiDriver::parseMusicDriver(ConfMan.get("music_driver", _domain));
+ _midiPopUp->setSelectedTag(id);
}
if (_outputRatePopUp) {
diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp
index 8e85b5a5f8..c77786c6cf 100644
--- a/sound/mididrv.cpp
+++ b/sound/mididrv.cpp
@@ -124,9 +124,9 @@ const MidiDriverDescription *MidiDriver::getAvailableMidiDrivers() {
return s_musicDrivers;
}
-const MidiDriverDescription &MidiDriver::findMusicDriver(const Common::String &str) {
+const MidiDriverDescription *MidiDriver::findMusicDriver(const Common::String &str) {
if (str.empty())
- return s_musicDrivers[0];
+ return 0;
const char *s = str.c_str();
int len = 0;
@@ -141,19 +141,15 @@ const MidiDriverDescription &MidiDriver::findMusicDriver(const Common::String &s
// We ignore any characters following an (optional) colon ':'
// contained in str.
if (!scumm_strnicmp(md->name, s, len)) {
- return *md;
+ return md;
}
md++;
}
- return s_musicDrivers[0];
+ return 0;
}
-int MidiDriver::parseMusicDriver(const Common::String &str) {
- return findMusicDriver(str).id;
-}
-
-static int getDefaultMIDIDriver() {
+static MidiDriverType getDefaultMIDIDriver() {
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
return MD_WINDOWS;
#elif defined(MACOSX)
@@ -171,15 +167,25 @@ static int getDefaultMIDIDriver() {
#endif
}
-int MidiDriver::detectMusicDriver(int flags) {
+MidiDriverType MidiDriver::parseMusicDriver(const Common::String &str) {
+ const MidiDriverDescription *md = findMusicDriver(str);
+ if (md)
+ return md->id;
+ return MD_AUTO;
+}
+
+MidiDriverType MidiDriver::detectMusicDriver(int flags) {
+ MidiDriverType musicDriver;
+
// Query the selected music driver (defaults to MD_AUTO).
- const MidiDriverDescription &md = findMusicDriver(ConfMan.get("music_driver"));
- int musicDriver = md.id;
+ const MidiDriverDescription *md = findMusicDriver("music_driver");
// Check whether the selected music driver is compatible with the
// given flags.
- if (! (md.flags & 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.
diff --git a/sound/mididrv.h b/sound/mididrv.h
index dd1786a094..700fd01f6b 100644
--- a/sound/mididrv.h
+++ b/sound/mididrv.h
@@ -126,10 +126,10 @@ struct MidiDriverDescription {
class MidiDriver {
public:
/** Find the music driver matching the given driver name/description. */
- static const MidiDriverDescription &findMusicDriver(const Common::String &str);
+ static const MidiDriverDescription *findMusicDriver(const Common::String &str);
- /** Convert a string containing a music driver name into MIDI Driver type. */
- static int parseMusicDriver(const Common::String &str);
+ /** 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);
/**
* Get a list of all available MidiDriver types.
@@ -139,7 +139,7 @@ public:
static MidiDriver *createMidi(int midiDriver);
- static int detectMusicDriver(int flags);
+ static MidiDriverType detectMusicDriver(int flags);
public: