[Scummvm-cvs-logs] scummvm master -> 62f5c475f3bf7482526ce58bd90f37343ef523a6

fingolfin max at quendi.de
Thu Mar 24 16:54:08 CET 2011


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

Summary:
754c250c65 HUGO: When erroring out due to a missing file, tell the user which file is missing
00932cc715 QUEEN: Fix incorrect 'all notes off' handling
2d4dff8cb4 DRACI: Fix incorrect 'all notes off' handling
e9570c3a4b AUDIO: Added Audio::MidiPlayer class
f4b30ecf6e AGI: Change SoundGenMIDI to derive from Audio::MidiPlayer
4780eb7393 DRACI: Change MusicPlayer to derive from Audio::MidiPlayer
94e7a231fe HUGO: Change MidiPlayer to derive from Audio::MidiPlayer
e76a8a8eb6 M4: Change MidiPlayer to derive from Audio::MidiPlayer
84d68f31e8 MADE: Change MusicPlayer to derive from Audio::MidiPlayer
7cc04f25ff PARALLACTION: Change MidiPlayer impls to derive from Audio::MidiPlayer
47e347b922 TINSEL: Change MidiMusicPlayer to derive from Audio::MidiPlayer
6b797ccb2e QUEEN: Rename some MidiMusic members to match Audio::MidiPlayer
06b5432e94 SAGA: Rename some MusicDriver members to match Audio::MidiPlayer
9a646cde46 HUGO: Turn FileManager::getBootCypher into a const static variable
62f5c475f3 AUDIO: Expand MidiPlayer docs / goals a bit, mention deadlock bug


Commit: 754c250c65ca746d7620d74928ce91af4e5ef228
    https://github.com/scummvm/scummvm/commit/754c250c65ca746d7620d74928ce91af4e5ef228
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:45-07:00

Commit Message:
HUGO: When erroring out due to a missing file, tell the user which file is missing

Changed paths:
    engines/hugo/file.cpp



diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index f4eada4..214390c 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -532,7 +532,7 @@ void FileManager::printBootText() {
 			warning("printBootText - Skipping as H1 Dos may be a freeware");
 			return;
 		} else {
-			error("Missing startup file");
+			error("Missing startup file '%s'", getBootFilename());
 		}
 	}
 
@@ -574,7 +574,7 @@ void FileManager::readBootFile() {
 			_vm->_boot.registered = kRegFreeware;
 			return;
 		} else {
-			error("Missing startup file");
+			error("Missing startup file '%s'", getBootFilename());
 		}
 	}
 


Commit: 00932cc71540350e64c1f3b3dd495d8425500865
    https://github.com/scummvm/scummvm/commit/00932cc71540350e64c1f3b3dd495d8425500865
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:45-07:00

Commit Message:
QUEEN: Fix incorrect 'all notes off' handling

Changed paths:
    engines/queen/music.cpp



diff --git a/engines/queen/music.cpp b/engines/queen/music.cpp
index e04527d..df5ff02 100644
--- a/engines/queen/music.cpp
+++ b/engines/queen/music.cpp
@@ -178,7 +178,7 @@ void MidiMusic::send(uint32 b) {
 	} else if ((b & 0xFFF0) == 0x007BB0) {
 		//Only respond to All Notes Off if this channel
 		//has currently been allocated
-		if (_channel[channel])
+		if (!_channel[channel])
 			return;
 	}
 


Commit: 2d4dff8cb46dbe249e5e7918aa50f6adfc5cf6ea
    https://github.com/scummvm/scummvm/commit/2d4dff8cb46dbe249e5e7918aa50f6adfc5cf6ea
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:46-07:00

Commit Message:
DRACI: Fix incorrect 'all notes off' handling

Changed paths:
    engines/draci/music.cpp



diff --git a/engines/draci/music.cpp b/engines/draci/music.cpp
index cdea2d9..7c31cc3 100644
--- a/engines/draci/music.cpp
+++ b/engines/draci/music.cpp
@@ -117,7 +117,7 @@ void MusicPlayer::send(uint32 b) {
 	else if ((b & 0xFFF0) == 0x007BB0) {
 		//Only respond to All Notes Off if this channel
 		//has currently been allocated
-		if (_channel[b & 0x0F])
+		if (!_channel[b & 0x0F])
 			return;
 	}
 


Commit: e9570c3a4b18984669bd17ba4c80c98c77f3f6f1
    https://github.com/scummvm/scummvm/commit/e9570c3a4b18984669bd17ba4c80c98c77f3f6f1
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:46-07:00

Commit Message:
AUDIO: Added Audio::MidiPlayer class

This code is currently not complete, but contains enough code to
allow several engines to switch their pseudo MidiDrivers to be
based on this class, greatly reducing code duplication.

Changed paths:
  A audio/midiplayer.cpp
  A audio/midiplayer.h
    audio/module.mk



diff --git a/audio/midiplayer.cpp b/audio/midiplayer.cpp
new file mode 100644
index 0000000..12d03d7
--- /dev/null
+++ b/audio/midiplayer.cpp
@@ -0,0 +1,172 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "audio/midiplayer.h"
+#include "audio/midiparser.h"
+
+#include "common/config-manager.h"
+
+namespace Audio {
+
+MidiPlayer::MidiPlayer() :
+	_driver(0),
+	_parser(0),
+	_isLooping(false),
+	_isPlaying(false),
+	_masterVolume(0),
+	_nativeMT32(false) {
+
+	memset(_channelsTable, 0, sizeof(_channelsTable));
+	memset(_channelsVolume, 127, sizeof(_channelsVolume));
+
+// TODO
+}
+
+MidiPlayer::~MidiPlayer() {
+// TODO
+}
+
+void MidiPlayer::setVolume(int volume) {
+	volume = CLIP(volume, 0, 255);
+
+	if (_masterVolume == volume)
+		return;
+
+	Common::StackLock lock(_mutex);
+
+	_masterVolume = volume;
+
+	for (int i = 0; i < kNumChannels; ++i) {
+		if (_channelsTable[i]) {
+			_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
+		}
+	}
+}
+
+void MidiPlayer::syncVolume() {
+	int volume = ConfMan.getInt("music_volume");
+	if (ConfMan.getBool("mute")) {
+		volume = -1;
+	}
+	setVolume(volume);
+}
+
+
+void MidiPlayer::send(uint32 b) {
+	byte channel = (byte)(b & 0x0F);
+	if ((b & 0xFFF0) == 0x07B0) {
+		// Adjust volume changes by master volume
+		byte volume = (byte)((b >> 16) & 0x7F);
+		_channelsVolume[channel] = volume;
+		volume = volume * _masterVolume / 255;
+		b = (b & 0xFF00FFFF) | (volume << 16);
+	} else if ((b & 0xFFF0) == 0x007BB0) {
+		// Only respond to All Notes Off if this channel
+		// has currently been allocated
+		if (!_channelsTable[channel])
+			return;
+	}
+
+	sendToChannel(channel, b);
+}
+
+void MidiPlayer::sendToChannel(byte channel, uint32 b) {
+	if (!_channelsTable[channel]) {
+		_channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
+		// TODO: Some engines overload this method to insert code at this
+		// point which calls the channel's volume() method.
+		// Does this make sense, and should we maybe do it in general?
+	}
+	if (_channelsTable[channel])
+		_channelsTable[channel]->send(b);
+}
+
+void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
+	switch (type) {
+	case 0x2F:	// End of Track
+		endOfTrack();
+		break;
+	default:
+		//warning("Unhandled meta event: %02x", type);
+		break;
+	}
+}
+
+void MidiPlayer::endOfTrack() {
+	if (_isLooping) {
+		assert(_parser);
+		_parser->jumpToTick(0);
+	} else
+		stop();
+}
+
+#if 0
+void MidiPlayer::onTimer(void *data) {
+	assert(data);
+	((MidiPlayer *)data)->onTimer();
+}
+
+void MidiPlayer::onTimer() {
+	Common::StackLock lock(_mutex);
+
+	// FIXME: There are various alternatives for this function:
+
+#if 0
+	if (_parser) {
+		_parser->onTimer();
+	}
+#elif 0
+	if (_isPlaying) {
+		assert(_parser);
+		_parser->onTimer();
+	}
+#endif
+}
+#endif
+
+
+void MidiPlayer::stop() {
+	Common::StackLock lock(_mutex);
+
+	_isPlaying = false;
+	if (_parser) {
+		_parser->unloadMusic();
+		_parser = NULL;
+	}
+}
+
+void MidiPlayer::pause() {
+//	debugC(2, kDraciSoundDebugLevel, "Pausing track %d", _track);
+	setVolume(-1);	// FIXME: This should be 0, shouldn't it?
+	_isPlaying = false;
+}
+
+void MidiPlayer::resume() {
+//	debugC(2, kDraciSoundDebugLevel, "Resuming track %d", _track);
+	syncVolume();
+	_isPlaying = true;
+}
+
+} // End of namespace Audio
diff --git a/audio/midiplayer.h b/audio/midiplayer.h
new file mode 100644
index 0000000..913d49c
--- /dev/null
+++ b/audio/midiplayer.h
@@ -0,0 +1,117 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SOUND_MIDIPLAYER_H
+#define SOUND_MIDIPLAYER_H
+
+#include "common/scummsys.h"
+#include "common/mutex.h"
+#include "audio/mididrv.h"
+
+class MidiParser;
+
+namespace Audio {
+
+/**
+ * Simple MIDI playback class.
+ *
+ * @note Currently incomplete, as it lacks play() methods. This is just a
+ * start of the real thing, which tries to include code replicated between
+ * several of our engines.
+ *
+ * @todo Document origin of this class. It is based on code shared by
+ * several engines (e.g. DRACI says it copied it from MADE, which took
+ * it from SAGE).
+ */
+class MidiPlayer : public MidiDriver_BASE {
+public:
+	MidiPlayer();
+	~MidiPlayer();
+
+	// TODO: Implement ways to actually play stuff
+	//virtual void play(TODO);
+	// TODO: Document these
+	virtual void stop();
+	virtual void pause();
+	virtual void resume();
+
+	bool isPlaying() const { return _isPlaying; }
+
+	int getVolume() const { return _masterVolume; }
+	virtual void setVolume(int volume);	// FIXME: Overloaded by Tinsel
+	void syncVolume();
+
+	bool hasNativeMT32() const { return _nativeMT32; }
+
+	// MidiDriver_BASE interface
+	virtual void send(uint32 b);
+	virtual void metaEvent(byte type, byte *data, uint16 length);
+
+	/**
+	 * This method is invoked by send() after suitably filtering
+	 * the message b.
+	 */
+	virtual void sendToChannel(byte channel, uint32 b);
+
+	/**
+	 * This method is invoked by metaEvent when an end-of-track
+	 * event arrives. By default, this tells the parser
+	 * to jump to the start (if looping is enabled) resp.
+	 * invokes stope():
+	 * Overload this to customize behavior.
+	 */
+	virtual void endOfTrack();
+
+protected:
+
+#if 0
+	// TODO: Start to make use of these, once we figured
+	// out the right way :)
+	static void onTimer(void *data);
+	virtual void onTimer();
+#endif
+
+	enum {
+		kNumChannels = 16
+	};
+
+	Common::Mutex _mutex;
+	MidiDriver *_driver;
+	MidiParser *_parser;
+
+	MidiChannel *_channelsTable[kNumChannels];
+	uint8 _channelsVolume[kNumChannels];
+
+	bool _isLooping;
+	bool _isPlaying;
+	int _masterVolume;	// FIXME: byte or int ?
+
+	bool _nativeMT32;
+};
+
+
+} // End of namespace Audio
+
+#endif
diff --git a/audio/module.mk b/audio/module.mk
index 5b93c80..661d3cc 100644
--- a/audio/module.mk
+++ b/audio/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS := \
 	midiparser_smf.o \
 	midiparser_xmidi.o \
 	midiparser.o \
+	midiplayer.o \
 	mixer.o \
 	mpu401.o \
 	musicplugin.o \


Commit: f4b30ecf6ebb8095eddfc62bb1e832b83b9d6527
    https://github.com/scummvm/scummvm/commit/f4b30ecf6ebb8095eddfc62bb1e832b83b9d6527
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:46-07:00

Commit Message:
AGI: Change SoundGenMIDI to derive from Audio::MidiPlayer

As a side effect, this fixes the incorrect handling of 'All Note Off'
in SoundGenMIDI::send.

Changed paths:
    engines/agi/sound_midi.cpp
    engines/agi/sound_midi.h



diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp
index b58e1e5..2c6a189 100644
--- a/engines/agi/sound_midi.cpp
+++ b/engines/agi/sound_midi.cpp
@@ -71,7 +71,7 @@ MIDISound::MIDISound(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : A
 		warning("Error creating MIDI sound from resource %d (Type %d, length %d)", resnum, _type, len);
 }
 
-SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, pMixer), _parser(0), _isPlaying(false), _isGM(false) {
+SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, pMixer), _isGM(false) {
 	MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB);
 	_driver = MidiDriver::createMidi(dev);
 	assert(_driver);
@@ -83,10 +83,6 @@ SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, p
 		_nativeMT32 = false;
 	}
 
-	memset(_channel, 0, sizeof(_channel));
-	memset(_channelVolume, 127, sizeof(_channelVolume));
-	_masterVolume = 0;
-
 	int ret = _driver->open();
 	if (ret == 0) {
 		if (_nativeMT32)
@@ -114,67 +110,30 @@ SoundGenMIDI::~SoundGenMIDI() {
 	delete[] _midiMusicData;
 }
 
-void SoundGenMIDI::setChannelVolume(int channel) {
-	int newVolume = _channelVolume[channel] * _masterVolume / 255;
-	_channel[channel]->volume(newVolume);
-}
-
-void SoundGenMIDI::setVolume(int volume) {
-	Common::StackLock lock(_mutex);
-
-	volume = CLIP(volume, 0, 255);
-	if (_masterVolume == volume)
-		return;
-	_masterVolume = volume;
-
-	for (int i = 0; i < 16; ++i) {
-		if (_channel[i]) {
-			setChannelVolume(i);
-		}
-	}
-}
-
 void SoundGenMIDI::send(uint32 b) {
-	byte channel = (byte)(b & 0x0F);
-	if ((b & 0xFFF0) == 0x07B0) {
-		// Adjust volume changes by master volume
-		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-	} else if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
+	if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
 		b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
 	}
-	else if ((b & 0xFFF0) == 0x007BB0) {
-		//Only respond to All Notes Off if this channel
-		//has currently been allocated
-		if (_channel[b & 0x0F])
-			return;
-	}
 
-	if (!_channel[channel]) {
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
+	Audio::MidiPlayer::send(b);
+}
+
+void SoundGenMIDI::sendToChannel(byte channel, uint32 b) {
+	if (!_channelsTable[channel]) {
+		_channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
 		// If a new channel is allocated during the playback, make sure
 		// its volume is correctly initialized.
-		if (_channel[channel])
-			setChannelVolume(channel);
+		if (_channelsTable[channel])
+			_channelsTable[channel]->volume(_channelsVolume[channel] * _masterVolume / 255);
 	}
 
-	if (_channel[channel])
-		_channel[channel]->send(b);
+	if (_channelsTable[channel])
+		_channelsTable[channel]->send(b);
 }
 
-void SoundGenMIDI::metaEvent(byte type, byte *data, uint16 length) {
-
-	switch (type) {
-	case 0x2F:	// End of Track
-		stop();
-		_vm->_sound->soundIsFinished();
-		break;
-	default:
-		//warning("Unhandled meta event: %02x", type);
-		break;
-	}
+void SoundGenMIDI::endOfTrack() {
+	stop();
+	_vm->_sound->soundIsFinished();
 }
 
 void SoundGenMIDI::onTimer(void *refCon) {
@@ -212,37 +171,6 @@ void SoundGenMIDI::play(int resnum) {
 	}
 }
 
-void SoundGenMIDI::stop() {
-	Common::StackLock lock(_mutex);
-
-	if (!_isPlaying)
-		return;
-
-	_isPlaying = false;
-	if (_parser) {
-		_parser->unloadMusic();
-		_parser = NULL;
-	}
-}
-
-void SoundGenMIDI::pause() {
-	setVolume(-1);
-	_isPlaying = false;
-}
-
-void SoundGenMIDI::resume() {
-	syncVolume();
-	_isPlaying = true;
-}
-
-void SoundGenMIDI::syncVolume() {
-	int volume = ConfMan.getInt("music_volume");
-	if (ConfMan.getBool("mute")) {
-		volume = -1;
-	}
-	setVolume(volume);
-}
-
 /* channel / intrument setup: */
 
 /* most songs are good with this: */
diff --git a/engines/agi/sound_midi.h b/engines/agi/sound_midi.h
index f70a20f..9551673 100644
--- a/engines/agi/sound_midi.h
+++ b/engines/agi/sound_midi.h
@@ -28,9 +28,7 @@
 #ifndef AGI_SOUND_MIDI_H
 #define AGI_SOUND_MIDI_H
 
-#include "audio/mididrv.h"
-#include "audio/midiparser.h"
-#include "common/mutex.h"
+#include "audio/midiplayer.h"
 
 namespace Agi {
 
@@ -46,52 +44,30 @@ protected:
 	uint16 _type; ///< Sound resource type
 };
 
-class SoundGenMIDI : public SoundGen, public MidiDriver_BASE {
+class SoundGenMIDI : public SoundGen, public Audio::MidiPlayer {
 public:
 	SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer);
 	~SoundGenMIDI();
 
 	void play(int resnum);
-	void stop();
-
-	bool isPlaying() const { return _isPlaying; }
-	void setPlaying(bool playing) { _isPlaying = playing; }
-
-	void setVolume(int volume);
-	int getVolume() const { return _masterVolume; }
-	void syncVolume();
-
-	void setNativeMT32(bool b) { _nativeMT32 = b; }
-	bool hasNativeMT32() const { return _nativeMT32; }
-	void pause();
-	void resume();
-	void setLoop(bool loop) { _looping = loop; }
+	void stop() { Audio::MidiPlayer::stop(); }
 
 	void setGM(bool isGM) { _isGM = isGM; }
 
 	// MidiDriver_BASE interface implementation
 	virtual void send(uint32 b);
-	virtual void metaEvent(byte type, byte *data, uint16 length);
+
+	// Overload Audio::MidiPlayer method
+	virtual void sendToChannel(byte channel, uint32 b);
+	virtual void endOfTrack();
 
 private:
 
 	static void onTimer(void *data);
-	void setChannelVolume(int channel);
-
-	MidiParser *_parser;
-	Common::Mutex _mutex;
 
-	MidiChannel *_channel[16];
-	MidiDriver *_driver;
 	MidiParser *_smfParser;
-	byte _channelVolume[16];
-	bool _nativeMT32;
 	bool _isGM;
 
-	bool _isPlaying;
-	bool _looping;
-	byte _masterVolume;
-
 	byte *_midiMusicData;
 
 	SoundMgr *_manager;


Commit: 4780eb7393cc8cc30dd822966eb82507bb61f6eb
    https://github.com/scummvm/scummvm/commit/4780eb7393cc8cc30dd822966eb82507bb61f6eb
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:46-07:00

Commit Message:
DRACI: Change MusicPlayer to derive from Audio::MidiPlayer

Changed paths:
    engines/draci/music.cpp
    engines/draci/music.h



diff --git a/engines/draci/music.cpp b/engines/draci/music.cpp
index 7c31cc3..77f5154 100644
--- a/engines/draci/music.cpp
+++ b/engines/draci/music.cpp
@@ -36,7 +36,7 @@
 
 namespace Draci {
 
-MusicPlayer::MusicPlayer(const char *pathMask) : _parser(0), _driver(0), _pathMask(pathMask), _looping(false), _isPlaying(false), _isGM(false), _track(-1) {
+MusicPlayer::MusicPlayer(const char *pathMask) : _pathMask(pathMask), _isGM(false), _track(-1) {
 
 	MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
 	_nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
@@ -47,9 +47,6 @@ MusicPlayer::MusicPlayer(const char *pathMask) : _parser(0), _driver(0), _pathMa
 	if (_nativeMT32)
 		_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
 
-	memset(_channel, 0, sizeof(_channel));
-	memset(_channelVolume, 127, sizeof(_channelVolume));
-	_masterVolume = 0;
 	_smfParser = MidiParser::createParser_SMF();
 	_midiMusicData = NULL;
 
@@ -81,71 +78,17 @@ MusicPlayer::~MusicPlayer() {
 	delete[] _midiMusicData;
 }
 
-void MusicPlayer::setChannelVolume(int channel) {
-	int newVolume = _channelVolume[channel] * _masterVolume / 255;
-	debugC(3, kDraciSoundDebugLevel, "Music channel %d: volume %d->%d",
-		channel, _channelVolume[channel], newVolume);
-	_channel[channel]->volume(newVolume);
-}
-
-void MusicPlayer::setVolume(int volume) {
-	Common::StackLock lock(_mutex);
-
-	volume = CLIP(volume, 0, 255);
-	if (_masterVolume == volume)
-		return;
-	_masterVolume = volume;
-
-	for (int i = 0; i < 16; ++i) {
-		if (_channel[i]) {
-			setChannelVolume(i);
-		}
-	}
-}
-
-void MusicPlayer::send(uint32 b) {
-	byte channel = (byte)(b & 0x0F);
-	if ((b & 0xFFF0) == 0x07B0) {
-		// Adjust volume changes by master volume
-		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-	} else if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
-		b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
-	}
-	else if ((b & 0xFFF0) == 0x007BB0) {
-		//Only respond to All Notes Off if this channel
-		//has currently been allocated
-		if (!_channel[b & 0x0F])
-			return;
-	}
-
-	if (!_channel[channel]) {
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
+void MusicPlayer::sendToChannel(byte channel, uint32 b) {
+	if (!_channelsTable[channel]) {
+		_channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
 		// If a new channel is allocated during the playback, make sure
 		// its volume is correctly initialized.
-		if (_channel[channel])
-			setChannelVolume(channel);
+		if (_channelsTable[channel])
+			_channelsTable[channel]->volume(_channelsVolume[channel] * _masterVolume / 255);
 	}
 
-	if (_channel[channel])
-		_channel[channel]->send(b);
-}
-
-void MusicPlayer::metaEvent(byte type, byte *data, uint16 length) {
-
-	switch (type) {
-	case 0x2F:	// End of Track
-		if (_looping)
-			_parser->jumpToTick(0);
-		else
-			stop();
-		break;
-	default:
-		//warning("Unhandled meta event: %02x", type);
-		break;
-	}
+	if (_channelsTable[channel])
+		_channelsTable[channel]->send(b);
 }
 
 void MusicPlayer::onTimer(void *refCon) {
@@ -193,7 +136,7 @@ void MusicPlayer::playSMF(int track, bool loop) {
 
 		syncVolume();
 
-		_looping = loop;
+		_isLooping = loop;
 		_isPlaying = true;
 		_track = track;
 		debugC(2, kDraciSoundDebugLevel, "Playing track %d", track);
@@ -203,39 +146,9 @@ void MusicPlayer::playSMF(int track, bool loop) {
 }
 
 void MusicPlayer::stop() {
-	Common::StackLock lock(_mutex);
-
-	if (!_isPlaying)
-		return;
-
+	Audio::MidiPlayer::stop();
 	debugC(2, kDraciSoundDebugLevel, "Stopping track %d", _track);
 	_track = -1;
-	_isPlaying = false;
-	if (_parser) {
-		_parser->unloadMusic();
-		_parser = NULL;
-	}
-}
-
-void MusicPlayer::pause() {
-	debugC(2, kDraciSoundDebugLevel, "Pausing track %d", _track);
-	setVolume(-1);
-	_isPlaying = false;
-}
-
-void MusicPlayer::resume() {
-	debugC(2, kDraciSoundDebugLevel, "Resuming track %d", _track);
-	syncVolume();
-	_isPlaying = true;
-}
-
-void MusicPlayer::syncVolume() {
-	int volume = ConfMan.getInt("music_volume");
-	if (ConfMan.getBool("mute")) {
-		volume = -1;
-	}
-	debugC(2, kDraciSoundDebugLevel, "Syncing music volume to %d", volume);
-	setVolume(volume);
 }
 
 } // End of namespace Draci
diff --git a/engines/draci/music.h b/engines/draci/music.h
index 0125a66..a1d0aaa 100644
--- a/engines/draci/music.h
+++ b/engines/draci/music.h
@@ -28,58 +28,33 @@
 #ifndef DRACI_MUSIC_H
 #define DRACI_MUSIC_H
 
-#include "audio/mididrv.h"
-#include "audio/midiparser.h"
-#include "common/mutex.h"
+#include "audio/midiplayer.h"
 
 namespace Draci {
 
 // Taken from MADE, which took it from SAGA.
 
-class MusicPlayer : public MidiDriver_BASE {
+class MusicPlayer : public Audio::MidiPlayer {
 public:
 	MusicPlayer(const char *pathMask);
 	~MusicPlayer();
 
-	bool isPlaying() const { return _isPlaying; }
-	void setPlaying(bool playing) { _isPlaying = playing; }
-
-	void setVolume(int volume);
-	int getVolume() const { return _masterVolume; }
-	void syncVolume();
-
-	bool hasNativeMT32() const { return _nativeMT32; }
 	void playSMF(int track, bool loop);
 	void stop();
-	void pause();
-	void resume();
-	void setLoop(bool loop) { _looping = loop; }
 
 	void setGM(bool isGM) { _isGM = isGM; }
 
-	// MidiDriver_BASE interface implementation
-	virtual void send(uint32 b);
-	virtual void metaEvent(byte type, byte *data, uint16 length);
+	// Overload Audio::MidiPlayer method
+	virtual void sendToChannel(byte channel, uint32 b);
 
 protected:
 
 	static void onTimer(void *data);
-	void setChannelVolume(int channel);
-
-	MidiParser *_parser;
-	Common::Mutex _mutex;
 
-	MidiChannel *_channel[16];
-	MidiDriver *_driver;
 	MidiParser *_smfParser;
 	Common::String _pathMask;
-	byte _channelVolume[16];
-	bool _nativeMT32;
 	bool _isGM;
 
-	bool _isPlaying;
-	bool _looping;
-	byte _masterVolume;
 	int _track;
 
 	byte *_midiMusicData;


Commit: 94e7a231fe7a975886ba74bc1670cb4a34619316
    https://github.com/scummvm/scummvm/commit/94e7a231fe7a975886ba74bc1670cb4a34619316
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:47-07:00

Commit Message:
HUGO: Change MidiPlayer to derive from Audio::MidiPlayer

Changed paths:
    engines/hugo/sound.cpp
    engines/hugo/sound.h



diff --git a/engines/hugo/sound.cpp b/engines/hugo/sound.cpp
index f80faea..04da0c8 100644
--- a/engines/hugo/sound.cpp
+++ b/engines/hugo/sound.cpp
@@ -37,6 +37,7 @@
 
 #include "audio/decoders/raw.h"
 #include "audio/audiostream.h"
+#include "audio/midiparser.h"
 
 #include "hugo/hugo.h"
 #include "hugo/game.h"
@@ -47,16 +48,9 @@
 namespace Hugo {
 
 MidiPlayer::MidiPlayer(MidiDriver *driver)
-	: _driver(driver), _parser(0), _midiData(0) {
+	: _midiData(0) {
 	assert(_driver);
-	memset(_channelsTable, 0, sizeof(_channelsTable));
-	for (int i = 0; i < kNumbChannels; i++) {
-		_channelsVolume[i] = 127;
-	}
-	_isLooping = false;
-	_isPlaying = false;
 	_paused = false;
-	_masterVolume = 0;
 }
 
 MidiPlayer::~MidiPlayer() {
@@ -72,18 +66,6 @@ MidiPlayer::~MidiPlayer() {
 	delete _parser;
 }
 
-bool MidiPlayer::isPlaying() const {
-	return _isPlaying;
-}
-
-int MidiPlayer::getVolume() const {
-	return _masterVolume;
-}
-
-void MidiPlayer::setLooping(bool loop) {
-	_isLooping = loop;
-}
-
 void MidiPlayer::play(uint8 *stream, uint16 size) {
 	debugC(3, kDebugMusic, "MidiPlayer::play");
 	if (!stream) {
@@ -97,7 +79,7 @@ void MidiPlayer::play(uint8 *stream, uint16 size) {
 		memcpy(_midiData, stream, size);
 
 		Common::StackLock lock(_mutex);
-		syncVolume();
+		syncVolume();	// FIXME: syncVolume calls setVolume which in turn also locks the mutex! ugh
 		_parser->loadMusic(_midiData, size);
 		_parser->setTrack(0);
 		_isLooping = false;
@@ -120,7 +102,7 @@ void MidiPlayer::stop() {
 void MidiPlayer::pause(bool p) {
 	_paused = p;
 
-	for (int i = 0; i < kNumbChannels; ++i) {
+	for (int i = 0; i < kNumChannels; ++i) {
 		if (_channelsTable[i]) {
 			_channelsTable[i]->volume(_paused ? 0 : _channelsVolume[i] * _masterVolume / 255);
 		}
@@ -138,39 +120,6 @@ void MidiPlayer::updateTimer() {
 	}
 }
 
-void MidiPlayer::adjustVolume(int diff) {
-	debugC(3, kDebugMusic, "MidiPlayer::adjustVolume");
-	setVolume(_masterVolume + diff);
-}
-
-void MidiPlayer::syncVolume() {
-	int volume = ConfMan.getInt("music_volume");
-	if (ConfMan.getBool("mute")) {
-		volume = -1;
-	}
-	debugC(2, kDebugMusic, "Syncing music volume to %d", volume);
-	setVolume(volume);
-}
-
-void MidiPlayer::setVolume(int volume) {
-	debugC(3, kDebugMusic, "MidiPlayer::setVolume");
-	_masterVolume = CLIP(volume, 0, 255);
-
-	Common::StackLock lock(_mutex);
-	for (int i = 0; i < kNumbChannels; ++i) {
-		if (_channelsTable[i]) {
-			_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
-		}
-	}
-}
-
-void MidiPlayer::setChannelVolume(int channel) {
-	int newVolume = _channelsVolume[channel] * _masterVolume / 255;
-	debugC(3, kDebugMusic, "Music channel %d: volume %d->%d",
-		channel, _channelsVolume[channel], newVolume);
-	_channelsTable[channel]->volume(newVolume);
-}
-
 int MidiPlayer::open() {
 	if (!_driver)
 		return 255;
@@ -188,49 +137,19 @@ int MidiPlayer::open() {
 	return 0;
 }
 
-void MidiPlayer::send(uint32 b) {
-	byte volume, ch = (byte)(b & 0xF);
-	debugC(9, kDebugMusic, "MidiPlayer::send, channel %d (volume is %d)", ch, _channelsVolume[ch]);
-	switch (b & 0xFFF0) {
-	case 0x07B0:                                    // volume change
-		volume = (byte)((b >> 16) & 0x7F);
-		_channelsVolume[ch] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-		debugC(8, kDebugMusic, "Volume change, channel %d volume %d", ch, volume);
-		break;
-	case 0x7BB0:                                    // all notes off
-		debugC(8, kDebugMusic, "All notes off, channel %d", ch);
-		if (!_channelsTable[ch]) {                  // channel not yet allocated, no need to send the event
-			return;
-		}
-		break;
+void MidiPlayer::sendToChannel(byte channel, uint32 b) {
+	if (!_channelsTable[channel]) {
+		_channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
+		// If a new channel is allocated during the playback, make sure
+		// its volume is correctly initialized.
+		if (_channelsTable[channel])
+			_channelsTable[channel]->volume(_channelsVolume[channel] * _masterVolume / 255);
 	}
 
-	if (!_channelsTable[ch]) {
-		_channelsTable[ch] = (ch == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
-		if (_channelsTable[ch])
-			setChannelVolume(ch);
-	}
-	if (_channelsTable[ch]) {
-		_channelsTable[ch]->send(b);
-	}
+	if (_channelsTable[channel])
+		_channelsTable[channel]->send(b);
 }
 
-void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
-	switch (type) {
-	case 0x2F:                                      // end of Track
-		if (_isLooping) {
-			_parser->jumpToTick(0);
-		} else {
-			stop();
-		}
-		break;
-	default:
-//		warning("Unhandled meta event: %02x", type);
-		break;
-	}
-}
 
 void MidiPlayer::timerCallback(void *p) {
 	MidiPlayer *player = (MidiPlayer *)p;
diff --git a/engines/hugo/sound.h b/engines/hugo/sound.h
index cdde8cc..b8a7bf9 100644
--- a/engines/hugo/sound.h
+++ b/engines/hugo/sound.h
@@ -34,52 +34,32 @@
 #define HUGO_SOUND_H
 
 #include "audio/mixer.h"
-#include "audio/mididrv.h"
-#include "audio/midiparser.h"
+#include "audio/midiplayer.h"
 #include "audio/softsynth/pcspk.h"
 
 namespace Hugo {
 
-class MidiPlayer : public MidiDriver_BASE {
+class MidiPlayer : public Audio::MidiPlayer {
 public:
 	MidiPlayer(MidiDriver *driver);
 	~MidiPlayer();
 
-	bool isPlaying() const;
-	int getVolume() const;
-
-	void adjustVolume(int diff);
 	void pause(bool p);
 	void play(uint8 *stream, uint16 size);
-	void setChannelVolume(int channel);
-	void setLooping(bool loop);
-	void setVolume(int volume);
 	void stop();
-	void syncVolume();
 	void updateTimer();
 
-	// MidiDriver_BASE interface
-	virtual void metaEvent(byte type, byte *data, uint16 length);
-	virtual void send(uint32 b);
-
 	int open();
 	uint32 getBaseTempo();
 
+	// Overload Audio::MidiPlayer method
+	virtual void sendToChannel(byte channel, uint32 b);
+
 private:
 	static void timerCallback(void *p);
 
-	static const int kNumbChannels = 16;
-
-	MidiDriver *_driver;
-	MidiParser *_parser;
 	uint8 *_midiData;
-	bool _isLooping;
-	bool _isPlaying;
 	bool _paused;
-	int _masterVolume;
-	MidiChannel *_channelsTable[kNumbChannels];
-	uint8 _channelsVolume[kNumbChannels];
-	Common::Mutex _mutex;
 };
 
 class SoundHandler {


Commit: e76a8a8eb6c68b1ffc048385c41cd1b542623449
    https://github.com/scummvm/scummvm/commit/e76a8a8eb6c68b1ffc048385c41cd1b542623449
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:47-07:00

Commit Message:
M4: Change MidiPlayer to derive from Audio::MidiPlayer

Also fix the _driver double delete regression I recently introduced

Changed paths:
    engines/m4/m4.cpp
    engines/m4/m4.h
    engines/m4/midi.cpp
    engines/m4/midi.h



diff --git a/engines/m4/m4.cpp b/engines/m4/m4.cpp
index d8d25f6..4cc2bf8 100644
--- a/engines/m4/m4.cpp
+++ b/engines/m4/m4.cpp
@@ -151,7 +151,6 @@ MadsM4Engine::~MadsM4Engine() {
 	delete _palette;
 	delete _globals;
 	delete _sound;
-	delete _driver;
 	delete _resourceManager;
 }
 
@@ -159,16 +158,8 @@ Common::Error MadsM4Engine::run() {
 	// Initialize backend
 	_screen = new M4Surface(true); // Special form for creating screen reference
 
-	MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
-	bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
-
-	_driver = MidiDriver::createMidi(dev);
-	if (native_mt32)
-		_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
-
-	_midi = new MidiPlayer(this, _driver);
-	_midi->setGM(true);
-	_midi->setNativeMT32(native_mt32);
+	_midi = new MidiPlayer(this);
+	_midi->setGM(true);	// FIXME: Really? Always?
 
 	_saveLoad = new SaveLoad(this);
 	_palette = new Palette(this);
diff --git a/engines/m4/m4.h b/engines/m4/m4.h
index f665df2..a43f3e1 100644
--- a/engines/m4/m4.h
+++ b/engines/m4/m4.h
@@ -148,7 +148,6 @@ protected:
 
 	void shutdown();
 
-	MidiDriver *_driver;
 	MidiPlayer *_midi;
 
 public:
diff --git a/engines/m4/midi.cpp b/engines/m4/midi.cpp
index f4fe003..b982fc8 100644
--- a/engines/m4/midi.cpp
+++ b/engines/m4/midi.cpp
@@ -28,14 +28,22 @@
 
 #include "m4/m4.h"
 #include "m4/midi.h"
+#include "audio/midiparser.h"
+#include "common/config-manager.h"
 #include "common/memstream.h"
 
 namespace M4 {
 
-MidiPlayer::MidiPlayer(MadsM4Engine *vm, MidiDriver *driver) : _vm(vm), _midiData(NULL), _driver(driver), _isPlaying(false), _isGM(false) {
+MidiPlayer::MidiPlayer(MadsM4Engine *vm) : _vm(vm), _midiData(NULL), _isGM(false) {
+
+	MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
+	_nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
+
+	_driver = MidiDriver::createMidi(dev);
 	assert(_driver);
-	memset(_channel, 0, sizeof(_channel));
-	_masterVolume = 0;
+	if (_nativeMT32)
+		_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
+
 	_parser = MidiParser::createParser_SMF();
 	_parser->setMidiDriver(this);
 	_parser->setTimerRate(_driver->getBaseTempo());
@@ -48,7 +56,7 @@ MidiPlayer::MidiPlayer(MadsM4Engine *vm, MidiDriver *driver) : _vm(vm), _midiDat
 MidiPlayer::~MidiPlayer() {
 	_driver->setTimerCallback(NULL, NULL);
 	_parser->setMidiDriver(NULL);
-	stopMusic();
+	stop();
 	if (_driver) {
 		_driver->close();
 		delete _driver;
@@ -58,64 +66,12 @@ MidiPlayer::~MidiPlayer() {
 	free(_midiData);
 }
 
-void MidiPlayer::setVolume(int volume) {
-	Common::StackLock lock(_mutex);
-
-	if (volume < 0)
-		volume = 0;
-	else if (volume > 255)
-		volume = 255;
-
-	if (_masterVolume == volume)
-		return;
-
-	_masterVolume = volume;
-
-	for (int i = 0; i < 16; ++i) {
-		if (_channel[i]) {
-			_channel[i]->volume(_channelVolume[i] * _masterVolume / 255);
-		}
-	}
-}
-
 void MidiPlayer::send(uint32 b) {
-	byte channel = (byte)(b & 0x0F);
-	if ((b & 0xFFF0) == 0x07B0) {
-		// Adjust volume changes by master volume
-		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-	} else if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
+	if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
 		b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
 	}
-	else if ((b & 0xFFF0) == 0x007BB0) {
-		//Only respond to All Notes Off if this channel
-		//has currently been allocated
-		if (!_channel[b & 0x0F])
-			return;
-	}
 
-	if (!_channel[channel])
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
-
-	if (_channel[channel])
-		_channel[channel]->send(b);
-}
-
-void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
-	switch (type) {
-	case 0x2F:
-		// End of track. (Not called when auto-looping.)
-		stopMusic();
-		break;
-	case 0x51:
-		// Set tempo. Handled by the standard MIDI parser already.
-		break;
-	default:
-		warning("Unhandled meta event: %02x", type);
-		break;
-	}
+	Audio::MidiPlayer::send(b);
 }
 
 void MidiPlayer::onTimer(void *refCon) {
@@ -127,7 +83,7 @@ void MidiPlayer::onTimer(void *refCon) {
 }
 
 void MidiPlayer::playMusic(const char *name, int32 vol, bool loop, int32 trigger, int32 scene) {
-	stopMusic();
+	stop();
 
 	char fullname[144];
 	_vm->res()->changeExtension(fullname, name, "HMP");
@@ -157,7 +113,7 @@ void MidiPlayer::playMusic(const char *name, int32 vol, bool loop, int32 trigger
 	_isPlaying = true;
 }
 
-void MidiPlayer::stopMusic() {
+void MidiPlayer::stop() {
 	Common::StackLock lock(_mutex);
 
 	_isPlaying = false;
diff --git a/engines/m4/midi.h b/engines/m4/midi.h
index cc3f626..e1f92cd 100644
--- a/engines/m4/midi.h
+++ b/engines/m4/midi.h
@@ -28,32 +28,22 @@
 #ifndef M4_MIDI_H
 #define M4_MIDI_H
 
-#include "audio/mididrv.h"
-#include "audio/midiparser.h"
-#include "common/mutex.h"
+#include "audio/midiplayer.h"
 
 namespace M4 {
 
-class MidiPlayer : public MidiDriver_BASE {
+class MidiPlayer : public Audio::MidiPlayer {
 public:
-	MidiPlayer(MadsM4Engine *vm, MidiDriver *driver);
+	MidiPlayer(MadsM4Engine *vm);
 	~MidiPlayer();
 
-	bool isPlaying() const { return _isPlaying; }
-
-	void setVolume(int volume);
-	int getVolume() const { return _masterVolume; }
-
-	void setNativeMT32(bool b) { _nativeMT32 = b; }
-	bool hasNativeMT32()  const{ return _nativeMT32; }
 	void playMusic(const char *name, int32 vol, bool loop, int32 trigger, int32 scene);
-	void stopMusic();
+	virtual void stop();
 
 	void setGM(bool isGM) { _isGM = isGM; }
 
 	// MidiDriver_BASE interface implementation
 	virtual void send(uint32 b);
-	virtual void metaEvent(byte type, byte *data, uint16 length);
 
 protected:
 	static void onTimer(void *data);
@@ -61,23 +51,14 @@ protected:
 	MadsM4Engine *_vm;
 	byte *_midiData;
 
-	MidiChannel *_channel[16];
-	MidiDriver *_driver;
-	MidiParser *_parser;
-	byte _channelVolume[16];
-	bool _nativeMT32;
 	bool _isGM;
 
-	bool _isPlaying;
 	bool _randomLoop;
-	byte _masterVolume;
 
 	byte *_musicData;
 	uint16 *_buf;
 	size_t _musicDataSize;
 
-	Common::Mutex _mutex;
-
 	byte *convertHMPtoSMF(byte *data, uint32 inSize, uint32 &outSize);
 };
 


Commit: 84d68f31e8734d06febfbbff1493147f0ef680c5
    https://github.com/scummvm/scummvm/commit/84d68f31e8734d06febfbbff1493147f0ef680c5
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:47-07:00

Commit Message:
MADE: Change MusicPlayer to derive from Audio::MidiPlayer

Changed paths:
    engines/made/music.cpp
    engines/made/music.h



diff --git a/engines/made/music.cpp b/engines/made/music.cpp
index a6cc2bb..054f812 100644
--- a/engines/made/music.cpp
+++ b/engines/made/music.cpp
@@ -37,7 +37,7 @@
 
 namespace Made {
 
-MusicPlayer::MusicPlayer() : _parser(0), _driver(0), _looping(false), _isPlaying(false), _isGM(false) {
+MusicPlayer::MusicPlayer() : _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);
@@ -47,8 +47,6 @@ MusicPlayer::MusicPlayer() : _parser(0), _driver(0), _looping(false), _isPlaying
 	if (_nativeMT32)
 		_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
 
-	memset(_channel, 0, sizeof(_channel));
-	_masterVolume = 0;
 	_xmidiParser = MidiParser::createParser_XMIDI();
 	_smfParser = MidiParser::createParser_SMF();
 
@@ -77,61 +75,12 @@ MusicPlayer::~MusicPlayer() {
 	delete _smfParser;
 }
 
-void MusicPlayer::setVolume(int volume) {
-	volume = CLIP(volume, 0, 255);
-
-	if (_masterVolume == volume)
-		return;
-
-	_masterVolume = volume;
-
-	Common::StackLock lock(_mutex);
-
-	for (int i = 0; i < 16; ++i) {
-		if (_channel[i]) {
-			_channel[i]->volume(_channelVolume[i] * _masterVolume / 255);
-		}
-	}
-}
-
 void MusicPlayer::send(uint32 b) {
-	byte channel = (byte)(b & 0x0F);
-	if ((b & 0xFFF0) == 0x07B0) {
-		// Adjust volume changes by master volume
-		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-	} else if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
+	if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
 		b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
 	}
-	else if ((b & 0xFFF0) == 0x007BB0) {
-		// Only respond to All Notes Off if this channel
-		// has currently been allocated
-		if (!_channel[b & 0x0F])
-			return;
-	}
-
-	if (!_channel[channel])
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
 
-	if (_channel[channel])
-		_channel[channel]->send(b);
-}
-
-void MusicPlayer::metaEvent(byte type, byte *data, uint16 length) {
-
-	switch (type) {
-	case 0x2F:	// End of Track
-		if (_looping)
-			_parser->jumpToTick(0);
-		else
-			stop();
-		break;
-	default:
-		//warning("Unhandled meta event: %02x", type);
-		break;
-	}
+	Audio::MidiPlayer::send(b);
 }
 
 void MusicPlayer::onTimer(void *refCon) {
@@ -164,7 +113,7 @@ void MusicPlayer::playXMIDI(GenericResource *midiResource, MusicFlags flags) {
 
 		setVolume(127);
 
-		_looping = flags & MUSIC_LOOP;
+		_isLooping = flags & MUSIC_LOOP;
 		_isPlaying = true;
 	}
 }
@@ -190,21 +139,11 @@ void MusicPlayer::playSMF(GenericResource *midiResource, MusicFlags flags) {
 
 		setVolume(127);
 
-		_looping = flags & MUSIC_LOOP;
+		_isLooping = flags & MUSIC_LOOP;
 		_isPlaying = true;
 	}
 }
 
-void MusicPlayer::stop() {
-	Common::StackLock lock(_mutex);
-
-	_isPlaying = false;
-	if (_parser) {
-		_parser->unloadMusic();
-		_parser = NULL;
-	}
-}
-
 void MusicPlayer::pause() {
 	setVolume(-1);
 	_isPlaying = false;
diff --git a/engines/made/music.h b/engines/made/music.h
index 43869ca..8925440 100644
--- a/engines/made/music.h
+++ b/engines/made/music.h
@@ -28,7 +28,7 @@
 #ifndef MADE_MUSIC_H
 #define MADE_MUSIC_H
 
-#include "audio/mididrv.h"
+#include "audio/midiplayer.h"
 #include "audio/midiparser.h"
 #include "common/mutex.h"
 
@@ -41,48 +41,28 @@ enum MusicFlags {
 	MUSIC_LOOP = 1
 };
 
-class MusicPlayer : public MidiDriver_BASE {
+class MusicPlayer : public Audio::MidiPlayer {
 public:
 	MusicPlayer();
 	~MusicPlayer();
 
-	bool isPlaying() const { return _isPlaying; }
-	void setPlaying(bool playing) { _isPlaying = playing; }
-
-	void setVolume(int volume);
-	int getVolume() const { return _masterVolume; }
-
-	bool hasNativeMT32() const { return _nativeMT32; }
 	void playXMIDI(GenericResource *midiResource, MusicFlags flags = MUSIC_NORMAL);
 	void playSMF(GenericResource *midiResource, MusicFlags flags = MUSIC_NORMAL);
-	void stop();
+//	void stop();
 	void pause();
 	void resume();
-	void setLoop(bool loop) { _looping = loop; }
 
 	void setGM(bool isGM) { _isGM = isGM; }
 
 	// 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;
-	byte _channelVolume[16];
-	bool _nativeMT32;
 	bool _isGM;
-
-	bool _isPlaying;
-	bool _looping;
-	byte _masterVolume;
 };
 
 } // End of namespace Made


Commit: 7cc04f25ff614df96a805fb1c64b12c422e7022e
    https://github.com/scummvm/scummvm/commit/7cc04f25ff614df96a805fb1c64b12c422e7022e
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:47-07:00

Commit Message:
PARALLACTION: Change MidiPlayer impls to derive from Audio::MidiPlayer

Changed paths:
    engines/parallaction/sound_br.cpp
    engines/parallaction/sound_ns.cpp



diff --git a/engines/parallaction/sound_br.cpp b/engines/parallaction/sound_br.cpp
index c80f96b..1bc085f 100644
--- a/engines/parallaction/sound_br.cpp
+++ b/engines/parallaction/sound_br.cpp
@@ -27,8 +27,8 @@
 #include "common/util.h"
 
 #include "audio/mixer.h"
-#include "audio/mididrv.h"
 #include "audio/midiparser.h"
+#include "audio/midiplayer.h"
 #include "audio/mods/protracker.h"
 #include "audio/decoders/raw.h"
 
@@ -201,13 +201,9 @@ MidiParser *createParser_MSC() {
 }
 
 
-class MidiPlayer_MSC : public MidiDriver_BASE {
+class MidiPlayer_MSC : public Audio::MidiPlayer {
 public:
 
-	enum {
-		NUM_CHANNELS = 16
-	};
-
 	MidiPlayer_MSC(MidiDriver *driver);
 	~MidiPlayer_MSC();
 
@@ -215,42 +211,26 @@ public:
 	void stop();
 	void pause(bool p);
 	void updateTimer();
-	void adjustVolume(int diff);
 	void setVolume(int volume);
-	int getVolume() const { return _masterVolume; }
-	void setLooping(bool loop) { _isLooping = loop; }
 
 	// MidiDriver_BASE interface
 	virtual void send(uint32 b);
-	virtual void metaEvent(byte type, byte *data, uint16 length);
 
 private:
 
 	static void timerCallback(void *p);
 	void setVolumeInternal(int volume);
 
-	Common::Mutex _mutex;
-	MidiDriver *_driver;
-	MidiParser *_parser;
 	uint8 *_midiData;
-	bool _isLooping;
-	bool _isPlaying;
 	bool _paused;
-
-	int _masterVolume;
-	MidiChannel *_channels[NUM_CHANNELS];
-	uint8 _volume[NUM_CHANNELS];
 };
 
 
 
 MidiPlayer_MSC::MidiPlayer_MSC(MidiDriver *driver)
-	: _driver(driver), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _paused(false), _masterVolume(0) {
+	: _midiData(0), _paused(false) {
+	_driver = driver;
 	assert(_driver);
-	memset(_channels, 0, sizeof(_channels));
-	for (int i = 0; i < NUM_CHANNELS; i++) {
-		_volume[i] = 127;
-	}
 
 	int ret = _driver->open();
 	if (ret == 0) {
@@ -295,13 +275,9 @@ void MidiPlayer_MSC::play(Common::SeekableReadStream *stream) {
 }
 
 void MidiPlayer_MSC::stop() {
-	Common::StackLock lock(_mutex);
-	if (_isPlaying) {
-		_isPlaying = false;
-		_parser->unloadMusic();
-		free(_midiData);
-		_midiData = 0;
-	}
+	Audio::MidiPlayer::stop();
+	free(_midiData);
+	_midiData = 0;
 }
 
 void MidiPlayer_MSC::pause(bool p) {
@@ -320,10 +296,6 @@ void MidiPlayer_MSC::updateTimer() {
 	}
 }
 
-void MidiPlayer_MSC::adjustVolume(int diff) {
-	setVolume(_masterVolume + diff);
-}
-
 void MidiPlayer_MSC::setVolume(int volume) {
 	_masterVolume = CLIP(volume, 0, 255);
 	setVolumeInternal(_masterVolume);
@@ -331,43 +303,28 @@ void MidiPlayer_MSC::setVolume(int volume) {
 
 void MidiPlayer_MSC::setVolumeInternal(int volume) {
 	Common::StackLock lock(_mutex);
-	for (int i = 0; i < NUM_CHANNELS; ++i) {
-		if (_channels[i]) {
-			_channels[i]->volume(_volume[i] * volume / 255);
+	for (int i = 0; i < kNumChannels; ++i) {
+		if (_channelsTable[i]) {
+			_channelsTable[i]->volume(_channelsVolume[i] * volume / 255);
 		}
 	}
 }
 
 void MidiPlayer_MSC::send(uint32 b) {
+	// FIXME/TODO: Unlike Audio::MidiPlayer::send(), this code
+	// does not handle All Note Off. Is this on purpose?
+	// If not, we could simply remove this method, and use the
+	// inherited one.
 	const byte ch = b & 0x0F;
 	byte param2 = (b >> 16) & 0xFF;
 
 	switch (b & 0xFFF0) {
 	case 0x07B0: // volume change
-		_volume[ch] = param2;
+		_channelsVolume[ch] = param2;
 		break;
 	}
 
-	if (!_channels[ch]) {
-		_channels[ch] = (ch == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
-	}
-	if (_channels[ch]) {
-		_channels[ch]->send(b);
-	}
-}
-
-void MidiPlayer_MSC::metaEvent(byte type, byte *data, uint16 length) {
-	switch (type) {
-	case 0x2F: // end of Track
-		if (_isLooping) {
-			_parser->jumpToTick(0);
-		} else {
-			stop();
-		}
-		break;
-	default:
-		break;
-	}
+	sendToChannel(ch, b);
 }
 
 void MidiPlayer_MSC::timerCallback(void *p) {
diff --git a/engines/parallaction/sound_ns.cpp b/engines/parallaction/sound_ns.cpp
index f924364..8f3f0c3 100644
--- a/engines/parallaction/sound_ns.cpp
+++ b/engines/parallaction/sound_ns.cpp
@@ -29,6 +29,7 @@
 
 #include "audio/mixer.h"
 #include "audio/midiparser.h"
+#include "audio/midiplayer.h"
 #include "audio/mods/protracker.h"
 #include "audio/decoders/raw.h"
 
@@ -38,13 +39,9 @@
 
 namespace Parallaction {
 
-class MidiPlayer : public MidiDriver_BASE {
+class MidiPlayer : public Audio::MidiPlayer {
 public:
 
-	enum {
-		NUM_CHANNELS = 16
-	};
-
 	MidiPlayer(MidiDriver *driver);
 	~MidiPlayer();
 
@@ -52,38 +49,18 @@ public:
 	void stop();
 	void pause(bool p);
 	void updateTimer();
-	void adjustVolume(int diff);
-	void setVolume(int volume);
-	int getVolume() const { return _masterVolume; }
-	void setLooping(bool loop) { _isLooping = loop; }
-
-	// MidiDriver_BASE interface
-	virtual void send(uint32 b);
-	virtual void metaEvent(byte type, byte *data, uint16 length);
 
 private:
-
 	static void timerCallback(void *p);
 
-	MidiDriver *_driver;
-	MidiParser *_parser;
 	uint8 *_midiData;
-	bool _isLooping;
-	bool _isPlaying;
 	bool _paused;
-	int _masterVolume;
-	MidiChannel *_channelsTable[NUM_CHANNELS];
-	uint8 _channelsVolume[NUM_CHANNELS];
-	Common::Mutex _mutex;
 };
 
 MidiPlayer::MidiPlayer(MidiDriver *driver)
-	: _driver(driver), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _paused(false), _masterVolume(0) {
-	assert(_driver);
-	memset(_channelsTable, 0, sizeof(_channelsTable));
-	for (int i = 0; i < NUM_CHANNELS; i++) {
-		_channelsVolume[i] = 127;
-	}
+	: _midiData(0), _paused(false) {
+	assert(driver);
+	_driver = driver;
 
 	int ret = _driver->open();
 	if (ret == 0) {
@@ -128,19 +105,15 @@ void MidiPlayer::play(Common::SeekableReadStream *stream) {
 }
 
 void MidiPlayer::stop() {
-	Common::StackLock lock(_mutex);
-	if (_isPlaying) {
-		_isPlaying = false;
-		_parser->unloadMusic();
-		free(_midiData);
-		_midiData = 0;
-	}
+	Audio::MidiPlayer::stop();
+	free(_midiData);
+	_midiData = 0;
 }
 
 void MidiPlayer::pause(bool p) {
 	_paused = p;
 
-	for (int i = 0; i < NUM_CHANNELS; ++i) {
+	for (int i = 0; i < kNumChannels; ++i) {
 		if (_channelsTable[i]) {
 			_channelsTable[i]->volume(_paused ? 0 : _channelsVolume[i] * _masterVolume / 255);
 		}
@@ -158,61 +131,6 @@ void MidiPlayer::updateTimer() {
 	}
 }
 
-void MidiPlayer::adjustVolume(int diff) {
-	setVolume(_masterVolume + diff);
-}
-
-void MidiPlayer::setVolume(int volume) {
-	_masterVolume = CLIP(volume, 0, 255);
-
-	Common::StackLock lock(_mutex);
-	for (int i = 0; i < NUM_CHANNELS; ++i) {
-		if (_channelsTable[i]) {
-			_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
-		}
-	}
-}
-
-void MidiPlayer::send(uint32 b) {
-	byte volume, ch = (byte)(b & 0xF);
-	switch (b & 0xFFF0) {
-	case 0x07B0: // volume change
-		volume = (byte)((b >> 16) & 0x7F);
-		_channelsVolume[ch] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-		break;
-	case 0x7BB0: // all notes off
-		if (!_channelsTable[ch]) {
-			// channel not yet allocated, no need to send the event
-			return;
-		}
-		break;
-	}
-
-	if (!_channelsTable[ch]) {
-		_channelsTable[ch] = (ch == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
-	}
-	if (_channelsTable[ch]) {
-		_channelsTable[ch]->send(b);
-	}
-}
-
-void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
-	switch (type) {
-	case 0x2F: // end of Track
-		if (_isLooping) {
-			_parser->jumpToTick(0);
-		} else {
-			stop();
-		}
-		break;
-	default:
-//		warning("Unhandled meta event: %02x", type);
-		break;
-	}
-}
-
 void MidiPlayer::timerCallback(void *p) {
 	MidiPlayer *player = (MidiPlayer *)p;
 


Commit: 47e347b9227e4472fdefbfa8f2811dd95d0e7a2f
    https://github.com/scummvm/scummvm/commit/47e347b9227e4472fdefbfa8f2811dd95d0e7a2f
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:48-07:00

Commit Message:
TINSEL: Change MidiMusicPlayer to derive from Audio::MidiPlayer

Changed paths:
    engines/tinsel/music.cpp
    engines/tinsel/music.h



diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp
index 235f03a..943beb4 100644
--- a/engines/tinsel/music.cpp
+++ b/engines/tinsel/music.cpp
@@ -386,7 +386,7 @@ void DeleteMidiBuffer() {
 	midiBuffer.pDat = NULL;
 }
 
-MidiMusicPlayer::MidiMusicPlayer() : _parser(0), _driver(0), _looping(false), _isPlaying(false) {
+MidiMusicPlayer::MidiMusicPlayer() {
 	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);
@@ -396,10 +396,6 @@ MidiMusicPlayer::MidiMusicPlayer() : _parser(0), _driver(0), _looping(false), _i
 	if (native_mt32)
 		_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
 
-	memset(_channel, 0, sizeof(_channel));
-	memset(_channelVolume, 0, sizeof(_channelVolume));
-	_masterVolume = 0;
-
 	int ret = _driver->open();
 	if (ret == 0) {
 		if (native_mt32)
@@ -428,64 +424,23 @@ MidiMusicPlayer::~MidiMusicPlayer() {
 void MidiMusicPlayer::setVolume(int volume) {
 	_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
 
-	if (_masterVolume == volume)
-		return;
-
-	_masterVolume = volume;
-
-	Common::StackLock lock(_mutex);
-
-	for (int i = 0; i < 16; ++i) {
-		if (_channel[i]) {
-			_channel[i]->volume(_channelVolume[i] * _masterVolume / 255);
-		}
-	}
+	Audio::MidiPlayer::setVolume(volume);
 }
 
 void MidiMusicPlayer::send(uint32 b) {
-	byte channel = (byte)(b & 0x0F);
-	if ((b & 0xFFF0) == 0x07B0) {
-		// Adjust volume changes by master volume
-		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
-		volume = volume * _masterVolume / 255;
-		b = (b & 0xFF00FFFF) | (volume << 16);
-	} else if ((b & 0xFFF0) == 0x007BB0) {
-		// Only respond to All Notes Off if this channel
-		// has currently been allocated
-		if (!_channel[b & 0x0F])
-			return;
-	}
-
-	if (!_channel[channel])
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
-
-	if (_channel[channel]) {
-		_channel[channel]->send(b);
+	Audio::MidiPlayer::send(b);
 
+	byte channel = (byte)(b & 0x0F);
+	if (_channelsTable[channel]) {
 		if ((b & 0xFFF0) == 0x0079B0) {
 			// We've just Reset All Controllers, so we need to
 			// re-adjust the volume. Otherwise, volume is reset to
 			// default whenever the music changes.
-			_channel[channel]->send(0x000007B0 | (((_channelVolume[channel] * _masterVolume) / 255) << 16) | channel);
+			_channelsTable[channel]->send(0x000007B0 | (((_channelsVolume[channel] * _masterVolume) / 255) << 16) | channel);
 		}
 	}
 }
 
-void MidiMusicPlayer::metaEvent(byte type, byte *data, uint16 length) {
-	switch (type) {
-	case 0x2F:	// End of Track
-		if (_looping)
-			_parser->jumpToTick(0);
-		else
-			stop();
-		break;
-	default:
-		//warning("Unhandled meta event: %02x", type);
-		break;
-	}
-}
-
 void MidiMusicPlayer::onTimer(void *refCon) {
 	MidiMusicPlayer *music = (MidiMusicPlayer *)refCon;
 	Common::StackLock lock(music->_mutex);
@@ -522,21 +477,11 @@ void MidiMusicPlayer::playXMIDI(byte *midiData, uint32 size, bool loop) {
 
 		_parser = parser;
 
-		_looping = loop;
+		_isLooping = loop;
 		_isPlaying = true;
 	}
 }
 
-void MidiMusicPlayer::stop() {
-	Common::StackLock lock(_mutex);
-
-	_isPlaying = false;
-	if (_parser) {
-		_parser->unloadMusic();
-		_parser = NULL;
-	}
-}
-
 void MidiMusicPlayer::pause() {
 	setVolume(-1);
 	_isPlaying = false;
diff --git a/engines/tinsel/music.h b/engines/tinsel/music.h
index 1857032..9436c02 100644
--- a/engines/tinsel/music.h
+++ b/engines/tinsel/music.h
@@ -28,12 +28,13 @@
 #ifndef TINSEL_MUSIC_H
 #define TINSEL_MUSIC_H
 
-#include "audio/mididrv.h"
-#include "audio/midiparser.h"
+#include "audio/midiplayer.h"
 #include "audio/audiostream.h"
 #include "audio/mixer.h"
 #include "common/mutex.h"
 
+class MidiParser;
+
 namespace Tinsel {
 
 bool PlayMidiSequence(		// Plays the specified MIDI sequence through the sound driver
@@ -60,27 +61,21 @@ SCNHANDLE GetTrackOffset(int trackNumber);
 
 void dumpMusic();
 
-class MidiMusicPlayer : public MidiDriver_BASE {
+class MidiMusicPlayer : public Audio::MidiPlayer {
 public:
 	MidiMusicPlayer();
 	~MidiMusicPlayer();
 
-	bool isPlaying() { return _isPlaying; }
-	void setPlaying(bool playing) { _isPlaying = playing; }
-
-	void setVolume(int volume);
-	int getVolume() { return _masterVolume; }
+	virtual void setVolume(int volume);
 
 	void playXMIDI(byte *midiData, uint32 size, bool loop);
 
-	void stop();
+//	void stop();
 	void pause();
 	void resume();
-	void setLoop(bool loop) { _looping = loop; }
 
 	// MidiDriver_BASE interface implementation
 	virtual void send(uint32 b);
-	virtual void metaEvent(byte type, byte *data, uint16 length);
 
 	// The original sets the "sequence timing" to 109 Hz, whatever that
 	// means. The default is 120.
@@ -90,17 +85,7 @@ protected:
 
 	static void onTimer(void *data);
 
-	MidiParser *_parser;
-	Common::Mutex _mutex;
-
-	MidiChannel *_channel[16];
-	MidiDriver *_driver;
 	MidiParser *_xmidiParser;
-	byte _channelVolume[16];
-
-	bool _isPlaying;
-	bool _looping;
-	byte _masterVolume;
 };
 
 class PCMMusicPlayer : public Audio::AudioStream {


Commit: 6b797ccb2e82a954cc9a74fb9e8c47d5015ccf50
    https://github.com/scummvm/scummvm/commit/6b797ccb2e82a954cc9a74fb9e8c47d5015ccf50
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:48-07:00

Commit Message:
QUEEN: Rename some MidiMusic members to match Audio::MidiPlayer

Changed paths:
    engines/queen/music.cpp
    engines/queen/music.h



diff --git a/engines/queen/music.cpp b/engines/queen/music.cpp
index df5ff02..58ecfa6 100644
--- a/engines/queen/music.cpp
+++ b/engines/queen/music.cpp
@@ -40,9 +40,9 @@ namespace Queen {
 extern MidiDriver *C_Player_CreateAdLibMidiDriver(Audio::Mixer *);
 
 MidiMusic::MidiMusic(QueenEngine *vm)
-	: _isPlaying(false), _looping(false), _randomLoop(false), _masterVolume(192), _buf(0) {
+	: _isPlaying(false), _isLooping(false), _randomLoop(false), _masterVolume(192), _buf(0) {
 
-	memset(_channel, 0, sizeof(_channel));
+	memset(_channelsTable, 0, sizeof(_channelsTable));
 	_queuePos = _lastSong = _currentSong = 0;
 	queueClear();
 
@@ -118,8 +118,8 @@ void MidiMusic::setVolume(int volume) {
 	_masterVolume = volume;
 
 	for (int i = 0; i < 16; ++i) {
-		if (_channel[i])
-			_channel[i]->volume(_channelVolume[i] * _masterVolume / 255);
+		if (_channelsTable[i])
+			_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
 	}
 }
 
@@ -156,7 +156,7 @@ bool MidiMusic::queueSong(uint16 songNum) {
 void MidiMusic::queueClear() {
 	_lastSong = _songQueue[0];
 	_queuePos = 0;
-	_looping = _randomLoop = false;
+	_isLooping = _randomLoop = false;
 	memset(_songQueue, 0, sizeof(_songQueue));
 }
 
@@ -170,7 +170,7 @@ void MidiMusic::send(uint32 b) {
 	if ((b & 0xFFF0) == 0x07B0) {
 		// Adjust volume changes by master volume
 		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
+		_channelsVolume[channel] = volume;
 		volume = volume * _masterVolume / 255;
 		b = (b & 0xFF00FFFF) | (volume << 16);
 	} else if ((b & 0xF0) == 0xC0 && !_nativeMT32) {
@@ -178,7 +178,7 @@ void MidiMusic::send(uint32 b) {
 	} else if ((b & 0xFFF0) == 0x007BB0) {
 		//Only respond to All Notes Off if this channel
 		//has currently been allocated
-		if (!_channel[channel])
+		if (!_channelsTable[channel])
 			return;
 	}
 
@@ -190,17 +190,17 @@ void MidiMusic::send(uint32 b) {
 	if (channel == 5 && _currentSong == 38)
 		return;
 
-	if (!_channel[channel])
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
+	if (!_channelsTable[channel])
+		_channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
 
-	if (_channel[channel])
-		_channel[channel]->send(b);
+	if (_channelsTable[channel])
+		_channelsTable[channel]->send(b);
 }
 
 void MidiMusic::metaEvent(byte type, byte *data, uint16 length) {
 	switch (type) {
 	case 0x2F: // End of Track
-		if (_looping || _songQueue[1]) {
+		if (_isLooping || _songQueue[1]) {
 			playMusic();
 		} else {
 			stopMusic();
@@ -333,7 +333,7 @@ void MidiMusic::queueUpdatePos() {
 	} else {
 		if (_queuePos < (MUSIC_QUEUE_SIZE - 1) && _songQueue[_queuePos + 1])
 			_queuePos++;
-		else if (_looping)
+		else if (_isLooping)
 			_queuePos = 0;
 	}
 }
diff --git a/engines/queen/music.h b/engines/queen/music.h
index 09d29fb..3e8fc58 100644
--- a/engines/queen/music.h
+++ b/engines/queen/music.h
@@ -50,7 +50,7 @@ public:
 	void stopSong() { stopMusic(); }
 	void playMusic();
 	void stopMusic();
-	void setLoop(bool loop)		{ _looping = loop; }
+	void setLoop(bool loop)		{ _isLooping = loop; }
 	void queueTuneList(int16 tuneList);
 	bool queueSong(uint16 songNum);
 	void queueClear();
@@ -76,15 +76,15 @@ protected:
 
 	MidiDriver *_driver;
 	MidiParser *_parser;
-	MidiChannel *_channel[16];
-	byte _channelVolume[16];
+	MidiChannel *_channelsTable[16];
+	byte _channelsVolume[16];
 	bool _adlib;
 	bool _nativeMT32;
 	Common::Mutex _mutex;
 	Common::RandomSource _rnd;
 
 	bool _isPlaying;
-	bool _looping;
+	bool _isLooping;
 	bool _randomLoop;
 	byte _masterVolume;
 	uint8 _queuePos;


Commit: 06b5432e94d2bb102852f404dfe53ec6ceb154e7
    https://github.com/scummvm/scummvm/commit/06b5432e94d2bb102852f404dfe53ec6ceb154e7
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:48-07:00

Commit Message:
SAGA: Rename some MusicDriver members to match Audio::MidiPlayer

Changed paths:
    engines/saga/music.cpp
    engines/saga/music.h



diff --git a/engines/saga/music.cpp b/engines/saga/music.cpp
index 6db55c2..8554a22 100644
--- a/engines/saga/music.cpp
+++ b/engines/saga/music.cpp
@@ -44,7 +44,7 @@ namespace Saga {
 #define MUSIC_SUNSPOT 26
 
 MusicDriver::MusicDriver() : _isGM(false) {
-	memset(_channel, 0, sizeof(_channel));
+	memset(_channelsTable, 0, sizeof(_channelsTable));
 	_masterVolume = 0;
 	_nativeMT32 = ConfMan.getBool("native_mt32");
 
@@ -80,8 +80,8 @@ void MusicDriver::setVolume(int volume) {
 	Common::StackLock lock(_mutex);
 
 	for (int i = 0; i < 16; ++i) {
-		if (_channel[i]) {
-			_channel[i]->volume(_channelVolume[i] * _masterVolume / 255);
+		if (_channelsTable[i]) {
+			_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
 		}
 	}
 }
@@ -91,7 +91,7 @@ void MusicDriver::send(uint32 b) {
 	if ((b & 0xFFF0) == 0x07B0) {
 		// Adjust volume changes by master volume
 		byte volume = (byte)((b >> 16) & 0x7F);
-		_channelVolume[channel] = volume;
+		_channelsVolume[channel] = volume;
 		volume = volume * _masterVolume / 255;
 		b = (b & 0xFF00FFFF) | (volume << 16);
 	} else if ((b & 0xF0) == 0xC0 && !_isGM && !isMT32()) {
@@ -100,14 +100,14 @@ void MusicDriver::send(uint32 b) {
 	} else if ((b & 0xFFF0) == 0x007BB0) {
 		// Only respond to All Notes Off if this channel
 		// has currently been allocated
-		if (!_channel[channel])
+		if (!_channelsTable[channel])
 			return;
 	}
 
-	if (!_channel[channel])
-		_channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
+	if (!_channelsTable[channel])
+		_channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
 	else
-		_channel[channel]->send(b);
+		_channelsTable[channel]->send(b);
 }
 
 Music::Music(SagaEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) {
diff --git a/engines/saga/music.h b/engines/saga/music.h
index 745f322..25b54cf 100644
--- a/engines/saga/music.h
+++ b/engines/saga/music.h
@@ -67,10 +67,10 @@ public:
 
 protected:
 
-	MidiChannel *_channel[16];
+	MidiChannel *_channelsTable[16];
 	MidiDriver *_driver;
 	MusicType _driverType;
-	byte _channelVolume[16];
+	byte _channelsVolume[16];
 	bool _isGM;
 	bool _nativeMT32;
 


Commit: 9a646cde46c1d61ab14c057a0142e851e9ec3a91
    https://github.com/scummvm/scummvm/commit/9a646cde46c1d61ab14c057a0142e851e9ec3a91
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:46:49-07:00

Commit Message:
HUGO: Turn FileManager::getBootCypher into a const static variable

Changed paths:
    engines/hugo/file.cpp
    engines/hugo/file.h



diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index 214390c..b0ef2d1 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -46,6 +46,13 @@
 #include "hugo/mouse.h"
 
 namespace Hugo {
+
+namespace {
+static const char *s_bootCyper = "Copyright 1992, David P Gray, Gray Design Associates";
+static const int s_bootCyperLen = sizeof(s_bootCyper) - 1;
+}
+
+
 FileManager::FileManager(HugoEngine *vm) : _vm(vm) {
 	has_read_header = false;
 	firstUIFFl = true;
@@ -523,7 +530,6 @@ bool FileManager::restoreGame(const int16 slot) {
  */
 void FileManager::printBootText() {
 	debugC(1, kDebugFile, "printBootText()");
-	static const char *cypher = getBootCypher();
 
 	Common::File ofp;
 	if (!ofp.open(getBootFilename())) {
@@ -547,7 +553,7 @@ void FileManager::printBootText() {
 		// Decrypt the exit text, using CRYPT substring
 		int i;
 		for (i = 0; i < _vm->_boot.exit_len; i++)
-			buf[i] ^= cypher[i % strlen(cypher)];
+			buf[i] ^= s_bootCyper[i % s_bootCyperLen];
 
 		buf[i] = '\0';
 		Utils::notifyBox(buf);
@@ -563,7 +569,6 @@ void FileManager::printBootText() {
  */
 void FileManager::readBootFile() {
 	debugC(1, kDebugFile, "readBootFile()");
-	static const char *cypher = getBootCypher();
 
 	Common::File ofp;
 	if (!ofp.open(getBootFilename())) {
@@ -592,7 +597,7 @@ void FileManager::readBootFile() {
 	byte checksum = 0;
 	for (uint32 i = 0; i < sizeof(_vm->_boot); i++) {
 		checksum ^= p[i];
-		p[i] ^= cypher[i % strlen(cypher)];
+		p[i] ^= s_bootCyper[i % s_bootCyperLen];
 	}
 	ofp.close();
 
@@ -669,8 +674,5 @@ void FileManager::readUIFImages() {
 	readUIFItem(UIF_IMAGES, _vm->_screen->getGUIBuffer());   // Read all uif images
 }
 
-const char *FileManager::getBootCypher() const {
-	return "Copyright 1992, David P Gray, Gray Design Associates";
-}
 } // End of namespace Hugo
 
diff --git a/engines/hugo/file.h b/engines/hugo/file.h
index 77c6811..0e13134 100644
--- a/engines/hugo/file.h
+++ b/engines/hugo/file.h
@@ -118,7 +118,6 @@ protected:
 	PCC_header_t PCC_header;
 
 	seq_t *readPCX(Common::ReadStream &f, seq_t *seqPtr, byte *imagePtr, const bool firstFl, const char *name);
-	const char *getBootCypher() const;
 
 	// If this is the first call, read the lookup table
 	bool has_read_header;


Commit: 62f5c475f3bf7482526ce58bd90f37343ef523a6
    https://github.com/scummvm/scummvm/commit/62f5c475f3bf7482526ce58bd90f37343ef523a6
Author: Max Horn (max at quendi.de)
Date: 2011-03-24T08:49:46-07:00

Commit Message:
AUDIO: Expand MidiPlayer docs / goals a bit, mention deadlock bug

Changed paths:
    audio/midiplayer.h



diff --git a/audio/midiplayer.h b/audio/midiplayer.h
index 913d49c..fd60d0b 100644
--- a/audio/midiplayer.h
+++ b/audio/midiplayer.h
@@ -41,6 +41,18 @@ namespace Audio {
  * start of the real thing, which tries to include code replicated between
  * several of our engines.
  *
+ * Eventually, this should offer ways to start playback of SMF and XMIDI
+ * data (and possibly make it easy to add further playback methods),
+ * should be able to automatically instantiate _driver as needed,
+ * should perform memory management on the MidiParser object(s) being
+ * used, and possibly more.
+ *
+ * Also, care should be taken to ensure that mutex locking is done right;
+ * currently, it isn't: That is, many engines have (and already had before
+ * this class was introduced) various potential deadlocks hiding in their
+ * MIDI code, caused by a thread trying to lock a mutex twice -- this may
+ * work on some systems, but on others is a sure way towards a deadlock.
+ *
  * @todo Document origin of this class. It is based on code shared by
  * several engines (e.g. DRACI says it copied it from MADE, which took
  * it from SAGE).






More information about the Scummvm-git-logs mailing list