diff options
Diffstat (limited to 'engines/parallaction/sound_br.cpp')
-rw-r--r-- | engines/parallaction/sound_br.cpp | 73 |
1 files changed, 21 insertions, 52 deletions
diff --git a/engines/parallaction/sound_br.cpp b/engines/parallaction/sound_br.cpp index 1bc085fd34..ee53f9641e 100644 --- a/engines/parallaction/sound_br.cpp +++ b/engines/parallaction/sound_br.cpp @@ -204,94 +204,69 @@ MidiParser *createParser_MSC() { class MidiPlayer_MSC : public Audio::MidiPlayer { public: - MidiPlayer_MSC(MidiDriver *driver); - ~MidiPlayer_MSC(); + MidiPlayer_MSC(); void play(Common::SeekableReadStream *stream); - void stop(); - void pause(bool p); - void updateTimer(); - void setVolume(int volume); + virtual void pause(bool p); + virtual void setVolume(int volume); + virtual void onTimer(); // MidiDriver_BASE interface virtual void send(uint32 b); -private: - static void timerCallback(void *p); +private: void setVolumeInternal(int volume); - - uint8 *_midiData; bool _paused; }; -MidiPlayer_MSC::MidiPlayer_MSC(MidiDriver *driver) - : _midiData(0), _paused(false) { - _driver = driver; +MidiPlayer_MSC::MidiPlayer_MSC() + : _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 = createParser_MSC(); - _parser->setMidiDriver(this); - _parser->setTimerRate(_driver->getBaseTempo()); _driver->setTimerCallback(this, &timerCallback); } } -MidiPlayer_MSC::~MidiPlayer_MSC() { - stop(); - +void MidiPlayer_MSC::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_MSC::play(Common::SeekableReadStream *stream) { - if (!stream) { - stop(); + stop(); + if (!stream) return; - } - stop(); int size = stream->size(); _midiData = (uint8 *)malloc(size); if (_midiData) { stream->read(_midiData, size); delete stream; - Common::StackLock lock(_mutex); + _parser = createParser_MSC(); _parser->loadMusic(_midiData, size); _parser->setTrack(0); + _parser->setMidiDriver(this); + _parser->setTimerRate(_driver->getBaseTempo()); _isLooping = true; _isPlaying = true; } } -void MidiPlayer_MSC::stop() { - Audio::MidiPlayer::stop(); - free(_midiData); - _midiData = 0; -} - void MidiPlayer_MSC::pause(bool p) { _paused = p; setVolumeInternal(_paused ? 0 : _masterVolume); } -void MidiPlayer_MSC::updateTimer() { - if (_paused) { - return; - } - +void MidiPlayer_MSC::onTimer() { Common::StackLock lock(_mutex); - if (_isPlaying) { + + if (!_paused && _isPlaying && _parser) { _parser->onTimer(); } } @@ -327,14 +302,8 @@ void MidiPlayer_MSC::send(uint32 b) { sendToChannel(ch, b); } -void MidiPlayer_MSC::timerCallback(void *p) { - MidiPlayer_MSC *player = (MidiPlayer_MSC *)p; - - player->updateTimer(); -} - -DosSoundMan_br::DosSoundMan_br(Parallaction_br *vm, MidiDriver *driver) : SoundMan_br(vm) { - _midiPlayer = new MidiPlayer_MSC(driver); +DosSoundMan_br::DosSoundMan_br(Parallaction_br *vm) : SoundMan_br(vm) { + _midiPlayer = new MidiPlayer_MSC(); assert(_midiPlayer); } |