aboutsummaryrefslogtreecommitdiff
path: root/engines/m4
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/m4
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/m4')
-rw-r--r--engines/m4/midi.cpp55
-rw-r--r--engines/m4/midi.h5
2 files changed, 9 insertions, 51 deletions
diff --git a/engines/m4/midi.cpp b/engines/m4/midi.cpp
index b982fc8129..d58b92bf01 100644
--- a/engines/m4/midi.cpp
+++ b/engines/m4/midi.cpp
@@ -34,7 +34,7 @@
namespace M4 {
-MidiPlayer::MidiPlayer(MadsM4Engine *vm) : _vm(vm), _midiData(NULL), _isGM(false) {
+MidiPlayer::MidiPlayer(MadsM4Engine *vm) : _vm(vm), _isGM(false) {
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
_nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
@@ -44,26 +44,10 @@ MidiPlayer::MidiPlayer(MadsM4Engine *vm) : _vm(vm), _midiData(NULL), _isGM(false
if (_nativeMT32)
_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
- _parser = MidiParser::createParser_SMF();
- _parser->setMidiDriver(this);
- _parser->setTimerRate(_driver->getBaseTempo());
-
int ret = _driver->open();
- if (ret == 0)
- _driver->setTimerCallback(this, &onTimer);
-}
-
-MidiPlayer::~MidiPlayer() {
- _driver->setTimerCallback(NULL, NULL);
- _parser->setMidiDriver(NULL);
- stop();
- if (_driver) {
- _driver->close();
- delete _driver;
+ if (ret == 0) {
+ _driver->setTimerCallback(this, &timerCallback);
}
- _driver = 0;
- delete _parser;
- free(_midiData);
}
void MidiPlayer::send(uint32 b) {
@@ -74,15 +58,9 @@ void MidiPlayer::send(uint32 b) {
Audio::MidiPlayer::send(b);
}
-void MidiPlayer::onTimer(void *refCon) {
- MidiPlayer *midi = (MidiPlayer *)refCon;
- Common::StackLock lock(midi->_mutex);
-
- if (midi->_isPlaying)
- midi->_parser->onTimer();
-}
-
void MidiPlayer::playMusic(const char *name, int32 vol, bool loop, int32 trigger, int32 scene) {
+ Common::StackLock lock(_mutex);
+
stop();
char fullname[144];
@@ -99,11 +77,10 @@ void MidiPlayer::playMusic(const char *name, int32 vol, bool loop, int32 trigger
_vm->res()->purge();
if (_midiData) {
- /*
- FILE *out = fopen("music.mid", "wb");
- fwrite(_midiData, smfSize, 1, out);
- fclose(out);
- */
+ _parser = MidiParser::createParser_SMF();
+ _parser->setMidiDriver(this);
+ _parser->setTimerRate(_driver->getBaseTempo());
+
_parser->loadMusic(_midiData, smfSize);
_parser->property(MidiParser::mpAutoLoop, loop);
}
@@ -113,20 +90,6 @@ void MidiPlayer::playMusic(const char *name, int32 vol, bool loop, int32 trigger
_isPlaying = true;
}
-void MidiPlayer::stop() {
- Common::StackLock lock(_mutex);
-
- _isPlaying = false;
- if (_parser) {
- _parser->unloadMusic();
- }
-
- if (_midiData) {
- free(_midiData);
- _midiData = NULL;
- }
-}
-
// This function will convert HMP music into type 1 SMF, which our SMF parser
// will be able to handle. It is based on Hans de Goede's HMP 2 MIDI file
// converter, which in turn is "based on the conversion algorithms found in
diff --git a/engines/m4/midi.h b/engines/m4/midi.h
index e1f92cd4b6..a544fb72aa 100644
--- a/engines/m4/midi.h
+++ b/engines/m4/midi.h
@@ -35,10 +35,8 @@ namespace M4 {
class MidiPlayer : public Audio::MidiPlayer {
public:
MidiPlayer(MadsM4Engine *vm);
- ~MidiPlayer();
void playMusic(const char *name, int32 vol, bool loop, int32 trigger, int32 scene);
- virtual void stop();
void setGM(bool isGM) { _isGM = isGM; }
@@ -46,10 +44,7 @@ public:
virtual void send(uint32 b);
protected:
- static void onTimer(void *data);
-
MadsM4Engine *_vm;
- byte *_midiData;
bool _isGM;