diff options
author | Max Horn | 2004-12-02 00:33:42 +0000 |
---|---|---|
committer | Max Horn | 2004-12-02 00:33:42 +0000 |
commit | 5d5a13eec758665306cd21af058c118debc2ab66 (patch) | |
tree | 0ccef35e3377f781d7b9bbbdf1b3d2a4993807a8 | |
parent | cdec823d98f37bf47a5e557371c6e5a6ce7e017f (diff) | |
download | scummvm-rg350-5d5a13eec758665306cd21af058c118debc2ab66.tar.gz scummvm-rg350-5d5a13eec758665306cd21af058c118debc2ab66.tar.bz2 scummvm-rg350-5d5a13eec758665306cd21af058c118debc2ab66.zip |
Moved MidiDriver creation code into the MidiDriver class (as static methods), same for some other MIDI related stuff
svn-id: r15968
-rw-r--r-- | Makefile.common | 2 | ||||
-rw-r--r-- | base/gameDetector.cpp | 102 | ||||
-rw-r--r-- | base/gameDetector.h | 17 | ||||
-rw-r--r-- | gui/options.cpp | 8 | ||||
-rw-r--r-- | queen/queen.cpp | 4 | ||||
-rw-r--r-- | saga/saga.cpp | 4 | ||||
-rw-r--r-- | scumm/scumm.cpp | 4 | ||||
-rw-r--r-- | simon/simon.cpp | 6 | ||||
-rw-r--r-- | sky/sky.cpp | 6 | ||||
-rw-r--r-- | sound/mididrv.cpp | 109 | ||||
-rw-r--r-- | sound/mididrv.h | 32 |
11 files changed, 148 insertions, 146 deletions
diff --git a/Makefile.common b/Makefile.common index bd37fb6943..a7998ad5ec 100644 --- a/Makefile.common +++ b/Makefile.common @@ -85,8 +85,8 @@ endif MODULES += \ gui \ graphics \ - backends \ sound \ + backends \ common ifdef USE_MT32EMU diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp index ccd7aa4ec6..58a82630a8 100644 --- a/base/gameDetector.cpp +++ b/base/gameDetector.cpp @@ -28,7 +28,6 @@ #include "base/version.h" #include "common/config-manager.h" -#include "common/scaler.h" // Only for gfx_modes #include "sound/mididrv.h" #include "sound/mixer.h" @@ -314,7 +313,7 @@ void GameDetector::parseCommandLine(int argc, char **argv) { // maybe print a message like: // "'option' is not a supported music driver on this machine. // Available driver: ..." - if (parseMusicDriver(option) < 0) + if (MidiDriver::parseMusicDriver(option) < 0) goto ShowHelpAndExit; ConfMan.set("music_driver", option, kTransientDomain); END_OPTION @@ -505,54 +504,6 @@ 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; // TODO : cahnge this and use Zodiac driver when needed - #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_ADLIB; - } 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..."); @@ -588,54 +539,3 @@ Engine *GameDetector::createEngine(OSystem *sys) { SoundMixer *GameDetector::createMixer() { return new SoundMixer(); } - -MidiDriver *GameDetector::createMidi(int midiDriver) { - switch(midiDriver) { - case MD_NULL: return MidiDriver_NULL_create(); - - // In the case of Adlib, we won't specify anything. - // IMuse is designed to set up its own Adlib driver - // if need be, and we only have to specify a native - // driver. - case MD_ADLIB: return NULL; - -#ifdef USE_MT32EMU - case MD_MT32: return MidiDriver_MT32_create(g_engine->_mixer); -#endif - - case MD_TOWNS: return MidiDriver_YM2612_create(g_engine->_mixer); - - // Right now PC Speaker and PCjr are handled - // outside the MidiDriver architecture, so - // don't create anything for now. - case MD_PCSPK: - case MD_PCJR: return NULL; -#if defined(__PALM_OS__) - case MD_YPA1: return MidiDriver_YamahaPa1_create(); -#ifndef DISABLE_TAPWAVE - case MD_ZODIAC: return MidiDriver_Zodiac_create(); -#endif -#endif -#if defined(WIN32) && !defined(_WIN32_WCE) - case MD_WINDOWS: return MidiDriver_WIN_create(); -#endif -#if defined(__MORPHOS__) - case MD_ETUDE: return MidiDriver_ETUDE_create(); -#endif -#if defined(UNIX) && !defined(__BEOS__) && !defined(MACOSX) - case MD_SEQ: return MidiDriver_SEQ_create(); -#endif -#if (defined(MACOSX) || defined(macintosh)) && !defined(__PALM_OS__) - case MD_QTMUSIC: return MidiDriver_QT_create(); -#endif -#if defined(MACOSX) - case MD_COREAUDIO: return MidiDriver_CORE_create(); -#endif -#if defined(UNIX) && defined(USE_ALSA) - case MD_ALSA: return MidiDriver_ALSA_create(); -#endif - } - - error("Invalid midi driver selected"); - return NULL; -} diff --git a/base/gameDetector.h b/base/gameDetector.h index cd02fba45d..e74176d5a4 100644 --- a/base/gameDetector.h +++ b/base/gameDetector.h @@ -27,10 +27,9 @@ class Engine; class GameDetector; -class MidiDriver; class OSystem; -class SoundMixer; class Plugin; +class SoundMixer; /** Global (shared) game feature flags. */ enum { @@ -39,15 +38,6 @@ enum { GF_DEFAULT_TO_1X_SCALER = 1 << 30 }; -enum MidiDriverType { - MDT_NONE = 0, - MDT_PCSPK = 1, // MD_PCSPK and MD_PCJR - MDT_ADLIB = 2, // MD_ADLIB - MDT_TOWNS = 4, // MD_TOWNS - MDT_NATIVE = 8, // Everything else - MDT_PREFER_NATIVE = 16 -}; - struct GameSettings { const char *name; const char *description; @@ -69,15 +59,12 @@ public: bool _dumpScripts; -public: void setTarget(const String &name); +public: Engine *createEngine(OSystem *system); static SoundMixer *createMixer(); - static MidiDriver *createMidi(int midiDriver); - - 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 38df8f916f..7bbbb98115 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -112,11 +112,11 @@ void OptionsDialog::open() { if (_multiMidiCheckbox) { // Music driver - const MidiDriverDescription *md = getAvailableMidiDrivers(); + const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); int i = 0; const int midiDriver = ConfMan.hasKey("music_driver", _domain) - ? parseMusicDriver(ConfMan.get("music_driver", _domain)) + ? MidiDriver::parseMusicDriver(ConfMan.get("music_driver", _domain)) : MD_AUTO; while (md->name && md->id != midiDriver) { i++; @@ -190,7 +190,7 @@ void OptionsDialog::close() { ConfMan.set("multi_midi", _multiMidiCheckbox->getState(), _domain); ConfMan.set("native_mt32", _mt32Checkbox->getState(), _domain); ConfMan.set("subtitles", _subCheckbox->getState(), _domain); - const MidiDriverDescription *md = getAvailableMidiDrivers(); + const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); while (md->name && md->id != (int)_midiPopUp->getSelectedTag()) md++; if (md->name) @@ -315,7 +315,7 @@ int OptionsDialog::addMIDIControls(GuiObject *boss, int yoffset) { yoffset += 16; // Populate it - const MidiDriverDescription *md = getAvailableMidiDrivers(); + const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); while (md->name) { _midiPopUp->appendEntry(md->description, md->id); md++; diff --git a/queen/queen.cpp b/queen/queen.cpp index 93ba371edc..a2780ce7dc 100644 --- a/queen/queen.cpp +++ b/queen/queen.cpp @@ -349,8 +349,8 @@ int QueenEngine::init(GameDetector &detector) { // Set mixer music volume to maximum, since music volume is regulated by MusicPlayer's MIDI messages _mixer->setMusicVolume(256); - int midiDriver = GameDetector::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE); - MidiDriver *driver = GameDetector::createMidi(midiDriver); + int midiDriver = MidiDriver::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE); + MidiDriver *driver = MidiDriver::createMidi(midiDriver); if (!driver) driver = MidiDriver_ADLIB_create(_mixer); else if (ConfMan.getBool("native_mt32") || (midiDriver == MD_MT32)) diff --git a/saga/saga.cpp b/saga/saga.cpp index 30a1f30e8c..be8e405e0d 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -187,12 +187,12 @@ int SagaEngine::init(GameDetector &detector) { _gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h, detector); // Graphics should be initialized before music - int midiDriver = GameDetector::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE); + int midiDriver = MidiDriver::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE); bool native_mt32 = (ConfMan.getBool("native_mt32") || (midiDriver == MD_MT32)); bool adlib = false; - MidiDriver *driver = GameDetector::createMidi(midiDriver); + MidiDriver *driver = MidiDriver::createMidi(midiDriver); if (!driver) { driver = MidiDriver_ADLIB_create(_mixer); adlib = true; diff --git a/scumm/scumm.cpp b/scumm/scumm.cpp index f207fee4b8..6fa95441c7 100644 --- a/scumm/scumm.cpp +++ b/scumm/scumm.cpp @@ -1310,7 +1310,7 @@ void ScummEngine_v90he::scummInit() { } void ScummEngine::setupMusic(int midi) { - _midiDriver = GameDetector::detectMusicDriver(midi); + _midiDriver = MidiDriver::detectMusicDriver(midi); _native_mt32 = (ConfMan.getBool("native_mt32") || (_midiDriver == MD_MT32)); #ifndef __GP32__ //ph0x FIXME, "quick dirty hack" @@ -1338,7 +1338,7 @@ void ScummEngine::setupMusic(int midi) { } else if (((_midiDriver == MD_PCJR) || (_midiDriver == MD_PCSPK)) && ((_version > 2) && (_version < 5))) { _musicEngine = new Player_V2(this, _midiDriver != MD_PCSPK); } else if (_version > 2 && _heversion <= 60) { - MidiDriver *nativeMidiDriver = GameDetector::createMidi(_midiDriver); + MidiDriver *nativeMidiDriver = MidiDriver::createMidi(_midiDriver); if (nativeMidiDriver != NULL && _native_mt32) nativeMidiDriver->property (MidiDriver::PROP_CHANNEL_MASK, 0x03FE); bool multi_midi = ConfMan.getBool("multi_midi") && _midiDriver != MD_NULL && (midi & MDT_ADLIB); diff --git a/simon/simon.cpp b/simon/simon.cpp index fb4a0868b6..722601f2b6 100644 --- a/simon/simon.cpp +++ b/simon/simon.cpp @@ -678,10 +678,10 @@ int SimonEngine::init(GameDetector &detector) { MidiDriver *driver = 0; _midiDriver = MD_NULL; if (_game == GAME_SIMON1AMIGA || _game == GAME_SIMON1CD32) - driver = GameDetector::createMidi(MD_NULL); // Create fake MIDI driver for Simon1Amiga and Simon2CD32 for now + driver = MidiDriver::createMidi(MD_NULL); // Create fake MIDI driver for Simon1Amiga and Simon2CD32 for now else { - _midiDriver = GameDetector::detectMusicDriver(MDT_ADLIB | MDT_NATIVE); - driver = GameDetector::createMidi(_midiDriver); + _midiDriver = MidiDriver::detectMusicDriver(MDT_ADLIB | MDT_NATIVE); + driver = MidiDriver::createMidi(_midiDriver); } if (!driver) driver = MidiDriver_ADLIB_create(_mixer); diff --git a/sky/sky.cpp b/sky/sky.cpp index e45c3c53d8..13cc4436bc 100644 --- a/sky/sky.cpp +++ b/sky/sky.cpp @@ -263,16 +263,16 @@ int SkyEngine::init(GameDetector &detector) { _systemVars.gameVersion = _skyDisk->determineGameVersion(); - int midiDriver = GameDetector::detectMusicDriver(MDT_ADLIB | MDT_NATIVE | MDT_PREFER_NATIVE); + int midiDriver = MidiDriver::detectMusicDriver(MDT_ADLIB | MDT_NATIVE | MDT_PREFER_NATIVE); if (midiDriver == MD_ADLIB) { _systemVars.systemFlags |= SF_SBLASTER; _skyMusic = new AdlibMusic(_mixer, _skyDisk, _system); } else { _systemVars.systemFlags |= SF_ROLAND; if (ConfMan.getBool("native_mt32") || (midiDriver == MD_MT32)) - _skyMusic = new MT32Music(GameDetector::createMidi(midiDriver), _skyDisk, _system); + _skyMusic = new MT32Music(MidiDriver::createMidi(midiDriver), _skyDisk, _system); else - _skyMusic = new GmMusic(GameDetector::createMidi(midiDriver), _skyDisk, _system); + _skyMusic = new GmMusic(MidiDriver::createMidi(midiDriver), _skyDisk, _system); } if (isCDVersion()) { diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp index ed37e93272..11fa0d3b15 100644 --- a/sound/mididrv.cpp +++ b/sound/mididrv.cpp @@ -21,9 +21,11 @@ */ #include "stdafx.h" -#include "sound/mididrv.h" -#include "common/str.h" +#include "base/engine.h" +#include "common/config-manager.h" +#include "common/str.h" +#include "sound/mididrv.h" /** Internal list of all available 'midi' drivers. */ static const struct MidiDriverDescription midiDrivers[] = { @@ -67,11 +69,11 @@ static const struct MidiDriverDescription midiDrivers[] = { }; -const MidiDriverDescription *getAvailableMidiDrivers() { +const MidiDriverDescription *MidiDriver::getAvailableMidiDrivers() { return midiDrivers; } -int parseMusicDriver(const Common::String &str) { +int MidiDriver::parseMusicDriver(const Common::String &str) { if (str.isEmpty()) return -1; @@ -87,3 +89,102 @@ int parseMusicDriver(const Common::String &str) { return -1; } + +int MidiDriver::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; // TODO : cahnge this and use Zodiac driver when needed + #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_ADLIB; + } 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; +} + +MidiDriver *MidiDriver::createMidi(int midiDriver) { + switch(midiDriver) { + case MD_NULL: return MidiDriver_NULL_create(); + + // In the case of Adlib, we won't specify anything. + // IMuse is designed to set up its own Adlib driver + // if need be, and we only have to specify a native + // driver. + case MD_ADLIB: return NULL; + +#ifdef USE_MT32EMU + case MD_MT32: return MidiDriver_MT32_create(g_engine->_mixer); +#endif + + case MD_TOWNS: return MidiDriver_YM2612_create(g_engine->_mixer); + + // Right now PC Speaker and PCjr are handled + // outside the MidiDriver architecture, so + // don't create anything for now. + case MD_PCSPK: + case MD_PCJR: return NULL; +#if defined(__PALM_OS__) + case MD_YPA1: return MidiDriver_YamahaPa1_create(); +#ifndef DISABLE_TAPWAVE + case MD_ZODIAC: return MidiDriver_Zodiac_create(); +#endif +#endif +#if defined(WIN32) && !defined(_WIN32_WCE) + case MD_WINDOWS: return MidiDriver_WIN_create(); +#endif +#if defined(__MORPHOS__) + case MD_ETUDE: return MidiDriver_ETUDE_create(); +#endif +#if defined(UNIX) && !defined(__BEOS__) && !defined(MACOSX) + case MD_SEQ: return MidiDriver_SEQ_create(); +#endif +#if (defined(MACOSX) || defined(macintosh)) && !defined(__PALM_OS__) + case MD_QTMUSIC: return MidiDriver_QT_create(); +#endif +#if defined(MACOSX) + case MD_COREAUDIO: return MidiDriver_CORE_create(); +#endif +#if defined(UNIX) && defined(USE_ALSA) + case MD_ALSA: return MidiDriver_ALSA_create(); +#endif + } + + error("Invalid midi driver selected"); + return NULL; +} diff --git a/sound/mididrv.h b/sound/mididrv.h index b6e57fe7f9..0041c146ed 100644 --- a/sound/mididrv.h +++ b/sound/mididrv.h @@ -51,8 +51,14 @@ enum { MD_MT32 = 16 }; -/** Convert a string containing a music driver name into MIDI Driver type. */ -extern int parseMusicDriver(const Common::String &str); +enum MidiDriverType { + MDT_NONE = 0, + MDT_PCSPK = 1, // MD_PCSPK and MD_PCJR + MDT_ADLIB = 2, // MD_ADLIB + MDT_TOWNS = 4, // MD_TOWNS + MDT_NATIVE = 8, // Everything else + MDT_PREFER_NATIVE = 16 +}; /** * Abstract description of a MIDI driver. Used by the config file and command @@ -65,16 +71,24 @@ struct MidiDriverDescription { int id; }; -/** - * Get a list of all available MidiDriver types. - * @return list of all available midi drivers, terminated by a zero entry - */ -extern const MidiDriverDescription *getAvailableMidiDrivers(); - - /** Abstract MIDI Driver Class */ class MidiDriver { public: + /** Convert a string containing a music driver name into MIDI Driver type. */ + static int parseMusicDriver(const Common::String &str); + + /** + * Get a list of all available MidiDriver types. + * @return list of all available midi drivers, terminated by a zero entry + */ + static const MidiDriverDescription *getAvailableMidiDrivers(); + + static MidiDriver *createMidi(int midiDriver); + + static int detectMusicDriver(int midiFlags); + + +public: virtual ~MidiDriver() { } /** |