aboutsummaryrefslogtreecommitdiff
path: root/engines/made
diff options
context:
space:
mode:
authorMax Horn2011-03-23 16:14:39 +0100
committerMax Horn2011-03-23 16:49:41 +0100
commite70fd59b3505619cccb6f3280a4cf0fb57aefa97 (patch)
tree055c9719a41c4706baa4e5c4837e5fd31da95486 /engines/made
parent29847ea42da3e597d3496972c80ce49bea76da20 (diff)
downloadscummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.tar.gz
scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.tar.bz2
scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.zip
ENGINES: Further simplify pseudo MidiDrivers; fix some regressions
The regression affected AGOS and maybe some others; specifically, the real MidiDriver would have been deleted twice -- I previously missed that the Engine instances takes care of freeing the real MidiDriver, not the MidiPlayer wrapping it. This commit should clarify the ownership of the real MidiDriver for most pseudo MidiDrivers.
Diffstat (limited to 'engines/made')
-rw-r--r--engines/made/made.cpp13
-rw-r--r--engines/made/music.cpp54
-rw-r--r--engines/made/music.h20
3 files changed, 34 insertions, 53 deletions
diff --git a/engines/made/made.cpp b/engines/made/made.cpp
index 1c8d54aada..c81fa3db25 100644
--- a/engines/made/made.cpp
+++ b/engines/made/made.cpp
@@ -100,18 +100,7 @@ MadeEngine::MadeEngine(OSystem *syst, const MadeGameDescription *gameDesc) : Eng
_script = new ScriptInterpreter(this);
- MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
- bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
- //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB);
-
- MidiDriver *driver = MidiDriver::createMidi(dev);
- if (native_mt32)
- driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
-
- _music = new MusicPlayer(driver);
- _music->setNativeMT32(native_mt32);
- _music->open();
- //_music->setAdLib(adlib);
+ _music = new MusicPlayer();
// Set default sound frequency
switch (getGameID()) {
diff --git a/engines/made/music.cpp b/engines/made/music.cpp
index acb37bc951..779b7d6fe9 100644
--- a/engines/made/music.cpp
+++ b/engines/made/music.cpp
@@ -37,17 +37,40 @@
namespace Made {
-MusicPlayer::MusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
+MusicPlayer::MusicPlayer() : _parser(0), _driver(0), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
+ MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
+ _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
+ //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB);
+
+ _driver = MidiDriver::createMidi(dev);
+ assert(_driver);
+ if (_nativeMT32)
+ _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
+
memset(_channel, 0, sizeof(_channel));
_masterVolume = 0;
_xmidiParser = MidiParser::createParser_XMIDI();
_smfParser = MidiParser::createParser_SMF();
+
+ int ret = _driver->open();
+ if (ret == 0) {
+ if (_nativeMT32)
+ _driver->sendMT32Reset();
+ else
+ _driver->sendGMReset();
+
+ _driver->setTimerCallback(this, &onTimer);
+ }
}
MusicPlayer::~MusicPlayer() {
_driver->setTimerCallback(NULL, NULL);
stop();
- this->close();
+ if (_driver) {
+ _driver->close();
+ delete _driver;
+ _driver = 0;
+ }
_xmidiParser->setMidiDriver(NULL);
_smfParser->setMidiDriver(NULL);
delete _xmidiParser;
@@ -71,33 +94,6 @@ void MusicPlayer::setVolume(int volume) {
}
}
-int MusicPlayer::open() {
- // Don't ever call open without first setting the output driver!
- if (!_driver)
- return 255;
-
- int ret = _driver->open();
- if (ret)
- return ret;
-
- if (_nativeMT32)
- _driver->sendMT32Reset();
- else
- _driver->sendGMReset();
-
- _driver->setTimerCallback(this, &onTimer);
- return 0;
-}
-
-void MusicPlayer::close() {
- stop();
- if (_driver) {
- _driver->close();
- delete _driver;
- }
- _driver = 0;
-}
-
void MusicPlayer::send(uint32 b) {
if (_passThrough) {
_driver->send(b);
diff --git a/engines/made/music.h b/engines/made/music.h
index 6bd4da470e..b52a8116b5 100644
--- a/engines/made/music.h
+++ b/engines/made/music.h
@@ -43,7 +43,7 @@ enum MusicFlags {
class MusicPlayer : public MidiDriver_BASE {
public:
- MusicPlayer(MidiDriver *driver);
+ MusicPlayer();
~MusicPlayer();
bool isPlaying() { return _isPlaying; }
@@ -52,8 +52,7 @@ public:
void setVolume(int volume);
int getVolume() { return _masterVolume; }
- void setNativeMT32(bool b) { _nativeMT32 = b; }
- bool hasNativeMT32() { return _nativeMT32; }
+ bool hasNativeMT32() const { return _nativeMT32; }
void playXMIDI(GenericResource *midiResource, MusicFlags flags = MUSIC_NORMAL);
void playSMF(GenericResource *midiResource, MusicFlags flags = MUSIC_NORMAL);
void stop();
@@ -64,20 +63,17 @@ public:
void setGM(bool isGM) { _isGM = isGM; }
- //MidiDriver interface implementation
- int open();
- void close();
- void send(uint32 b);
-
- void metaEvent(byte type, byte *data, uint16 length);
-
- MidiParser *_parser;
- Common::Mutex _mutex;
+ // MidiDriver_BASE interface implementation
+ virtual void send(uint32 b);
+ virtual void metaEvent(byte type, byte *data, uint16 length);
protected:
static void onTimer(void *data);
+ MidiParser *_parser;
+ Common::Mutex _mutex;
+
MidiChannel *_channel[16];
MidiDriver *_driver;
MidiParser *_xmidiParser, *_smfParser;