diff options
author | Jamieson Christian | 2003-05-16 22:00:33 +0000 |
---|---|---|
committer | Jamieson Christian | 2003-05-16 22:00:33 +0000 |
commit | 5a15ce808a61b29dc902e3cb039b8ebb515409b3 (patch) | |
tree | 2ca685155ab142df2be081da1fe1f9271deebf5c | |
parent | a4550829965bb23eb42aee205648e621e0336473 (diff) | |
download | scummvm-rg350-5a15ce808a61b29dc902e3cb039b8ebb515409b3.tar.gz scummvm-rg350-5a15ce808a61b29dc902e3cb039b8ebb515409b3.tar.bz2 scummvm-rg350-5a15ce808a61b29dc902e3cb039b8ebb515409b3.zip |
Feature [557411] Adlib sound effects with GM drivers.
Support for simultaneous drivers is based on a
#define in imuse.cpp, and is disabled by default.
svn-id: r7582
-rw-r--r-- | common/gameDetector.cpp | 6 | ||||
-rw-r--r-- | scumm/imuse.cpp | 84 | ||||
-rw-r--r-- | scumm/resource.cpp | 11 |
3 files changed, 77 insertions, 24 deletions
diff --git a/common/gameDetector.cpp b/common/gameDetector.cpp index a1905c61a2..30aacaad93 100644 --- a/common/gameDetector.cpp +++ b/common/gameDetector.cpp @@ -689,7 +689,11 @@ MidiDriver *GameDetector::createMidi() { switch(drv) { case MD_NULL: return MidiDriver_NULL_create(); #ifndef __PALM_OS__ - case MD_ADLIB: _use_adlib = true; return MidiDriver_ADLIB_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: _use_adlib = true; return NULL; #else case MD_YPA1: return MidiDriver_YamahaPa1_create(); #endif diff --git a/scumm/imuse.cpp b/scumm/imuse.cpp index 0805ccc83f..c79350c60f 100644 --- a/scumm/imuse.cpp +++ b/scumm/imuse.cpp @@ -31,6 +31,10 @@ // the most common iMuse diagnostic messages. // #define IMUSE_DEBUG +// Unremark this statement to support simultaneous +// use of Adlib and native MIDI drivers. +// #define ADLIB_TOO + // // Some constants // @@ -330,7 +334,6 @@ private: bool isMT32(int sound); bool isGM(int sound); int get_queue_sound_status(int sound); - Player *allocate_player(byte priority); void handle_marker(uint id, byte data); int get_channel_volume(uint a); void initMidiDriver (MidiDriver *midi); @@ -344,6 +347,8 @@ private: void expire_sustain_notes (MidiDriver *midi); void expire_volume_faders (MidiDriver *midi); + MidiDriver *getBestMidiDriver (int sound); + Player *allocate_player(byte priority); Part *allocate_part(byte pri, MidiDriver *midi); int32 ImSetTrigger (int sound, int id, int a, int b, int c, int d); @@ -606,6 +611,37 @@ bool IMuseInternal::isGM(int sound) { return false; } +MidiDriver *IMuseInternal::getBestMidiDriver (int sound) { + MidiDriver *driver = NULL; + + if (isGM (sound)) { + if (_midi_native) { + driver = _midi_native; +#if !defined(__PALM_OS__) // Adlib not supported on PalmOS + } else { + // Route it through Adlib anyway. + if (!_midi_adlib) { + _midi_adlib = MidiDriver_ADLIB_create(); + initMidiDriver (_midi_adlib); + } + driver = _midi_adlib; +#endif + } +#if !defined(__PALM_OS__) // Adlib not supported on PalmOS + } else { + if (!_midi_adlib) { +#if !defined(ADLIB_TOO) + if (_midi_native) return NULL; +#endif + _midi_adlib = MidiDriver_ADLIB_create(); + initMidiDriver (_midi_adlib); + } + driver = _midi_adlib; +#endif + } + return driver; +} + bool IMuseInternal::startSound(int sound) { Player *player; void *mdhd; @@ -632,6 +668,12 @@ bool IMuseInternal::startSound(int sound) { } } + // Check which MIDI driver this track should use. + // If it's NULL, it ain't something we can play. + MidiDriver *driver = getBestMidiDriver (sound); + if (!driver) + return false; + // If the requested sound is already playing, start it over // from scratch. This was originally a hack to prevent Sam & Max // iMuse messiness while upgrading the iMuse engine, but it @@ -650,7 +692,7 @@ bool IMuseInternal::startSound(int sound) { return false; player->clear(); - return player->startSound (sound, _midi_native); + return player->startSound (sound, driver); } @@ -1615,20 +1657,19 @@ void IMuseInternal::setBase(byte **base) { _base_sounds = base; } -IMuseInternal *IMuseInternal::create(OSystem *syst, MidiDriver *midi) { +IMuseInternal *IMuseInternal::create (OSystem *syst, MidiDriver *native_midi) { IMuseInternal *i = new IMuseInternal; - i->initialize(syst, midi); + i->initialize(syst, native_midi); return i; } -int IMuseInternal::initialize(OSystem *syst, MidiDriver *midi) { +int IMuseInternal::initialize(OSystem *syst, MidiDriver *native_midi) { int i; - if (midi == NULL) - error ("IMuse was initialized without a MIDI driver (even the NULL driver)"); - - _midi_native = midi; - initMidiDriver (_midi_native); + _midi_native = native_midi; + _midi_adlib = NULL; + if (native_midi) + initMidiDriver (_midi_native); _master_volume = 255; if (_music_volume < 1) @@ -1839,7 +1880,10 @@ void Player::uninit_parts() { error("asd"); while (_parts) _parts->uninit(); - _se->reallocateMidiChannels (_midi); // In case another player couldn't allocate all its parts + + // In case another player is waiting to allocate parts + if (_midi) + _se->reallocateMidiChannels (_midi); } void Player::uninit_seq() { @@ -3000,8 +3044,12 @@ int IMuseInternal::save_or_load(Serializer *ser, Scumm *scumm) { init_sustaining_notes(); _active_volume_faders = true; fix_parts_after_load(); - reallocateMidiChannels (_midi_native); set_master_volume (_master_volume); + + if (_midi_native) + reallocateMidiChannels (_midi_native); + if (_midi_adlib) + reallocateMidiChannels (_midi_adlib); } return 0; @@ -3028,11 +3076,15 @@ void IMuseInternal::fix_players_after_load(Scumm *scumm) { for (i = ARRAYSIZE(_players); i != 0; i--, player++) { if (player->_active) { - player->set_tempo(player->_tempo); scumm->getResourceAddress(rtSound, player->_id); - player->_mt32emulate = isMT32(player->_id); - player->_isGM = isGM(player->_id); - player->_midi = _midi_native; + player->_midi = getBestMidiDriver (player->_id); + if (player->_midi == NULL) { + player->clear(); + } else { + player->set_tempo(player->_tempo); + player->_mt32emulate = isMT32(player->_id); + player->_isGM = isGM(player->_id); + } } } } diff --git a/scumm/resource.cpp b/scumm/resource.cpp index 54b2884745..75f15a0406 100644 --- a/scumm/resource.cpp +++ b/scumm/resource.cpp @@ -723,21 +723,18 @@ int Scumm::readSoundResource(int type, int idx) { pri = 15; break; case MKID('ADL '): -// pri = 1; + pri = 1; if (_use_adlib) pri = 10; break; case MKID('ROL '): -// if (!_use_adlib) - pri = 3; + pri = 3; break; case MKID('GMD '): -// if (!_use_adlib) - pri = 4; + pri = 4; break; case MKID('MAC '): -// if (!_use_adlib) - pri = 2; + pri = 2; break; case MKID('SPK '): pri = -1; |