aboutsummaryrefslogtreecommitdiff
path: root/engines/touche
diff options
context:
space:
mode:
authorMax Horn2011-03-25 14:10:02 +0100
committerMax Horn2011-03-25 14:15:53 +0100
commit7949d7c6def2df6f3d44db4f55e9d1d3a87a0412 (patch)
tree85af1d8a79db595115afe67bd1fa0b216509bb8d /engines/touche
parentdb3802b02140d80e1a4e8ead91c1b7e39ee940c5 (diff)
downloadscummvm-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/touche')
-rw-r--r--engines/touche/midi.cpp43
-rw-r--r--engines/touche/midi.h9
2 files changed, 7 insertions, 45 deletions
diff --git a/engines/touche/midi.cpp b/engines/touche/midi.cpp
index bdf57880b8..c89375d876 100644
--- a/engines/touche/midi.cpp
+++ b/engines/touche/midi.cpp
@@ -44,8 +44,7 @@ static const uint8 _gmToRol[256] = {
};
-MidiPlayer::MidiPlayer()
- : _midiData(0) {
+MidiPlayer::MidiPlayer() {
// FIXME: Necessary?
memset(_channelsVolume, 0, sizeof(_channelsVolume));
@@ -55,9 +54,6 @@ MidiPlayer::MidiPlayer()
_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)
@@ -67,25 +63,18 @@ MidiPlayer::MidiPlayer()
}
}
-MidiPlayer::~MidiPlayer() {
- stop();
-
+void MidiPlayer::play(Common::ReadStream &stream, int size, bool loop) {
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) {
stop();
- _midiData = (uint8 *)malloc(size);
+ _midiData = (byte *)malloc(size);
if (_midiData) {
stream.read(_midiData, size);
- Common::StackLock lock(_mutex);
+ _parser = MidiParser::createParser_SMF();
+ _parser->setMidiDriver(this);
+ _parser->setTimerRate(_driver->getBaseTempo());
+
_parser->loadMusic(_midiData, size);
_parser->setTrack(0);
_isLooping = loop;
@@ -93,19 +82,6 @@ void MidiPlayer::play(Common::ReadStream &stream, int size, bool loop) {
}
}
-void MidiPlayer::stop() {
- Audio::MidiPlayer::stop();
- free(_midiData);
- _midiData = 0;
-}
-
-void MidiPlayer::updateTimer() {
- Common::StackLock lock(_mutex);
- if (_isPlaying) {
- _parser->onTimer();
- }
-}
-
void MidiPlayer::adjustVolume(int diff) {
setVolume(_masterVolume + diff);
}
@@ -135,9 +111,4 @@ void MidiPlayer::send(uint32 b) {
Audio::MidiPlayer::send(b);
}
-void MidiPlayer::timerCallback(void *p) {
- MidiPlayer *player = (MidiPlayer *)p;
- player->updateTimer();
-}
-
} // Touche namespace
diff --git a/engines/touche/midi.h b/engines/touche/midi.h
index 8f2f8507b7..f0f55e64e6 100644
--- a/engines/touche/midi.h
+++ b/engines/touche/midi.h
@@ -42,22 +42,13 @@ namespace Touche {
class MidiPlayer : public Audio::MidiPlayer {
public:
MidiPlayer();
- ~MidiPlayer();
void play(Common::ReadStream &stream, int size, bool loop = false);
- void stop();
- void updateTimer();
void adjustVolume(int diff);
void setVolume(int volume);
// MidiDriver_BASE interface
virtual void send(uint32 b);
-
-private:
-
- static void timerCallback(void *p);
-
- uint8 *_midiData;
};
} // namespace Touche