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/
This commit is contained in:
Florent Rougon
2022-08-19 20:52:29 +02:00
parent 8e43ccc87b
commit 8febf6b9f5
2 changed files with 22 additions and 7 deletions

View File

@@ -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<unsigned char, decltype(free)*>& data,
int len, int freq, int format )

View File

@@ -30,6 +30,8 @@
#ifndef _SG_SAMPLE_HXX
#define _SG_SAMPLE_HXX 1
#include <string>
#include <simgear/math/SGMath.hxx>
#include <simgear/props/props.hxx>
#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.