[Scummvm-cvs-logs] CVS: scummvm/scumm imuse.cpp,2.88,2.89 imuse.h,1.42,1.43 imuse_digi.cpp,1.42,1.43 imuse_digi.h,1.11,1.12 imuse_internal.h,2.18,2.19 imuse_player.cpp,2.28,2.29 music.h,2.2,2.3 player_v1.h,1.4,1.5 player_v2.cpp,2.25,2.26 player_v2.h,2.12,2.13 player_v3a.cpp,1.3,1.4 player_v3a.h,1.2,1.3 resource.cpp,1.148,1.149 sound.cpp,1.237,1.238 sound.h,1.44,1.45

Max Horn fingolfin at users.sourceforge.net
Sun Sep 7 10:16:03 CEST 2003


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv11361

Modified Files:
	imuse.cpp imuse.h imuse_digi.cpp imuse_digi.h imuse_internal.h 
	imuse_player.cpp music.h player_v1.h player_v2.cpp player_v2.h 
	player_v3a.cpp player_v3a.h resource.cpp sound.cpp sound.h 
Log Message:
some cleanup; clarified isSoundInUse semantics and the difference between IMuse::get_sound_active and IMuse::getSoundStatus; added lots of const qualifiers to IMuse; rewrote IMuseInternal::getSoundStatus (hopefully not breaking it); added MusicEngine::getSoundStatus

Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse.cpp,v
retrieving revision 2.88
retrieving revision 2.89
diff -u -d -r2.88 -r2.89
--- imuse.cpp	7 Sep 2003 16:16:19 -0000	2.88
+++ imuse.cpp	7 Sep 2003 17:14:55 -0000	2.89
@@ -424,25 +424,23 @@
 	return best;
 }
 
-int IMuseInternal::getSoundStatus(int sound, bool ignoreFadeouts) {
-	Player *player;
-	if (sound == -1) {
-		player = _players;
-		for (int i = ARRAYSIZE(_players); i; --i, ++player) {
-			if (player->isActive() &&(!ignoreFadeouts || !player->isFadingOut()))
+int IMuseInternal::getSoundStatus(int sound, bool ignoreFadeouts) const {
+	int i;
+	const Player *player = _players;
+
+	for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
+		if (player->isActive() && (!ignoreFadeouts || !player->isFadingOut())) {
+			if (sound == -1)
 				return player->getID();
+			else if (player->getID() == (uint16)sound)
+				return 1;
 		}
-		return 0;
 	}
-
-	player = findActivePlayer(sound);
-	if (player &&(!ignoreFadeouts || !player->isFadingOut()))
-		return 1;
-	return get_queue_sound_status(sound);
+	return (sound == -1) ? 0 : get_queue_sound_status(sound);
 }
 
-int IMuseInternal::get_queue_sound_status(int sound) {
-	uint16 *a;
+int IMuseInternal::get_queue_sound_status(int sound) const {
+	const uint16 *a;
 	int i, j;
 
 	j = _queue_pos;
@@ -1049,9 +1047,9 @@
 
 Player *IMuseInternal::findActivePlayer(int id) {
 	int i;
-	Player *player;
+	Player *player = _players;
 
-	for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
+	for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
 		if (player->isActive() && player->getID() == (uint16)id)
 			return player;
 	}
@@ -1746,8 +1744,8 @@
 
 IMuse::IMuse(OSystem *system, IMuseInternal *target) : _system(system), _target(target) { _mutex = system->create_mutex(); }
 IMuse::~IMuse() { if (_mutex) _system->delete_mutex(_mutex); if (_target) delete _target; }
-inline void IMuse::in() { _system->lock_mutex(_mutex); }
-inline void IMuse::out() { _system->unlock_mutex(_mutex); }
+inline void IMuse::in() const { _system->lock_mutex(_mutex); }
+inline void IMuse::out() const { _system->unlock_mutex(_mutex); }
 
 void IMuse::on_timer(MidiDriver *midi) { in(); _target->on_timer(midi); out(); }
 void IMuse::pause(bool paused) { in(); _target->pause(paused); out(); }
@@ -1759,8 +1757,8 @@
 void IMuse::startSound(int sound) { in(); _target->startSound(sound); out(); }
 void IMuse::stopSound(int sound) { in(); _target->stopSound(sound); out(); }
 int IMuse::stopAllSounds() { in(); int ret = _target->stopAllSounds(); out(); return ret; }
-int IMuse::getSoundStatus(int sound) { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; }
-bool IMuse::get_sound_active(int sound) { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; }
+int IMuse::getSoundStatus(int sound) const { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; }
+bool IMuse::get_sound_active(int sound) const { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; }
 int IMuse::getMusicTimer() { in(); int ret = _target->getMusicTimer(); out(); return ret; }
 int32 IMuse::doCommand (int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->doCommand(a,b,c,d,e,f,g,h); out(); return ret; }
 int32 IMuse::doCommand (int numargs, int args[]) { in(); int32 ret = _target->doCommand (numargs, args); out(); return ret; }

Index: imuse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- imuse.h	7 Sep 2003 16:16:19 -0000	1.42
+++ imuse.h	7 Sep 2003 17:14:56 -0000	1.43
@@ -38,11 +38,11 @@
 private:
 	OSystem *_system;
 	IMuseInternal *_target;
-	OSystem::MutexRef _mutex;
+	mutable OSystem::MutexRef _mutex;
 
 	IMuse(OSystem *system, IMuseInternal *target);
-	void in();
-	void out();
+	void in() const;
+	void out() const;
 
 public:
 	~IMuse();
@@ -66,8 +66,8 @@
 	void startSound(int sound);
 	void stopSound(int sound);
 	int stopAllSounds();
-	int getSoundStatus(int sound);
-	bool get_sound_active(int sound);
+	int getSoundStatus(int sound) const;
+	bool get_sound_active(int sound) const;
 	int getMusicTimer();
 	int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h);
 	int32 doCommand (int numargs, int args[]);

Index: imuse_digi.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- imuse_digi.cpp	7 Sep 2003 16:28:41 -0000	1.42
+++ imuse_digi.cpp	7 Sep 2003 17:14:56 -0000	1.43
@@ -1164,15 +1164,15 @@
 	}
 }
 
-bool IMuseDigital::getSoundStatus(int sound) {
+int IMuseDigital::getSoundStatus(int sound) const {
 	debug(5, "IMuseDigital::getSoundStatus(%d)", sound);
 	for (int l = 0; l < MAX_DIGITAL_CHANNELS; l++) {
 		if ((_channel[l]._idSound == sound) && _channel[l]._used) {
-			return true;
+			return 1;
 		}
 	}
 
-	return false;
+	return 0;
 }
 
 

Index: imuse_digi.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- imuse_digi.h	7 Sep 2003 16:28:41 -0000	1.11
+++ imuse_digi.h	7 Sep 2003 17:14:56 -0000	1.12
@@ -72,7 +72,7 @@
 	void stopAll();
 	void pause(bool pause);
 	int32 doCommand(int a, int b, int c, int d, int e, int f, int g, int h);
-	bool getSoundStatus(int sound);
+	int getSoundStatus(int sound) const;
 };
 
 #endif

Index: imuse_internal.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_internal.h,v
retrieving revision 2.18
retrieving revision 2.19
diff -u -d -r2.18 -r2.19
--- imuse_internal.h	7 Sep 2003 16:16:19 -0000	2.18
+++ imuse_internal.h	7 Sep 2003 17:14:56 -0000	2.19
@@ -232,21 +232,21 @@
 	void   fixAfterLoad();
 	Part * getActivePart(uint8 part);
 	uint   getBeatIndex();
-	int8   getDetune() { return _detune; }
-	byte   getEffectiveVolume() { return _vol_eff; }
-	int    getID() { return _id; }
-	MidiDriver *getMidiDriver() { return _midi; }
+	int8   getDetune() const { return _detune; }
+	byte   getEffectiveVolume() const { return _vol_eff; }
+	int    getID() const { return _id; }
+	MidiDriver *getMidiDriver() const { return _midi; }
 	int    getParam(int param, byte chan);
-	int8   getPan() { return _pan; }
+	int8   getPan() const { return _pan; }
 	Part * getPart(uint8 part);
-	byte   getPriority() { return _priority; }
-	uint   getTicksPerBeat() { return TICKS_PER_BEAT; }
-	int8   getTranspose() { return _transpose; }
-	byte   getVolume() { return _volume; }
-	bool   isActive() { return _active; }
-	bool   isFadingOut();
-	bool   isGM() { return _isGM; }
-	bool   isMT32() { return _isMT32; }
+	byte   getPriority() const { return _priority; }
+	uint   getTicksPerBeat() const { return TICKS_PER_BEAT; }
+	int8   getTranspose() const { return _transpose; }
+	byte   getVolume() const { return _volume; }
+	bool   isActive() const { return _active; }
+	bool   isFadingOut() const;
+	bool   isGM() const { return _isGM; }
+	bool   isMT32() const { return _isMT32; }
 	bool   jump(uint track, uint beat, uint tick);
 	void   onTimer();
 	void   removePart(Part *part);
@@ -397,7 +397,7 @@
 	byte *findStartOfSound(int sound);
 	bool isMT32(int sound);
 	bool isGM(int sound);
-	int get_queue_sound_status(int sound);
+	int get_queue_sound_status(int sound) const;
 	void handle_marker(uint id, byte data);
 	int get_channel_volume(uint a);
 	void initMidiDriver(MidiDriver *midi);
@@ -462,7 +462,7 @@
 	bool startSound(int sound);
 	int stopSound(int sound);
 	int stopAllSounds();
-	int getSoundStatus(int sound, bool ignoreFadeouts = true);
+	int getSoundStatus(int sound, bool ignoreFadeouts = true) const;
 	int getMusicTimer();
 	int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h);
 	int32 doCommand (int numargs, int args[]);

Index: imuse_player.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_player.cpp,v
retrieving revision 2.28
retrieving revision 2.29
diff -u -d -r2.28 -r2.29
--- imuse_player.cpp	29 Aug 2003 04:05:23 -0000	2.28
+++ imuse_player.cpp	7 Sep 2003 17:14:56 -0000	2.29
@@ -132,7 +132,7 @@
 	return _parser ? (_parser->getTick() * 2 / _parser->getPPQN()) : 0;
 }
 
-bool Player::isFadingOut() {
+bool Player::isFadingOut() const {
 	int i;
 	for (i = 0; i < ARRAYSIZE(_parameterFaders); ++i) {
 		if (_parameterFaders[i].param == ParameterFader::pfVolume &&

Index: music.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/music.h,v
retrieving revision 2.2
retrieving revision 2.3
diff -u -d -r2.2 -r2.3
--- music.h	7 Sep 2003 16:28:41 -0000	2.2
+++ music.h	7 Sep 2003 17:14:56 -0000	2.3
@@ -33,7 +33,7 @@
 	virtual void startSound(int sound) = 0;
 	virtual void stopSound(int sound) = 0;
 //	virtual void stopAllSounds() = 0;
-//	virtual bool getSoundStatus(int sound) const = 0;
+	virtual int getSoundStatus(int sound) const = 0;
 };
 
 #endif

Index: player_v1.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/player_v1.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- player_v1.h	7 Sep 2003 16:16:19 -0000	1.4
+++ player_v1.h	7 Sep 2003 17:14:56 -0000	1.5
@@ -58,7 +58,7 @@
 	void clear_channel(int i);
 	void chainSound(int nr, byte *data);
 
-	void do_mix (int16 *buf, uint len);
+	void do_mix(int16 *buf, uint len);
 
 	void set_mplex(uint mplex);
 	void parseSpeakerChunk();

Index: player_v2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/player_v2.cpp,v
retrieving revision 2.25
retrieving revision 2.26
diff -u -d -r2.25 -r2.26
--- player_v2.cpp	7 Sep 2003 16:16:19 -0000	2.25
+++ player_v2.cpp	7 Sep 2003 17:14:56 -0000	2.26
@@ -522,7 +522,7 @@
 	mutex_down();
 }
 
-bool Player_V2::getSoundStatus(int nr) const {
+int Player_V2::getSoundStatus(int nr) const {
 	return _current_nr == nr || _next_nr == nr;
 }
 

Index: player_v2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/player_v2.h,v
retrieving revision 2.12
retrieving revision 2.13
diff -u -d -r2.12 -r2.13
--- player_v2.h	7 Sep 2003 16:16:19 -0000	2.12
+++ player_v2.h	7 Sep 2003 17:14:56 -0000	2.13
@@ -81,7 +81,7 @@
 	virtual void startSound(int nr);
 	virtual void stopSound(int nr);
 	virtual void stopAllSounds();
-	virtual bool getSoundStatus(int nr) const;
+	virtual int  getSoundStatus(int nr) const;
 	virtual int  getMusicTimer() const;
 
 protected:

Index: player_v3a.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/player_v3a.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- player_v3a.cpp	7 Sep 2003 16:16:19 -0000	1.3
+++ player_v3a.cpp	7 Sep 2003 17:14:56 -0000	1.4
@@ -294,11 +294,11 @@
 	return _music_timer / 30;
 }
 
-bool Player_V3A::getSoundStatus(int nr) const {
+int Player_V3A::getSoundStatus(int nr) const {
 	if (nr == _curSong)
-		return true;
+		return 1;
 	for (int i = 0; i < V3A_MAXCHANS; i++)
 		if (_soundID[i] == nr)
-			return true;
-	return false;
+			return 1;
+	return 0;
 }

Index: player_v3a.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/player_v3a.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- player_v3a.h	7 Sep 2003 16:16:19 -0000	1.2
+++ player_v3a.h	7 Sep 2003 17:14:56 -0000	1.3
@@ -45,7 +45,7 @@
 	virtual int  getMusicTimer() const;
 
 	virtual void playMusic();
-	virtual bool getSoundStatus(int nr) const;
+	virtual int  getSoundStatus(int nr) const;
 
 protected:
 	SoundMixer *_mixer;

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource.cpp,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- resource.cpp	5 Sep 2003 07:38:36 -0000	1.148
+++ resource.cpp	7 Sep 2003 17:14:56 -0000	1.149
@@ -1760,7 +1760,7 @@
 	case rtCostume:
 		return isCostumeInUse(i);
 	case rtSound:
-		return _sound->isSoundActive(i);
+		return _sound->isSoundInUse(i);
 	default:
 		return false;
 	}

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/sound.cpp,v
retrieving revision 1.237
retrieving revision 1.238
diff -u -d -r1.237 -r1.238
--- sound.cpp	7 Sep 2003 16:32:23 -0000	1.237
+++ sound.cpp	7 Sep 2003 17:14:56 -0000	1.238
@@ -179,20 +179,30 @@
 	debug(3, "playSound #%d (room %d)", soundID, _scumm->getResourceRoomNr(rtSound, soundID));
 	ptr = _scumm->getResourceAddress(rtSound, soundID);
 	if (!ptr) {
-		// FIXME: Should we replace this by an assert, and/or print an error message?
 		return;
 	}
 
 	if (READ_UINT32(ptr) == MKID('iMUS')){
-		assert(_scumm->_imuseDigital);
-		_scumm->_imuseDigital->startSound(soundID);
+		assert(_scumm->_musicEngine);
+		_scumm->_musicEngine->startSound(soundID);
 		return;
 	}
 	else if (READ_UINT32(ptr) == MKID('Crea')) {
-		assert(_scumm->_imuseDigital);
-		_scumm->_imuseDigital->startSound(soundID);
+		assert(_scumm->_musicEngine);
+		_scumm->_musicEngine->startSound(soundID);
 		return;
 	}
+/*
+	// XMIDI 
+	else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) {
+		// Pass XMIDI on to IMuse unprocessed.
+		// IMuse can handle XMIDI resources now.
+	}
+	else if (READ_UINT32(ptr) == MKID('ADL ')) {
+		// played as MIDI, just to make perhaps the later use
+		// of WA possible (see "else if" with GF_OLD256 below)
+	}
+*/
 	else if (READ_UINT32(ptr) == MKID('SOUN')) {
 		ptr += 24;
 		int track = ptr[0];
@@ -258,17 +268,6 @@
 		
 		return;
 	}	
-/*
-	// XMIDI 
-	else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) {
-		// Pass XMIDI on to IMuse unprocessed.
-		// IMuse can handle XMIDI resources now.
-	}
-	else if (READ_UINT32(ptr) == MKID('ADL ')) {
-		// played as MIDI, just to make perhaps the later use
-		// of WA possible (see "else if" with GF_OLD256 below)
-	}
-*/
 	// Support for sampled sound effects in Monkey Island 1 and 2
 	else if (READ_UINT32(ptr) == MKID('SBL ')) {
 		debug(2, "Using SBL sound effect");
@@ -645,7 +644,6 @@
 
 
 int Sound::isSoundRunning(int sound) const {
-	int i;
 
 	if (sound == _currentCDSound)
 		return pollCD();
@@ -661,12 +659,6 @@
 		}
 	}
 	
-	i = _soundQue2Pos;
-	while (i--) {
-		if (_soundQue2[i] == sound)
-			return 1;
-	}
-
 	if (isSoundInQueue(sound))
 		return 1;
 
@@ -688,41 +680,48 @@
 	return 0;
 }
 
-// This is exactly the same as isSoundRunning except that it
-// calls IMuse::get_sound_active() instead of IMuse::getSoundStatus().
-// This is necessary when determining what resources to
-// expire from memory.
-bool Sound::isSoundActive(int sound) const {
-	int i;
+/**
+ * Check whether the sound resource with the specified ID is still
+ * used. This is invoked by Scumm::isResourceInUse, to determine
+ * which resources can be expired from memory.
+ * Technically, this works very similar to isSoundRunning, however it
+ * calls IMuse::get_sound_active() instead of IMuse::getSoundStatus().
+ * The difference between those two is in how they treat sounds which
+ * are being faded out: get_sound_active() returns true even when the
+ * sound is being faded out, while getSoundStatus() returns false in
+ * that case.
+ */
+bool Sound::isSoundInUse(int sound) const {
 
 	if (sound == _currentCDSound)
 		return pollCD() != 0;
 
-	i = _soundQue2Pos;
-	while (i--) {
-		if (_soundQue2[i] == sound)
-			return true;
-	}
-
 	if (isSoundInQueue(sound))
 		return true;
 
 	if (!_scumm->isResourceLoaded(rtSound, sound))
 		return false;
 
-	if (_scumm->_imuseDigital) {
-		return _scumm->_imuseDigital->getSoundStatus(sound) != 0;
-	}
+	if (_scumm->_imuseDigital)
+		return _scumm->_imuseDigital->getSoundStatus(sound);
 
-	if (!_scumm->_imuse)
-		return false;
-	return _scumm->_imuse->get_sound_active(sound);
+	if (_scumm->_imuse)
+		return _scumm->_imuse->get_sound_active(sound);
+
+	return false;
 }
 
 bool Sound::isSoundInQueue(int sound) const {
-	int i = 0, j, num;
+	int i, j, num;
 	int16 table[16];
 
+	i = _soundQue2Pos;
+	while (i--) {
+		if (_soundQue2[i] == sound)
+			return 1;
+	}
+
+	i = 0;
 	while (i < _soundQuePos) {
 		num = _soundQue[i++];
 

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/sound.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- sound.h	1 Sep 2003 13:43:21 -0000	1.44
+++ sound.h	7 Sep 2003 17:14:56 -0000	1.45
@@ -125,7 +125,7 @@
 	void stopTalkSound();
 	bool isMouthSyncOff(uint pos);
 	int isSoundRunning(int sound) const;
-	bool isSoundActive(int sound) const;
+	bool isSoundInUse(int sound) const;
 	bool isSoundInQueue(int sound) const;
 	void stopSound(int a);
 	void stopAllSounds();





More information about the Scummvm-git-logs mailing list