diff options
author | Max Horn | 2011-03-25 14:10:02 +0100 |
---|---|---|
committer | Max Horn | 2011-03-25 14:15:53 +0100 |
commit | 7949d7c6def2df6f3d44db4f55e9d1d3a87a0412 (patch) | |
tree | 85af1d8a79db595115afe67bd1fa0b216509bb8d /engines/agi | |
parent | db3802b02140d80e1a4e8ead91c1b7e39ee940c5 (diff) | |
download | scummvm-rg350-7949d7c6def2df6f3d44db4f55e9d1d3a87a0412.tar.gz scummvm-rg350-7949d7c6def2df6f3d44db4f55e9d1d3a87a0412.tar.bz2 scummvm-rg350-7949d7c6def2df6f3d44db4f55e9d1d3a87a0412.zip |
AUDIO: Move more common code to Audio::MidiPlayer
This also should fix some regressions from the previous
commits, related to MidiParser's either being leaked,
or being deleted and then used again (i.e., crashing).
I tested as many games as I had available, but further
testing of all affected engines is called for anyway.
Diffstat (limited to 'engines/agi')
-rw-r--r-- | engines/agi/sound_midi.cpp | 37 | ||||
-rw-r--r-- | engines/agi/sound_midi.h | 13 |
2 files changed, 13 insertions, 37 deletions
diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp index 2c6a189fbd..ff23a70808 100644 --- a/engines/agi/sound_midi.cpp +++ b/engines/agi/sound_midi.cpp @@ -90,24 +90,11 @@ SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, p else _driver->sendGMReset(); - _driver->setTimerCallback(this, &onTimer); + // FIXME: We need to cast "this" here due to the effects of + // multiple inheritance. This hack can go away once this + // setTimerCallback() has been moved inside Audio::MidiPlayer code. + _driver->setTimerCallback(static_cast<Audio::MidiPlayer *>(this), &timerCallback); } - - _smfParser = MidiParser::createParser_SMF(); - _midiMusicData = NULL; -} - -SoundGenMIDI::~SoundGenMIDI() { - _driver->setTimerCallback(NULL, NULL); - stop(); - if (_driver) { - _driver->close(); - delete _driver; - _driver = 0; - } - _smfParser->setMidiDriver(NULL); - delete _smfParser; - delete[] _midiMusicData; } void SoundGenMIDI::send(uint32 b) { @@ -136,14 +123,6 @@ void SoundGenMIDI::endOfTrack() { _vm->_sound->soundIsFinished(); } -void SoundGenMIDI::onTimer(void *refCon) { - SoundGenMIDI *music = (SoundGenMIDI *)refCon; - Common::StackLock lock(music->_mutex); - - if (music->_parser) - music->_parser->onTimer(); -} - void SoundGenMIDI::play(int resnum) { MIDISound *track; @@ -154,10 +133,10 @@ void SoundGenMIDI::play(int resnum) { track = (MIDISound *)_vm->_game.sounds[resnum]; // Convert AGI Sound data to MIDI - int midiMusicSize = convertSND2MIDI(track->_data, &_midiMusicData); + int midiMusicSize = convertSND2MIDI(track->_data, &_midiData); - if (_smfParser->loadMusic(_midiMusicData, midiMusicSize)) { - MidiParser *parser = _smfParser; + MidiParser *parser = MidiParser::createParser_SMF(); + if (parser->loadMusic(_midiData, midiMusicSize)) { parser->setTrack(0); parser->setMidiDriver(this); parser->setTimerRate(_driver->getBaseTempo()); @@ -168,6 +147,8 @@ void SoundGenMIDI::play(int resnum) { syncVolume(); _isPlaying = true; + } else { + delete parser; } } diff --git a/engines/agi/sound_midi.h b/engines/agi/sound_midi.h index 9551673a4e..5733358fee 100644 --- a/engines/agi/sound_midi.h +++ b/engines/agi/sound_midi.h @@ -28,6 +28,8 @@ #ifndef AGI_SOUND_MIDI_H #define AGI_SOUND_MIDI_H +#include "agi/sound.h" + #include "audio/midiplayer.h" namespace Agi { @@ -47,13 +49,12 @@ protected: class SoundGenMIDI : public SoundGen, public Audio::MidiPlayer { public: SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer); - ~SoundGenMIDI(); void play(int resnum); + // We must overload stop() here to implement the pure virtual + // stop() method of the SoundGen class. void stop() { Audio::MidiPlayer::stop(); } - void setGM(bool isGM) { _isGM = isGM; } - // MidiDriver_BASE interface implementation virtual void send(uint32 b); @@ -62,14 +63,8 @@ public: virtual void endOfTrack(); private: - - static void onTimer(void *data); - - MidiParser *_smfParser; bool _isGM; - byte *_midiMusicData; - SoundMgr *_manager; }; |