From 8febf6b9f58e9a1919ff370bc9714174c881dbbc Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Fri, 19 Aug 2022 20:52:29 +0200 Subject: [PATCH] SGSoundSample constructor changes - Add an explicit constructor SGSoundSample(const SGPath& file) that directly uses the specified path instead of going through ResourceManager::findPath(). - Reimplement the existing constructor as SGSoundSample(const std::string& file, const SGPath& dir), delegating to the new one. - The first argument of the delegating constructor is now a const std::string& instead of a const char*. Among others, this will allow a better implementation of FGSoundManager::playAudioSampleCommand(). More explanations can be found here: https://sourceforge.net/p/flightgear/mailman/message/37695786/ --- simgear/sound/sample.cxx | 13 +++++++++---- simgear/sound/sample.hxx | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/simgear/sound/sample.cxx b/simgear/sound/sample.cxx index 2ff503a6..c1a46a85 100644 --- a/simgear/sound/sample.cxx +++ b/simgear/sound/sample.cxx @@ -79,14 +79,19 @@ std::string SGSoundSampleInfo::random_string() // SGSoundSample // -// constructor -SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) : +// Constructor +SGSoundSample::SGSoundSample(const SGPath& file) : _is_file(true) { - SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir); - _refname = p.utf8Str(); + _refname = file.utf8Str(); } +// Delegating constructor that goes through the ResourceManager +SGSoundSample::SGSoundSample(const string& file, const SGPath& dir) : + SGSoundSample( + simgear::ResourceManager::instance()->findPath(file, dir)) +{ } + // constructor SGSoundSample::SGSoundSample( std::unique_ptr& data, int len, int freq, int format ) diff --git a/simgear/sound/sample.hxx b/simgear/sound/sample.hxx index 804fe549..eb4f52fe 100644 --- a/simgear/sound/sample.hxx +++ b/simgear/sound/sample.hxx @@ -30,6 +30,8 @@ #ifndef _SG_SAMPLE_HXX #define _SG_SAMPLE_HXX 1 +#include + #include #include #include "soundmgr.hxx" @@ -259,11 +261,19 @@ public: virtual ~SGSoundSample () = default; /** - * Constructor - * @param file File name of sound + * Constructor that uses the specified path as is + * @param file Path to sound file Buffer data is freed by the sample group */ - SGSoundSample(const char *file, const SGPath& currentDir); + explicit SGSoundSample(const SGPath& file); + + /** + * Constructor that goes through ResourceManager::findPath() + * @param file File name of sound + @param dir “Context” argument for ResourceManager::findPath() + Buffer data is freed by the sample group + */ + SGSoundSample(const std::string& file, const SGPath& dir); /** * Constructor.