[Scummvm-git-logs] scummvm master -> bf1a12220fc5d60de2ff8a8bb5533bde57973849

rvanlaar roland at rolandvanlaar.nl
Fri Jul 24 13:11:02 UTC 2020


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:
bf1a12220f DIRECTOR: Put isValidChannel check into function


Commit: bf1a12220fc5d60de2ff8a8bb5533bde57973849
    https://github.com/scummvm/scummvm/commit/bf1a12220fc5d60de2ff8a8bb5533bde57973849
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-07-24T15:09:07+02:00

Commit Message:
DIRECTOR: Put isValidChannel check into function

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


diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index 6e8dee8bcd..d7410900ba 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -63,10 +63,8 @@ DirectorSound::~DirectorSound() {
 }
 
 SoundChannel *DirectorSound::getChannel(uint8 soundChannel) {
-	if (soundChannel == 0 || soundChannel > _channels.size()) {
-		warning("Invalid sound channel %d", soundChannel);
+	if (!isChannelValid(soundChannel))
 		return nullptr;
-	}
 	return &_channels[soundChannel - 1];
 }
 
@@ -90,10 +88,8 @@ void DirectorSound::playMCI(Audio::AudioStream &stream, uint32 from, uint32 to)
 }
 
 void DirectorSound::playStream(Audio::AudioStream &stream, uint8 soundChannel) {
-	if (soundChannel == 0 || soundChannel > _channels.size()) {
-		warning("Invalid sound channel %d", soundChannel);
+	if (!isChannelValid(soundChannel))
 		return;
-	}
 
 	cancelFade(soundChannel);
 	_mixer->stopHandle(_channels[soundChannel - 1].handle);
@@ -136,10 +132,8 @@ void DirectorSound::playCastMember(int castId, uint8 soundChannel, bool allowRep
 }
 
 void DirectorSound::registerFade(uint8 soundChannel, bool fadeIn, int ticks) {
-	if (soundChannel == 0 || soundChannel > _channels.size()) {
-		warning("Invalid sound channel %d", soundChannel);
+	if (!isChannelValid(soundChannel))
 		return;
-	}
 
 	cancelFade(soundChannel);
 
@@ -151,12 +145,8 @@ void DirectorSound::registerFade(uint8 soundChannel, bool fadeIn, int ticks) {
 }
 
 bool DirectorSound::fadeChannel(uint8 soundChannel) {
-	if (soundChannel == 0 || soundChannel > _channels.size()) {
-		warning("Invalid sound channel %d", soundChannel);
+	if (!isChannelValid(soundChannel) || !isChannelActive(soundChannel))
 		return false;
-	} else if (!isChannelActive(soundChannel)) {
-			return false;
-	}
 
 	FadeParams *fade = _channels[soundChannel - 1].fade;
 	if (!fade)
@@ -192,28 +182,29 @@ void DirectorSound::cancelFade(uint8 soundChannel) {
 }
 
 bool DirectorSound::isChannelActive(uint8 soundChannel) {
-	if (soundChannel == 0 || soundChannel > _channels.size()) {
-		warning("Invalid sound channel %d", soundChannel);
+	if (!isChannelValid(soundChannel))
 		return false;
-	}
-
 	return _mixer->isSoundHandleActive(_channels[soundChannel - 1].handle);
 }
 
-int DirectorSound::lastPlayingCast(uint8 soundChannel) {
+bool DirectorSound::isChannelValid(uint8 soundChannel) {
 	if (soundChannel == 0 || soundChannel > _channels.size()) {
 		warning("Invalid sound channel %d", soundChannel);
 		return false;
 	}
+	return true;
+}
+
+int DirectorSound::lastPlayingCast(uint8 soundChannel) {
+	if (!isChannelValid(soundChannel))
+		return false;
 
 	return _channels[soundChannel - 1].lastPlayingCast;
 }
 
 void DirectorSound::stopSound(uint8 soundChannel) {
-	if (soundChannel == 0 || soundChannel > _channels.size()) {
-		warning("Invalid sound channel %d", soundChannel);
+	if (!isChannelValid(soundChannel))
 		return;
-	}
 
 	cancelFade(soundChannel);
 	_mixer->stopHandle(_channels[soundChannel - 1].handle);
diff --git a/engines/director/sound.h b/engines/director/sound.h
index ea1c4b1a08..3d3aa542ef 100644
--- a/engines/director/sound.h
+++ b/engines/director/sound.h
@@ -85,6 +85,7 @@ public:
 	void stopSound();
 
 private:
+	bool isChannelValid(uint8 soundChannel);
 	void cancelFade(uint8 soundChannel);
 };
 




More information about the Scummvm-git-logs mailing list