[Scummvm-cvs-logs] scummvm master -> 8982fff1b79aa3cc53a5c328b283e0f102cb647f

fingolfin max at quendi.de
Wed Mar 23 00:21:02 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8982fff1b7 AUDIO: Add pure virtual MidiDriver::isOpen() method


Commit: 8982fff1b79aa3cc53a5c328b283e0f102cb647f
    https://github.com/scummvm/scummvm/commit/8982fff1b79aa3cc53a5c328b283e0f102cb647f
Author: Max Horn (max at quendi.de)
Date: 2011-03-22T15:51:47-07:00

Commit Message:
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.

Changed paths:
    audio/mididrv.h
    audio/mpu401.cpp
    audio/null.h
    audio/softsynth/adlib.cpp
    audio/softsynth/emumidi.h
    backends/midi/alsa.cpp
    backends/midi/camd.cpp
    backends/midi/coreaudio.cpp
    backends/midi/coremidi.cpp
    backends/midi/dmedia.cpp
    backends/midi/seq.cpp
    backends/midi/stmidi.cpp
    backends/midi/timidity.cpp
    backends/midi/windows.cpp
    engines/agi/sound_midi.cpp
    engines/agi/sound_midi.h
    engines/agos/midi.cpp
    engines/agos/midi.h
    engines/draci/music.cpp
    engines/draci/music.h
    engines/groovie/music.cpp
    engines/groovie/music.h
    engines/hugo/sound.cpp
    engines/hugo/sound.h
    engines/kyra/sound_midi.cpp
    engines/lure/sound.cpp
    engines/lure/sound.h
    engines/m4/midi.cpp
    engines/m4/midi.h
    engines/made/music.cpp
    engines/made/music.h
    engines/parallaction/sound_br.cpp
    engines/parallaction/sound_ns.cpp
    engines/queen/music.cpp
    engines/queen/music.h
    engines/saga/music.cpp
    engines/saga/music.h
    engines/sci/sound/drivers/mididriver.h
    engines/scumm/imuse/imuse_internal.h
    engines/tinsel/music.cpp
    engines/tinsel/music.h
    engines/touche/midi.cpp
    engines/touche/midi.h



diff --git a/audio/mididrv.h b/audio/mididrv.h
index eed8c41..f635472 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 8d1e5b6..4834772 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 5df7493..8570d4d 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 4a9ce54..9e86347 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 815c020..190b70c 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 feed60e..2257f60 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 57251b4..ee3baaa 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 75c512c..0158cc4 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 c066335..9123c9b 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 f0ab84c..c4c1968 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 064129b..7cd7f0a 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 562c3c7..42f829a 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 eeaf872..642ddf6 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 b585b71..aad7f48 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 47cab00..050c0d6 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 059d412..b7355a0 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 fe2d1cd..e80b89d 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 9c8303b..c27c5a7 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 caa82c2..cc1cd6d 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 f6f3a5a..0d15fda 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 0114091..7651576 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 5974559..e45e130 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 5ef8439..c4feb5f 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 49e78a4..e5e9d94 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 cd5af12..903375c 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 5f954eb..482527d 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 f50748a..454bff2 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 f130ddc..3a6475d 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 8344f8d..a631cec 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 8c9248a..5ace997 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 9840c50..024588e 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 e127cf2..5be9539 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 15fdede..de8a861 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 4dc698d..0447178 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 fe45d56..50f7b3d 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 f801001..3e1f3e3 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 7d599d9..22d957e 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 f745d62..5cecebd 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 0014480..3a6470f 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 7461cfc..fb0f6b9 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 e2a3b4c..5545200 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 0b15643..c420fb3 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 8e43c12..75f3326 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);






More information about the Scummvm-git-logs mailing list