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/tinsel | |
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/tinsel')
-rw-r--r-- | engines/tinsel/music.cpp | 51 | ||||
-rw-r--r-- | engines/tinsel/music.h | 12 | ||||
-rw-r--r-- | engines/tinsel/tinsel.cpp | 18 |
3 files changed, 31 insertions, 50 deletions
diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp index 3e0d87bbb8..235f03ada8 100644 --- a/engines/tinsel/music.cpp +++ b/engines/tinsel/music.cpp @@ -386,18 +386,41 @@ void DeleteMidiBuffer() { midiBuffer.pDat = NULL; } -MidiMusicPlayer::MidiMusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _looping(false), _isPlaying(false) { +MidiMusicPlayer::MidiMusicPlayer() : _parser(0), _driver(0), _looping(false), _isPlaying(false) { + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); + bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); + //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB); + + _driver = MidiDriver::createMidi(dev); + assert(_driver); + if (native_mt32) + _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); + memset(_channel, 0, sizeof(_channel)); memset(_channelVolume, 0, sizeof(_channelVolume)); _masterVolume = 0; - this->open(); + + int ret = _driver->open(); + if (ret == 0) { + if (native_mt32) + _driver->sendMT32Reset(); + else + _driver->sendGMReset(); + + _driver->setTimerCallback(this, &onTimer); + } + _xmidiParser = MidiParser::createParser_XMIDI(); } MidiMusicPlayer::~MidiMusicPlayer() { _driver->setTimerCallback(NULL, NULL); stop(); - this->close(); + if (_driver) { + _driver->close(); + delete _driver; + _driver = 0; + } _xmidiParser->setMidiDriver(NULL); delete _xmidiParser; } @@ -419,28 +442,6 @@ void MidiMusicPlayer::setVolume(int volume) { } } -int MidiMusicPlayer::open() { - // Don't ever call open without first setting the output driver! - if (!_driver) - return 255; - - int ret = _driver->open(); - if (ret) - return ret; - - _driver->setTimerCallback(this, &onTimer); - return 0; -} - -void MidiMusicPlayer::close() { - stop(); - if (_driver) { - _driver->close(); - delete _driver; - } - _driver = 0; -} - void MidiMusicPlayer::send(uint32 b) { byte channel = (byte)(b & 0x0F); if ((b & 0xFFF0) == 0x07B0) { diff --git a/engines/tinsel/music.h b/engines/tinsel/music.h index a75f2b8617..1857032a6d 100644 --- a/engines/tinsel/music.h +++ b/engines/tinsel/music.h @@ -62,7 +62,7 @@ void dumpMusic(); class MidiMusicPlayer : public MidiDriver_BASE { public: - MidiMusicPlayer(MidiDriver *driver); + MidiMusicPlayer(); ~MidiMusicPlayer(); bool isPlaying() { return _isPlaying; } @@ -78,16 +78,12 @@ public: void resume(); void setLoop(bool loop) { _looping = loop; } - //MidiDriver interface implementation - int open(); - void close(); - void send(uint32 b); - - void metaEvent(byte type, byte *data, uint16 length); + // MidiDriver_BASE interface implementation + virtual void send(uint32 b); + virtual void metaEvent(byte type, byte *data, uint16 length); // The original sets the "sequence timing" to 109 Hz, whatever that // means. The default is 120. - uint32 getBaseTempo() { return _driver ? (109 * _driver->getBaseTempo()) / 120 : 0; } protected: diff --git a/engines/tinsel/tinsel.cpp b/engines/tinsel/tinsel.cpp index 23335539d1..ef0fe1c909 100644 --- a/engines/tinsel/tinsel.cpp +++ b/engines/tinsel/tinsel.cpp @@ -856,23 +856,8 @@ TinselEngine::TinselEngine(OSystem *syst, const TinselGameDescription *gameDesc) if (cd_num >= 0) _system->getAudioCDManager()->openCD(cd_num); - MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); - bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); - //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB); - - _driver = MidiDriver::createMidi(dev); - if (native_mt32) - _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); - - _midiMusic = new MidiMusicPlayer(_driver); + _midiMusic = new MidiMusicPlayer(); _pcmMusic = new PCMMusicPlayer(); - //_midiMusic->setNativeMT32(native_mt32); - //_midiMusic->setAdLib(adlib); - - if (native_mt32) - _driver->sendMT32Reset(); - else - _driver->sendGMReset(); _musicVolume = ConfMan.getInt("music_volume"); @@ -896,7 +881,6 @@ TinselEngine::~TinselEngine() { delete _midiMusic; delete _pcmMusic; delete _console; - delete _driver; _screenSurface.free(); FreeSaveScenes(); FreeTextBuffer(); |