diff options
Diffstat (limited to 'engines/parallaction/sound_ns.cpp')
-rw-r--r-- | engines/parallaction/sound_ns.cpp | 69 |
1 files changed, 19 insertions, 50 deletions
diff --git a/engines/parallaction/sound_ns.cpp b/engines/parallaction/sound_ns.cpp index 8f3f0c39e6..ba81314da6 100644 --- a/engines/parallaction/sound_ns.cpp +++ b/engines/parallaction/sound_ns.cpp @@ -42,74 +42,52 @@ namespace Parallaction { class MidiPlayer : public Audio::MidiPlayer { public: - MidiPlayer(MidiDriver *driver); - ~MidiPlayer(); + MidiPlayer(); void play(Common::SeekableReadStream *stream); - void stop(); void pause(bool p); - void updateTimer(); + virtual void onTimer(); private: - static void timerCallback(void *p); - - uint8 *_midiData; bool _paused; }; -MidiPlayer::MidiPlayer(MidiDriver *driver) - : _midiData(0), _paused(false) { - assert(driver); - _driver = driver; +MidiPlayer::MidiPlayer() + : _paused(false) { + + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); + _driver = MidiDriver::createMidi(dev); + assert(_driver); int ret = _driver->open(); if (ret == 0) { - _parser = MidiParser::createParser_SMF(); - _parser->setMidiDriver(this); - _parser->setTimerRate(_driver->getBaseTempo()); _driver->setTimerCallback(this, &timerCallback); } } -MidiPlayer::~MidiPlayer() { - stop(); - +void MidiPlayer::play(Common::SeekableReadStream *stream) { Common::StackLock lock(_mutex); - _driver->setTimerCallback(NULL, NULL); - _driver->close(); - delete _driver; - _driver = 0; - _parser->setMidiDriver(NULL); - delete _parser; -} -void MidiPlayer::play(Common::SeekableReadStream *stream) { - if (!stream) { - stop(); + stop(); + if (!stream) return; - } int size = stream->size(); - _midiData = (uint8 *)malloc(size); if (_midiData) { stream->read(_midiData, size); delete stream; - Common::StackLock lock(_mutex); + _parser = MidiParser::createParser_SMF(); _parser->loadMusic(_midiData, size); _parser->setTrack(0); + _parser->setMidiDriver(this); + _parser->setTimerRate(_driver->getBaseTempo()); _isLooping = true; _isPlaying = true; } } -void MidiPlayer::stop() { - Audio::MidiPlayer::stop(); - free(_midiData); - _midiData = 0; -} - void MidiPlayer::pause(bool p) { _paused = p; @@ -120,25 +98,16 @@ void MidiPlayer::pause(bool p) { } } -void MidiPlayer::updateTimer() { - if (_paused) { - return; - } - +void MidiPlayer::onTimer() { Common::StackLock lock(_mutex); - if (_isPlaying) { + + if (!_paused && _isPlaying && _parser) { _parser->onTimer(); } } -void MidiPlayer::timerCallback(void *p) { - MidiPlayer *player = (MidiPlayer *)p; - - player->updateTimer(); -} - -DosSoundMan_ns::DosSoundMan_ns(Parallaction_ns *vm, MidiDriver *midiDriver) : SoundMan_ns(vm), _playing(false) { - _midiPlayer = new MidiPlayer(midiDriver); +DosSoundMan_ns::DosSoundMan_ns(Parallaction_ns *vm) : SoundMan_ns(vm), _playing(false) { + _midiPlayer = new MidiPlayer(); } DosSoundMan_ns::~DosSoundMan_ns() { |