diff options
author | Max Horn | 2011-03-23 16:14:39 +0100 |
---|---|---|
committer | Max Horn | 2011-03-23 16:49:41 +0100 |
commit | e70fd59b3505619cccb6f3280a4cf0fb57aefa97 (patch) | |
tree | 055c9719a41c4706baa4e5c4837e5fd31da95486 /engines/agos/midi.cpp | |
parent | 29847ea42da3e597d3496972c80ce49bea76da20 (diff) | |
download | scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.tar.gz scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.tar.bz2 scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.zip |
ENGINES: Further simplify pseudo MidiDrivers; fix some regressions
The regression affected AGOS and maybe some others; specifically,
the real MidiDriver would have been deleted twice -- I previously
missed that the Engine instances takes care of freeing the real
MidiDriver, not the MidiPlayer wrapping it.
This commit should clarify the ownership of the real MidiDriver for
most pseudo MidiDrivers.
Diffstat (limited to 'engines/agos/midi.cpp')
-rw-r--r-- | engines/agos/midi.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp index d76aa42ddc..234aa8d815 100644 --- a/engines/agos/midi.cpp +++ b/engines/agos/midi.cpp @@ -25,6 +25,7 @@ +#include "common/config-manager.h" #include "common/file.h" #include "common/system.h" @@ -62,15 +63,34 @@ MidiPlayer::MidiPlayer() { } MidiPlayer::~MidiPlayer() { + stop(); + Common::StackLock lock(_mutex); - close(); + if (_driver) { + _driver->close(); + delete _driver; + } + _driver = NULL; + clearConstructs(); } -int MidiPlayer::open() { - // Don't ever call open without first setting the output driver! +int MidiPlayer::open(int gameType) { + // Don't call open() twice! + assert(!_driver); + + // Setup midi driver + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_ADLIB | MDT_MIDI | (gameType == GType_SIMON1 ? MDT_PREFER_MT32 : MDT_PREFER_GM)); + _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); + + _driver = MidiDriver::createMidi(dev); if (!_driver) return 255; + if (_nativeMT32) + _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); + + _map_mt32_to_gm = (gameType != GType_SIMON2 && !_nativeMT32); + int ret = _driver->open(); if (ret) return ret; @@ -84,18 +104,6 @@ int MidiPlayer::open() { return 0; } -void MidiPlayer::close() { - stop(); -// _system->lockMutex(_mutex); - if (_driver) { - delete _driver; - _driver->close(); - } - _driver = NULL; - clearConstructs(); -// _system->unlockMutex(_mutex); -} - void MidiPlayer::send(uint32 b) { if (!_current) return; @@ -305,12 +313,6 @@ void MidiPlayer::setDriver(MidiDriver *md) { _driver = md; } -void MidiPlayer::mapMT32toGM(bool map) { - Common::StackLock lock(_mutex); - - _map_mt32_to_gm = map; -} - void MidiPlayer::setLoop(bool loop) { Common::StackLock lock(_mutex); |