[Scummvm-git-logs] scummvm master -> 60111294a044fc1cfe189053050fe8468d505c6a

bluegr bluegr at gmail.com
Sun Aug 22 21:09:06 UTC 2021


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

Summary:
dcaad26e86 ENGINES: keep existExtractedCDAudioFiles in sync with DefaultAudioCDManager::play()
60111294a0 BACKENDS: moved the audio cd track path assembly into one location


Commit: dcaad26e86fe0a8f7612593d2c50c64527c5e148
    https://github.com/scummvm/scummvm/commit/dcaad26e86fe0a8f7612593d2c50c64527c5e148
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-23T00:09:03+03:00

Commit Message:
ENGINES: keep existExtractedCDAudioFiles in sync with DefaultAudioCDManager::play()

out of sync since: f5164c911758e84804ef7d4e18c72cef21185daf

Changed paths:
    backends/audiocd/default/default-audiocd.h
    engines/engine.cpp


diff --git a/backends/audiocd/default/default-audiocd.h b/backends/audiocd/default/default-audiocd.h
index 3c12560faa..83b4b94f0e 100644
--- a/backends/audiocd/default/default-audiocd.h
+++ b/backends/audiocd/default/default-audiocd.h
@@ -40,6 +40,9 @@ public:
 
 	virtual bool open();
 	virtual void close();
+	/**
+	 * @note Keep this in sync with Engine::existExtractedCDAudioFiles()
+	 */
 	virtual bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false,
 		Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
 	virtual void stop();
diff --git a/engines/engine.cpp b/engines/engine.cpp
index b62f0f0b52..e64e01b883 100644
--- a/engines/engine.cpp
+++ b/engines/engine.cpp
@@ -465,30 +465,42 @@ void GUIErrorMessageFormat(Common::U32String fmt, ...) {
  *
  * @return			true if audio files of the expected naming scheme are found, as long as ScummVM
  *					is also built with support to the respective audio format (eg. ogg, flac, mad/mp3)
+ * @note			Make sure to keep this in sync with DefaultAudioCDManager::play()
  */
 bool Engine::existExtractedCDAudioFiles() {
+	const char *extensions[] = {
 #ifdef USE_VORBIS
-	if (Common::File::exists("track1.ogg") ||
-	    Common::File::exists("track01.ogg"))
-		return true;
+		"ogg",
 #endif
 #ifdef USE_FLAC
-	if (Common::File::exists("track1.fla")  ||
-	    Common::File::exists("track1.flac") ||
-	    Common::File::exists("track01.fla") ||
-	    Common::File::exists("track01.flac"))
-		return true;
+		"fla", "flac",
 #endif
 #ifdef USE_MAD
-	if (Common::File::exists("track1.mp3") ||
-	    Common::File::exists("track01.mp3"))
-		return true;
+		"mp3",
 #endif
+		nullptr
+	};
+
+	const char *trackName[] = {
+		"track1",
+		"track01",
+		"track_1",
+		"track_01"
+	};
+
+	for (int i = 0; i < ARRAYSIZE(trackName); ++i) {
+		for (const char **ext = extensions; *ext; ++ext) {
+			const Common::String &filename = Common::String::format("%s.%s", trackName[i], *ext);
+			if (Common::File::exists(filename)) {
+				return true;
+			}
+		}
+	}
 	return false;
 }
 
 /**
- * Displays a warning on Windows version of ScummVM, if game data 
+ * Displays a warning on Windows version of ScummVM, if game data
  * are read from the same CD drive which should also play game CD audio.
  * @return			true, if this case is applicable and the warning is displayed
  */
@@ -529,7 +541,7 @@ bool Engine::isDataAndCDAudioReadFromSameCD() {
 }
 
 /**
- * Displays a warning, for the case when the game has CD audio but 
+ * Displays a warning, for the case when the game has CD audio but
  * no extracted (ripped) audio files were found.
  *
  * This method only shows the warning. It does not check for the


Commit: 60111294a044fc1cfe189053050fe8468d505c6a
    https://github.com/scummvm/scummvm/commit/60111294a044fc1cfe189053050fe8468d505c6a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-23T00:09:03+03:00

Commit Message:
BACKENDS: moved the audio cd track path assembly into one location

also added m4a audio cd support as it is supported in openStreamFile() which
is called in DefaultAudioCDManager::play()

Changed paths:
    backends/audiocd/audiocd.h
    backends/audiocd/default/default-audiocd.cpp
    backends/audiocd/default/default-audiocd.h
    engines/engine.cpp


diff --git a/backends/audiocd/audiocd.h b/backends/audiocd/audiocd.h
index 1a31cd7b20..6270b801ab 100644
--- a/backends/audiocd/audiocd.h
+++ b/backends/audiocd/audiocd.h
@@ -104,6 +104,12 @@ public:
 	 * @return a Status struct with playback data.
 	 */
 	virtual Status getStatus() const = 0;
+
+	/**
+	 * Checks whether the extracted audio cd tracks exists as files in
+	 * the search paths.
+	 */
+	virtual bool existExtractedCDAudioFiles() = 0;
 };
 
 #endif
diff --git a/backends/audiocd/default/default-audiocd.cpp b/backends/audiocd/default/default-audiocd.cpp
index e9d3e53c33..4f466e48c2 100644
--- a/backends/audiocd/default/default-audiocd.cpp
+++ b/backends/audiocd/default/default-audiocd.cpp
@@ -23,6 +23,7 @@
 #include "backends/audiocd/default/default-audiocd.h"
 #include "audio/audiostream.h"
 #include "common/config-manager.h"
+#include "common/file.h"
 #include "common/system.h"
 #include "common/util.h"
 
@@ -55,6 +56,44 @@ void DefaultAudioCDManager::close() {
 	stop();
 }
 
+void DefaultAudioCDManager::fillPotentialTrackNames(Common::Array<Common::String> &trackNames, int track) const {
+	trackNames.reserve(4);
+	trackNames.push_back(Common::String::format("track%d", track));
+	trackNames.push_back(Common::String::format("track%02d", track));
+	trackNames.push_back(Common::String::format("track_%d", track));
+	trackNames.push_back(Common::String::format("track_%02d", track));
+}
+
+bool DefaultAudioCDManager::existExtractedCDAudioFiles() {
+	// keep this in sync with STREAM_FILEFORMATS
+	const char *extensions[] = {
+#ifdef USE_VORBIS
+		"ogg",
+#endif
+#ifdef USE_FLAC
+		"fla", "flac",
+#endif
+#ifdef USE_MAD
+		"mp3",
+#endif
+		"m4a",
+		nullptr
+	};
+
+	Common::Array<Common::String> trackNames;
+	fillPotentialTrackNames(trackNames, 1);
+
+	for (Common::Array<Common::String>::iterator i = trackNames.begin(); i != trackNames.end(); ++i) {
+		for (const char **ext = extensions; *ext; ++ext) {
+			const Common::String &filename = Common::String::format("%s.%s", i->c_str(), *ext);
+			if (Common::File::exists(filename)) {
+				return true;
+			}
+		}
+	}
+	return false;
+}
+
 bool DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate,
 		Audio::Mixer::SoundType soundType) {
 	stop();
@@ -68,15 +107,13 @@ bool DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int du
 		// Try to load the track from a compressed data file, and if found, use
 		// that. If not found, attempt to start regular Audio CD playback of
 		// the requested track.
-		Common::String trackName[4];
-		trackName[0] = Common::String::format("track%d", track);
-		trackName[1] = Common::String::format("track%02d", track);
-		trackName[2] = Common::String::format("track_%d", track);
-		trackName[3] = Common::String::format("track_%02d", track);
+		Common::Array<Common::String> trackNames;
+		fillPotentialTrackNames(trackNames, track);
 		Audio::SeekableAudioStream *stream = 0;
 
-		for (int i = 0; !stream && i < ARRAYSIZE(trackName); ++i)
-			stream = Audio::SeekableAudioStream::openStreamFile(trackName[i]);
+		for (Common::Array<Common::String>::iterator i = trackNames.begin(); !stream && i != trackNames.end(); ++i) {
+			stream = Audio::SeekableAudioStream::openStreamFile(*i);
+		}
 
 		if (stream != 0) {
 			Audio::Timestamp start = Audio::Timestamp(0, startFrame, 75);
diff --git a/backends/audiocd/default/default-audiocd.h b/backends/audiocd/default/default-audiocd.h
index 83b4b94f0e..7451a15d04 100644
--- a/backends/audiocd/default/default-audiocd.h
+++ b/backends/audiocd/default/default-audiocd.h
@@ -40,9 +40,6 @@ public:
 
 	virtual bool open();
 	virtual void close();
-	/**
-	 * @note Keep this in sync with Engine::existExtractedCDAudioFiles()
-	 */
 	virtual bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false,
 		Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
 	virtual void stop();
@@ -51,6 +48,10 @@ public:
 	virtual void setBalance(int8 balance);
 	virtual void update();
 	virtual Status getStatus() const; // Subclasses should override for better status results
+	virtual bool existExtractedCDAudioFiles();
+
+private:
+	void fillPotentialTrackNames(Common::Array<Common::String> &trackNames, int track) const;
 
 protected:
 	/**
diff --git a/engines/engine.cpp b/engines/engine.cpp
index e64e01b883..b3877c24c9 100644
--- a/engines/engine.cpp
+++ b/engines/engine.cpp
@@ -47,6 +47,7 @@
 #include "common/translation.h"
 #include "common/singleton.h"
 
+#include "backends/audiocd/audiocd.h"
 #include "backends/keymapper/action.h"
 #include "backends/keymapper/keymapper.h"
 #include "base/version.h"
@@ -465,38 +466,9 @@ void GUIErrorMessageFormat(Common::U32String fmt, ...) {
  *
  * @return			true if audio files of the expected naming scheme are found, as long as ScummVM
  *					is also built with support to the respective audio format (eg. ogg, flac, mad/mp3)
- * @note			Make sure to keep this in sync with DefaultAudioCDManager::play()
  */
 bool Engine::existExtractedCDAudioFiles() {
-	const char *extensions[] = {
-#ifdef USE_VORBIS
-		"ogg",
-#endif
-#ifdef USE_FLAC
-		"fla", "flac",
-#endif
-#ifdef USE_MAD
-		"mp3",
-#endif
-		nullptr
-	};
-
-	const char *trackName[] = {
-		"track1",
-		"track01",
-		"track_1",
-		"track_01"
-	};
-
-	for (int i = 0; i < ARRAYSIZE(trackName); ++i) {
-		for (const char **ext = extensions; *ext; ++ext) {
-			const Common::String &filename = Common::String::format("%s.%s", trackName[i], *ext);
-			if (Common::File::exists(filename)) {
-				return true;
-			}
-		}
-	}
-	return false;
+	return g_system->getAudioCDManager()->existExtractedCDAudioFiles();
 }
 
 /**




More information about the Scummvm-git-logs mailing list