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/touche | |
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/touche')
-rw-r--r-- | engines/touche/midi.cpp | 58 | ||||
-rw-r--r-- | engines/touche/midi.h | 8 |
2 files changed, 28 insertions, 38 deletions
diff --git a/engines/touche/midi.cpp b/engines/touche/midi.cpp index c6c7a60dfd..4349a29bf5 100644 --- a/engines/touche/midi.cpp +++ b/engines/touche/midi.cpp @@ -36,11 +36,34 @@ MidiPlayer::MidiPlayer() : _driver(0), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _masterVolume(0) { memset(_channelsTable, 0, sizeof(_channelsTable)); memset(_channelsVolume, 0, sizeof(_channelsVolume)); - open(); + + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); + _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); + _driver = MidiDriver::createMidi(dev); + int ret = _driver->open(); + if (ret == 0) { + _parser = MidiParser::createParser_SMF(); + _parser->setMidiDriver(this); + _parser->setTimerRate(_driver->getBaseTempo()); + _driver->setTimerCallback(this, &timerCallback); + + if (_nativeMT32) + _driver->sendMT32Reset(); + else + _driver->sendGMReset(); + } } MidiPlayer::~MidiPlayer() { - close(); + stop(); + + Common::StackLock lock(_mutex); + _driver->setTimerCallback(NULL, NULL); + _driver->close(); + delete _driver; + _driver = 0; + _parser->setMidiDriver(NULL); + delete _parser; } void MidiPlayer::play(Common::ReadStream &stream, int size, bool loop) { @@ -88,37 +111,6 @@ void MidiPlayer::setVolume(int volume) { } } -int MidiPlayer::open() { - MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); - _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); - _driver = MidiDriver::createMidi(dev); - int ret = _driver->open(); - if (ret == 0) { - _parser = MidiParser::createParser_SMF(); - _parser->setMidiDriver(this); - _parser->setTimerRate(_driver->getBaseTempo()); - _driver->setTimerCallback(this, &timerCallback); - - if (_nativeMT32) - _driver->sendMT32Reset(); - else - _driver->sendGMReset(); - } - return ret; -} - -void MidiPlayer::close() { - stop(); - - Common::StackLock lock(_mutex); - _driver->setTimerCallback(NULL, NULL); - _driver->close(); - delete _driver; - _driver = 0; - _parser->setMidiDriver(NULL); - delete _parser; -} - void MidiPlayer::send(uint32 b) { byte volume, ch = (byte)(b & 0xF); switch (b & 0xFFF0) { diff --git a/engines/touche/midi.h b/engines/touche/midi.h index a750f12bec..bc5adc6b5f 100644 --- a/engines/touche/midi.h +++ b/engines/touche/midi.h @@ -57,11 +57,9 @@ public: int getVolume() const { return _masterVolume; } void setLooping(bool loop) { _isLooping = loop; } - // MidiDriver interface - int open(); - void close(); - void send(uint32 b); - void metaEvent(byte type, byte *data, uint16 length); + // MidiDriver_BASE interface + virtual void send(uint32 b); + virtual void metaEvent(byte type, byte *data, uint16 length); private: |