From 8982fff1b79aa3cc53a5c328b283e0f102cb647f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Mar 2011 15:42:17 +0100 Subject: AUDIO: Add pure virtual MidiDriver::isOpen() method This in turn enables modifying MidiDriver_MPU401::close() to allow it to be called on a midi driver that has not yet been opened. The specific issue that triggered me to make these changes was a crash-upon-quit in HUGO, caused by it instantiating a midi driver, then encountering an error (missing hugo.dat) *before* having opened the new midi driver; the general cleanup code then tries to close the (not yet opened) midi driver -> kaboom Also fixed some engines which were leaking MidiDriver instances. --- audio/mididrv.h | 5 ++++ audio/mpu401.cpp | 11 +++++--- audio/null.h | 1 + audio/softsynth/adlib.cpp | 2 +- audio/softsynth/emumidi.h | 2 ++ backends/midi/alsa.cpp | 1 + backends/midi/camd.cpp | 1 + backends/midi/coreaudio.cpp | 17 +++++++++--- backends/midi/coremidi.cpp | 11 ++++---- backends/midi/dmedia.cpp | 3 ++- backends/midi/seq.cpp | 1 + backends/midi/stmidi.cpp | 39 ++++++++++++++------------- backends/midi/timidity.cpp | 49 +++++++++++++++++----------------- backends/midi/windows.cpp | 3 +++ engines/agi/sound_midi.cpp | 4 +++ engines/agi/sound_midi.h | 1 + engines/agos/midi.cpp | 8 +++++- engines/agos/midi.h | 1 + engines/draci/music.cpp | 8 +++++- engines/draci/music.h | 1 + engines/groovie/music.cpp | 4 +++ engines/groovie/music.h | 1 + engines/hugo/sound.cpp | 4 +++ engines/hugo/sound.h | 1 + engines/kyra/sound_midi.cpp | 1 + engines/lure/sound.cpp | 4 +++ engines/lure/sound.h | 1 + engines/m4/midi.cpp | 8 +++++- engines/m4/midi.h | 1 + engines/made/music.cpp | 8 +++++- engines/made/music.h | 1 + engines/parallaction/sound_br.cpp | 5 ++++ engines/parallaction/sound_ns.cpp | 5 ++++ engines/queen/music.cpp | 4 ++- engines/queen/music.h | 1 + engines/saga/music.cpp | 5 ++++ engines/saga/music.h | 1 + engines/sci/sound/drivers/mididriver.h | 1 + engines/scumm/imuse/imuse_internal.h | 1 + engines/tinsel/music.cpp | 8 +++++- engines/tinsel/music.h | 1 + engines/touche/midi.cpp | 4 +++ engines/touche/midi.h | 1 + 43 files changed, 175 insertions(+), 65 deletions(-) diff --git a/audio/mididrv.h b/audio/mididrv.h index eed8c419f3..f635472f0e 100644 --- a/audio/mididrv.h +++ b/audio/mididrv.h @@ -182,6 +182,11 @@ public: */ virtual int open() = 0; + /** + * Check whether the midi driver has already been opened. + */ + virtual bool isOpen() const = 0; + /** Close the midi driver. */ virtual void close() = 0; diff --git a/audio/mpu401.cpp b/audio/mpu401.cpp index 8d1e5b6047..4834772c07 100644 --- a/audio/mpu401.cpp +++ b/audio/mpu401.cpp @@ -105,11 +105,14 @@ MidiDriver_MPU401::~MidiDriver_MPU401() { } void MidiDriver_MPU401::close() { - if (_timer_proc) + if (_timer_proc) { g_system->getTimerManager()->removeTimerProc(_timer_proc); - _timer_proc = 0; - for (int i = 0; i < 16; ++i) - send(0x7B << 8 | 0xB0 | i); + _timer_proc = 0; + } + if (isOpen()) { + for (int i = 0; i < 16; ++i) + send(0x7B << 8 | 0xB0 | i); + } } uint32 MidiDriver_MPU401::property(int prop, uint32 param) { diff --git a/audio/null.h b/audio/null.h index 5df7493a06..8570d4d293 100644 --- a/audio/null.h +++ b/audio/null.h @@ -33,6 +33,7 @@ class MidiDriver_NULL : public MidiDriver_MPU401 { public: int open() { return 0; } + bool isOpen() const { return true; } void send(uint32 b) { } }; diff --git a/audio/softsynth/adlib.cpp b/audio/softsynth/adlib.cpp index 4a9ce54c75..9e863471f0 100644 --- a/audio/softsynth/adlib.cpp +++ b/audio/softsynth/adlib.cpp @@ -118,7 +118,7 @@ public: byte getNumber() { return _channel; } void release() { _allocated = false; } - void send (uint32 b); + void send(uint32 b); // Regular messages void noteOff(byte note); diff --git a/audio/softsynth/emumidi.h b/audio/softsynth/emumidi.h index 815c020982..190b70c392 100644 --- a/audio/softsynth/emumidi.h +++ b/audio/softsynth/emumidi.h @@ -76,6 +76,8 @@ public: return 0; } + bool isOpen() const { return _isOpen; } + virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _timerProc = timer_proc; _timerParam = timer_param; diff --git a/backends/midi/alsa.cpp b/backends/midi/alsa.cpp index feed60eaef..2257f60e27 100644 --- a/backends/midi/alsa.cpp +++ b/backends/midi/alsa.cpp @@ -71,6 +71,7 @@ class MidiDriver_ALSA : public MidiDriver_MPU401 { public: MidiDriver_ALSA(int client, int port); int open(); + bool isOpen() const { return _isOpen; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); diff --git a/backends/midi/camd.cpp b/backends/midi/camd.cpp index 57251b45e1..ee3baaadd2 100644 --- a/backends/midi/camd.cpp +++ b/backends/midi/camd.cpp @@ -46,6 +46,7 @@ class MidiDriver_CAMD : public MidiDriver_MPU401 { public: MidiDriver_CAMD(); int open(); + bool isOpen() const { return _isOpen; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp index 75c512cad7..0158cc4a1d 100644 --- a/backends/midi/coreaudio.cpp +++ b/backends/midi/coreaudio.cpp @@ -72,7 +72,9 @@ do { \ class MidiDriver_CORE : public MidiDriver_MPU401 { public: MidiDriver_CORE(); + ~MidiDriver_CORE(); int open(); + bool isOpen() const { return _auGraph != 0; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); @@ -86,10 +88,18 @@ MidiDriver_CORE::MidiDriver_CORE() : _auGraph(0) { } +MidiDriver_CORE::~MidiDriver_CORE() { + if (_auGraph) { + AUGraphStop(_auGraph); + DisposeAUGraph(_auGraph); + _auGraph = 0; + } +} + int MidiDriver_CORE::open() { OSStatus err = 0; - if (_auGraph) + if (isOpen()) return MERR_ALREADY_OPEN; // Open the Music Device. @@ -176,7 +186,6 @@ bail: void MidiDriver_CORE::close() { MidiDriver_MPU401::close(); - if (_auGraph) { AUGraphStop(_auGraph); DisposeAUGraph(_auGraph); @@ -185,7 +194,7 @@ void MidiDriver_CORE::close() { } void MidiDriver_CORE::send(uint32 b) { - assert(_auGraph != NULL); + assert(isOpen()); byte status_byte = (b & 0x000000FF); byte first_byte = (b & 0x0000FF00) >> 8; @@ -198,7 +207,7 @@ void MidiDriver_CORE::sysEx(const byte *msg, uint16 length) { unsigned char buf[266]; assert(length + 2 <= ARRAYSIZE(buf)); - assert(_auGraph != NULL); + assert(isOpen()); // Add SysEx frame buf[0] = 0xF0; diff --git a/backends/midi/coremidi.cpp b/backends/midi/coremidi.cpp index c0663352cb..9123c9bc8c 100644 --- a/backends/midi/coremidi.cpp +++ b/backends/midi/coremidi.cpp @@ -56,6 +56,7 @@ public: MidiDriver_CoreMIDI(); ~MidiDriver_CoreMIDI(); int open(); + bool isOpen() const { return mOutPort != 0 && mDest != 0; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); @@ -80,7 +81,7 @@ MidiDriver_CoreMIDI::~MidiDriver_CoreMIDI() { } int MidiDriver_CoreMIDI::open() { - if (mDest) + if (isOpen()) return MERR_ALREADY_OPEN; OSStatus err = noErr; @@ -106,7 +107,7 @@ int MidiDriver_CoreMIDI::open() { void MidiDriver_CoreMIDI::close() { MidiDriver_MPU401::close(); - if (mOutPort && mDest) { + if (isOpen()) { MIDIPortDispose(mOutPort); mOutPort = 0; mDest = 0; @@ -114,8 +115,7 @@ void MidiDriver_CoreMIDI::close() { } void MidiDriver_CoreMIDI::send(uint32 b) { - assert(mOutPort != 0); - assert(mDest != 0); + assert(isOpen()); // Extract the MIDI data byte status_byte = (b & 0x000000FF); @@ -158,8 +158,7 @@ void MidiDriver_CoreMIDI::send(uint32 b) { } void MidiDriver_CoreMIDI::sysEx(const byte *msg, uint16 length) { - assert(mOutPort != 0); - assert(mDest != 0); + assert(isOpen()); byte buf[384]; MIDIPacketList *packetList = (MIDIPacketList *)buf; diff --git a/backends/midi/dmedia.cpp b/backends/midi/dmedia.cpp index f0ab84c934..c4c1968354 100644 --- a/backends/midi/dmedia.cpp +++ b/backends/midi/dmedia.cpp @@ -57,6 +57,7 @@ class MidiDriver_DMEDIA : public MidiDriver_MPU401 { public: MidiDriver_DMEDIA(); int open(); + bool isOpen() const { return _isOpen; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); @@ -179,7 +180,7 @@ void MidiDriver_DMEDIA::sysEx (const byte *msg, uint16 length) { memcpy(buf, msg, length); buf[length] = MD_EOX; event.sysexmsg = buf; - event.msglen = length; + event.msglen = length; event.msg[0] = MD_SYSEX; event.msg[1] = 0; event.msg[2] = 0; diff --git a/backends/midi/seq.cpp b/backends/midi/seq.cpp index 064129b74a..7cd7f0a38e 100644 --- a/backends/midi/seq.cpp +++ b/backends/midi/seq.cpp @@ -55,6 +55,7 @@ class MidiDriver_SEQ : public MidiDriver_MPU401 { public: MidiDriver_SEQ(); int open(); + bool isOpen() const { return _isOpen; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); diff --git a/backends/midi/stmidi.cpp b/backends/midi/stmidi.cpp index 562c3c7ece..42f829a7a3 100644 --- a/backends/midi/stmidi.cpp +++ b/backends/midi/stmidi.cpp @@ -48,8 +48,9 @@ class MidiDriver_STMIDI : public MidiDriver_MPU401 { public: - MidiDriver_STMIDI() : _isOpen (false) { } + MidiDriver_STMIDI() : _isOpen (false) { } int open(); + bool isOpen() const { return _isOpen; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); @@ -59,7 +60,7 @@ private: }; int MidiDriver_STMIDI::open() { - if ((_isOpen) && (!Bcostat(4))) + if (_isOpen && (!Bcostat(4))) return MERR_ALREADY_OPEN; warning("ST Midi Port Open"); _isOpen = true; @@ -123,36 +124,36 @@ void MidiDriver_STMIDI::sysEx (const byte *msg, uint16 length) { class StMidiMusicPlugin : public MusicPluginObject { public: - const char *getName() const { - return "STMIDI"; - } + const char *getName() const { + return "STMIDI"; + } - const char *getId() const { - return "stmidi"; - } + const char *getId() const { + return "stmidi"; + } - MusicDevices getDevices() const; - Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const; + MusicDevices getDevices() const; + Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const; }; MusicDevices StMidiMusicPlugin::getDevices() const { - MusicDevices devices; - // TODO: Return a different music type depending on the configuration - // TODO: List the available devices - devices.push_back(MusicDevice(this, "", MT_GM)); - return devices; + MusicDevices devices; + // TODO: Return a different music type depending on the configuration + // TODO: List the available devices + devices.push_back(MusicDevice(this, "", MT_GM)); + return devices; } Common::Error StMidiMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const { - *mididriver = new MidiDriver_STMIDI(); + *mididriver = new MidiDriver_STMIDI(); - return Common::kNoError; + return Common::kNoError; } //#if PLUGIN_ENABLED_DYNAMIC(STMIDI) - //REGISTER_PLUGIN_DYNAMIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin); + //REGISTER_PLUGIN_DYNAMIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin); //#else - REGISTER_PLUGIN_STATIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin); + REGISTER_PLUGIN_STATIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin); //#endif #endif diff --git a/backends/midi/timidity.cpp b/backends/midi/timidity.cpp index eeaf872747..642ddf6917 100644 --- a/backends/midi/timidity.cpp +++ b/backends/midi/timidity.cpp @@ -92,49 +92,50 @@ class MidiDriver_TIMIDITY : public MidiDriver_MPU401 { public: MidiDriver_TIMIDITY(); - int open(); - void close(); - void send(uint32 b); - void sysEx(const byte *msg, uint16 length); + int open(); + bool isOpen() const { return _isOpen; } + void close(); + void send(uint32 b); + void sysEx(const byte *msg, uint16 length); private: /* standart routine to extract ip address from a string */ - in_addr_t host_to_addr(const char* address); + in_addr_t host_to_addr(const char* address); /* creates a tcp connection to TiMidity server, returns filedesc (like open()) */ - int connect_to_server(const char* hostname, unsigned short tcp_port); + int connect_to_server(const char* hostname, unsigned short tcp_port); /* send command to the server; printf-like; returns reply string */ - char *timidity_ctl_command(const char *fmt, ...) GCC_PRINTF(2, 3); + char *timidity_ctl_command(const char *fmt, ...) GCC_PRINTF(2, 3); /* timidity data socket-related stuff */ - void timidity_meta_seq(int p1, int p2, int p3); - int timidity_sync(int centsec); - int timidity_eot(); + void timidity_meta_seq(int p1, int p2, int p3); + int timidity_sync(int centsec); + int timidity_eot(); /* write() analogue for any midi data */ - void timidity_write_data(const void *buf, size_t nbytes); + void timidity_write_data(const void *buf, size_t nbytes); /* get single line of server reply on control connection */ - int fdgets(char *buff, size_t buff_size); + int fdgets(char *buff, size_t buff_size); /* teardown connection to server */ - void teardown(); + void teardown(); /* close (if needed) and nullify both control and data filedescs */ - void close_all(); + void close_all(); private: - bool _isOpen; - int _device_num; + bool _isOpen; + int _device_num; - int _control_fd; - int _data_fd; + int _control_fd; + int _data_fd; /* buffer for partial data read from _control_fd - from timidity-io.c, see fdgets() */ - char _controlbuffer[BUFSIZ]; - int _controlbuffer_count; /* beginning of read pointer */ - int _controlbuffer_size; /* end of read pointer */ + char _controlbuffer[BUFSIZ]; + int _controlbuffer_count; /* beginning of read pointer */ + int _controlbuffer_size; /* end of read pointer */ }; MidiDriver_TIMIDITY::MidiDriver_TIMIDITY() { @@ -149,9 +150,9 @@ MidiDriver_TIMIDITY::MidiDriver_TIMIDITY() { } int MidiDriver_TIMIDITY::open() { - char *res; - char timidity_host[MAXHOSTNAMELEN]; - int timidity_port, data_port, i; + char *res; + char timidity_host[MAXHOSTNAMELEN]; + int timidity_port, data_port, i; /* count ourselves open */ if (_isOpen) diff --git a/backends/midi/windows.cpp b/backends/midi/windows.cpp index b585b71fbe..aad7f48d94 100644 --- a/backends/midi/windows.cpp +++ b/backends/midi/windows.cpp @@ -61,6 +61,7 @@ private: public: MidiDriver_WIN(int deviceIndex) : _isOpen(false), _device(deviceIndex) { } int open(); + bool isOpen() const { return _isOpen; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); @@ -93,6 +94,8 @@ void MidiDriver_WIN::close() { } void MidiDriver_WIN::send(uint32 b) { + assert(_isOpen); + union { DWORD dwData; BYTE bData[4]; diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp index 47cab0019f..050c0d6e2c 100644 --- a/engines/agi/sound_midi.cpp +++ b/engines/agi/sound_midi.cpp @@ -138,6 +138,10 @@ int SoundGenMIDI::open() { return 0; } +bool SoundGenMIDI::isOpen() const { + return _driver && _driver->isOpen(); +} + void SoundGenMIDI::close() { stop(); if (_driver) diff --git a/engines/agi/sound_midi.h b/engines/agi/sound_midi.h index 059d41208c..b7355a0d5d 100644 --- a/engines/agi/sound_midi.h +++ b/engines/agi/sound_midi.h @@ -72,6 +72,7 @@ public: // MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp index fe2d1cd25b..e80b89d43c 100644 --- a/engines/agos/midi.cpp +++ b/engines/agos/midi.cpp @@ -85,11 +85,17 @@ int MidiPlayer::open() { return 0; } +bool MidiPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiPlayer::close() { stop(); // _system->lockMutex(_mutex); - if (_driver) + if (_driver) { + delete _driver; _driver->close(); + } _driver = NULL; clearConstructs(); // _system->unlockMutex(_mutex); diff --git a/engines/agos/midi.h b/engines/agos/midi.h index 9c8303ba3c..c27c5a7973 100644 --- a/engines/agos/midi.h +++ b/engines/agos/midi.h @@ -115,6 +115,7 @@ public: public: // MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); diff --git a/engines/draci/music.cpp b/engines/draci/music.cpp index caa82c2cc0..cc1cd6d3fb 100644 --- a/engines/draci/music.cpp +++ b/engines/draci/music.cpp @@ -97,10 +97,16 @@ int MusicPlayer::open() { return 0; } +bool MusicPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MusicPlayer::close() { stop(); - if (_driver) + if (_driver) { _driver->close(); + delete _driver; + } _driver = 0; } diff --git a/engines/draci/music.h b/engines/draci/music.h index f6f3a5ae50..0d15fdaf1b 100644 --- a/engines/draci/music.h +++ b/engines/draci/music.h @@ -61,6 +61,7 @@ public: // MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); diff --git a/engines/groovie/music.cpp b/engines/groovie/music.cpp index 011409155c..7651576828 100644 --- a/engines/groovie/music.cpp +++ b/engines/groovie/music.cpp @@ -264,6 +264,10 @@ int MusicPlayerMidi::open() { return 0; } +bool MusicPlayerMidi::isOpen() const { + return _driver && _driver->isOpen(); +} + void MusicPlayerMidi::close() {} void MusicPlayerMidi::send(uint32 b) { diff --git a/engines/groovie/music.h b/engines/groovie/music.h index 5974559c53..e45e130a70 100644 --- a/engines/groovie/music.h +++ b/engines/groovie/music.h @@ -95,6 +95,7 @@ public: // MidiDriver interface virtual int open(); + virtual bool isOpen() const; virtual void close(); virtual void send(uint32 b); virtual void metaEvent(byte type, byte *data, uint16 length); diff --git a/engines/hugo/sound.cpp b/engines/hugo/sound.cpp index 5ef843977f..c4feb5fb1c 100644 --- a/engines/hugo/sound.cpp +++ b/engines/hugo/sound.cpp @@ -192,6 +192,10 @@ int MidiPlayer::open() { return 0; } +bool MidiPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiPlayer::close() { stop(); _mutex.lock(); diff --git a/engines/hugo/sound.h b/engines/hugo/sound.h index 49e78a4aeb..e5e9d94ebb 100644 --- a/engines/hugo/sound.h +++ b/engines/hugo/sound.h @@ -60,6 +60,7 @@ public: // MidiDriver interface int open(); + bool isOpen() const; MidiChannel *allocateChannel(); MidiChannel *getPercussionChannel(); diff --git a/engines/kyra/sound_midi.cpp b/engines/kyra/sound_midi.cpp index cd5af12106..903375c362 100644 --- a/engines/kyra/sound_midi.cpp +++ b/engines/kyra/sound_midi.cpp @@ -55,6 +55,7 @@ public: // DUMMY int open() { return 0; } + bool isOpen() const { return true; } void close() {} MidiChannel *allocateChannel() { return 0; } diff --git a/engines/lure/sound.cpp b/engines/lure/sound.cpp index 5f954eb337..482527da13 100644 --- a/engines/lure/sound.cpp +++ b/engines/lure/sound.cpp @@ -694,6 +694,10 @@ int MidiMusic::open() { return 0; } +bool MidiMusic::isOpen() const { + return _driver != 0; +} + void MidiMusic::close() { } diff --git a/engines/lure/sound.h b/engines/lure/sound.h index f50748ab0a..454bff26f4 100644 --- a/engines/lure/sound.h +++ b/engines/lure/sound.h @@ -86,6 +86,7 @@ public: //MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); void onTimer(); diff --git a/engines/m4/midi.cpp b/engines/m4/midi.cpp index f130ddc3b5..3a6475da89 100644 --- a/engines/m4/midi.cpp +++ b/engines/m4/midi.cpp @@ -83,10 +83,16 @@ int MidiPlayer::open() { return 0; } +bool MidiPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiPlayer::close() { stopMusic(); - if (_driver) + if (_driver) { _driver->close(); + delete _driver; + } _driver = 0; } diff --git a/engines/m4/midi.h b/engines/m4/midi.h index 8344f8d485..a631cec2cb 100644 --- a/engines/m4/midi.h +++ b/engines/m4/midi.h @@ -54,6 +54,7 @@ public: //MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); diff --git a/engines/made/music.cpp b/engines/made/music.cpp index 8c9248a262..5ace99788b 100644 --- a/engines/made/music.cpp +++ b/engines/made/music.cpp @@ -89,10 +89,16 @@ int MusicPlayer::open() { return 0; } +bool MusicPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MusicPlayer::close() { stop(); - if (_driver) + if (_driver) { _driver->close(); + delete _driver; + } _driver = 0; } diff --git a/engines/made/music.h b/engines/made/music.h index 9840c50cfa..024588ea4d 100644 --- a/engines/made/music.h +++ b/engines/made/music.h @@ -66,6 +66,7 @@ public: //MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); diff --git a/engines/parallaction/sound_br.cpp b/engines/parallaction/sound_br.cpp index e127cf2838..5be953936d 100644 --- a/engines/parallaction/sound_br.cpp +++ b/engines/parallaction/sound_br.cpp @@ -222,6 +222,7 @@ public: // MidiDriver interface int open(); + bool isOpen() const; void close(); void send(uint32 b); void metaEvent(byte type, byte *data, uint16 length); @@ -342,6 +343,10 @@ int MidiPlayer_MSC::open() { return ret; } +bool MidiPlayer_MSC::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiPlayer_MSC::close() { stop(); _mutex.lock(); diff --git a/engines/parallaction/sound_ns.cpp b/engines/parallaction/sound_ns.cpp index 15fdede571..de8a861d4b 100644 --- a/engines/parallaction/sound_ns.cpp +++ b/engines/parallaction/sound_ns.cpp @@ -59,6 +59,7 @@ public: // MidiDriver interface int open(); + bool isOpen() const; void close(); void send(uint32 b); void metaEvent(byte type, byte *data, uint16 length); @@ -178,6 +179,10 @@ int MidiPlayer::open() { return ret; } +bool MidiPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiPlayer::close() { stop(); _mutex.lock(); diff --git a/engines/queen/music.cpp b/engines/queen/music.cpp index 4dc698dac9..044717878b 100644 --- a/engines/queen/music.cpp +++ b/engines/queen/music.cpp @@ -78,8 +78,10 @@ MidiMusic::MidiMusic(QueenEngine *vm) _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); } } + assert(_driver); - _driver->open(); + int ret = _driver->open(); + assert(ret == 0); _driver->setTimerCallback(this, &timerCallback); if (_nativeMT32) diff --git a/engines/queen/music.h b/engines/queen/music.h index fe45d56fde..50f7b3d255 100644 --- a/engines/queen/music.h +++ b/engines/queen/music.h @@ -58,6 +58,7 @@ public: //MidiDriver interface implementation int open() { return 0; } + bool isOpen() const { return true; } void close() {} void send(uint32 b); diff --git a/engines/saga/music.cpp b/engines/saga/music.cpp index f801001d88..3e1f3e3f3d 100644 --- a/engines/saga/music.cpp +++ b/engines/saga/music.cpp @@ -50,6 +50,7 @@ MusicDriver::MusicDriver() : _isGM(false) { MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); _driver = MidiDriver::createMidi(dev); + assert(_driver); _driverType = MidiDriver::getMusicType(dev); if (isMT32()) _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); @@ -75,6 +76,10 @@ int MusicDriver::open() { return 0; } +bool MusicDriver::isOpen() const { + return _driver->isOpen(); +} + void MusicDriver::setVolume(int volume) { volume = CLIP(volume, 0, 255); diff --git a/engines/saga/music.h b/engines/saga/music.h index 7d599d91c2..22d957eb06 100644 --- a/engines/saga/music.h +++ b/engines/saga/music.h @@ -58,6 +58,7 @@ public: //MidiDriver interface implementation int open(); + bool isOpen() const; void close() { _driver->close(); } void send(uint32 b); diff --git a/engines/sci/sound/drivers/mididriver.h b/engines/sci/sound/drivers/mididriver.h index f745d62716..5cecebd325 100644 --- a/engines/sci/sound/drivers/mididriver.h +++ b/engines/sci/sound/drivers/mididriver.h @@ -89,6 +89,7 @@ public: return open(resMan); } virtual int open(ResourceManager *resMan) { return _driver->open(); } + bool isOpen() const { return _driver->isOpen(); } virtual void close() { _driver->close(); } virtual void send(uint32 b) { _driver->send(b); } uint32 getBaseTempo() { return _driver->getBaseTempo(); } diff --git a/engines/scumm/imuse/imuse_internal.h b/engines/scumm/imuse/imuse_internal.h index 0014480894..3a6470f832 100644 --- a/engines/scumm/imuse/imuse_internal.h +++ b/engines/scumm/imuse/imuse_internal.h @@ -284,6 +284,7 @@ public: public: // MidiDriver interface int open() { return 0; } + bool isOpen() const { return true; } void close() { } void send(uint32 b); const char *getErrorName(int error_code) { return "Unknown"; } diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp index 7461cfca72..fb0f6b94fb 100644 --- a/engines/tinsel/music.cpp +++ b/engines/tinsel/music.cpp @@ -432,10 +432,16 @@ int MidiMusicPlayer::open() { return 0; } +bool MidiMusicPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiMusicPlayer::close() { stop(); - if (_driver) + if (_driver) { _driver->close(); + delete _driver; + } _driver = 0; } diff --git a/engines/tinsel/music.h b/engines/tinsel/music.h index e2a3b4c2c1..5545200c59 100644 --- a/engines/tinsel/music.h +++ b/engines/tinsel/music.h @@ -80,6 +80,7 @@ public: //MidiDriver interface implementation int open(); + bool isOpen() const; void close(); void send(uint32 b); diff --git a/engines/touche/midi.cpp b/engines/touche/midi.cpp index 0b15643767..c420fb34ff 100644 --- a/engines/touche/midi.cpp +++ b/engines/touche/midi.cpp @@ -110,6 +110,10 @@ int MidiPlayer::open() { return ret; } +bool MidiPlayer::isOpen() const { + return _driver && _driver->isOpen(); +} + void MidiPlayer::close() { stop(); _mutex.lock(); diff --git a/engines/touche/midi.h b/engines/touche/midi.h index 8e43c12037..75f33269a7 100644 --- a/engines/touche/midi.h +++ b/engines/touche/midi.h @@ -59,6 +59,7 @@ public: // MidiDriver interface int open(); + bool isOpen() const; void close(); void send(uint32 b); void metaEvent(byte type, byte *data, uint16 length); -- cgit v1.2.3