From cdb719130feda380e6e67063111f8e701e064da2 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 13 Apr 2012 11:54:20 +0200 Subject: [PATCH] Changed: #1459 Simplify the sound group controller interface --- code/nel/include/nel/sound/group_controller.h | 27 +++++++++---------- .../include/nel/sound/u_group_controller.h | 15 ++++------- .../samples/sound/stream_file/stream_file.cpp | 6 ++--- .../stream_ogg_vorbis/stream_ogg_vorbis.cpp | 6 ++--- code/nel/src/sound/group_controller.cpp | 6 ++--- code/nel/src/sound/group_controller_root.cpp | 13 ++++++--- code/ryzom/client/src/sound_manager.cpp | 10 +++++-- code/ryzom/client/src/sound_manager.h | 5 +++- 8 files changed, 47 insertions(+), 41 deletions(-) diff --git a/code/nel/include/nel/sound/group_controller.h b/code/nel/include/nel/sound/group_controller.h index 08d474129..25b7034b6 100644 --- a/code/nel/include/nel/sound/group_controller.h +++ b/code/nel/include/nel/sound/group_controller.h @@ -57,9 +57,11 @@ public: private: CGroupController *m_Parent; std::map m_Children; - - float m_DevGain; - float m_UserGain; + + /// Gain as set by the interface + float m_Gain; + + /// Gain including parent gain float m_FinalGain; int m_NbSourcesInclChild; @@ -70,27 +72,22 @@ public: /// \name UGroupController //@{ - virtual void setDevGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_DevGain = gain; updateSourceGain(); } - virtual float getDevGain() { return m_DevGain; } - - virtual void setUserGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_UserGain = gain; updateSourceGain(); } - virtual float getUserGain() { return m_UserGain; } - - virtual void setGain(float devGain, float userGain) { NLMISC::clamp(devGain, 0.0f, 1.0f); NLMISC::clamp(userGain, 0.0f, 1.0f); m_DevGain = devGain; m_UserGain = userGain; updateSourceGain(); } + virtual void setGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); if (m_Gain != gain) { m_Gain = gain; updateSourceGain(); } } + virtual float getGain() { return m_Gain; } //@} - + inline float getFinalGain() const { return m_FinalGain; } - + void addSource(CSourceCommon *source); void removeSource(CSourceCommon *source); - + virtual std::string getPath(); - + protected: virtual ~CGroupController(); // subnodes can only be deleted by the root private: - inline float calculateTotalGain() { return m_DevGain * m_UserGain; } + inline float calculateTotalGain() { return m_Gain; } virtual void calculateFinalGain(); virtual void increaseSources(); virtual void decreaseSources(); diff --git a/code/nel/include/nel/sound/u_group_controller.h b/code/nel/include/nel/sound/u_group_controller.h index 54a28b835..5aadeb25c 100644 --- a/code/nel/include/nel/sound/u_group_controller.h +++ b/code/nel/include/nel/sound/u_group_controller.h @@ -35,9 +35,9 @@ // Project includes -#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "effects" -#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "music" -#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "dialog" +#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "sound:effects:game" +#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "sound:music:game" +#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "sound:dialog:game" namespace NLSOUND { @@ -50,13 +50,8 @@ namespace NLSOUND { class UGroupController { public: - virtual void setDevGain(float gain) = 0; - virtual float getDevGain() = 0; - - virtual void setUserGain(float gain) = 0; - virtual float getUserGain() = 0; - - virtual void setGain(float devGain, float userGain) = 0; + virtual void setGain(float gain) = 0; + virtual float getGain() = 0; protected: virtual ~UGroupController() { } diff --git a/code/nel/samples/sound/stream_file/stream_file.cpp b/code/nel/samples/sound/stream_file/stream_file.cpp index 2ace9dc6b..623ee4ff0 100644 --- a/code/nel/samples/sound/stream_file/stream_file.cpp +++ b/code/nel/samples/sound/stream_file/stream_file.cpp @@ -106,7 +106,7 @@ static void initSample() // s_Source->setSourceRelativeMode(true); // s_Source->setPitch(2.0f); - s_GroupController = s_AudioMixer->getGroupController("dialog"); + s_GroupController = s_AudioMixer->getGroupController("sound:dialog"); } static void runSample() @@ -129,10 +129,10 @@ static void runSample() #endif { case '+': - s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f); + s_GroupController->setGain(s_GroupController->getGain() + 0.1f); break; case '-': - s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f); + s_GroupController->setGain(s_GroupController->getGain() - 0.1f); break; case 'x': s_Source->stop(); diff --git a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp index b3645913c..e0f0df705 100644 --- a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp +++ b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp @@ -100,7 +100,7 @@ static void initSample() s_StreamSource->setFormat(s_AudioDecoder->getChannels(), s_AudioDecoder->getBitsPerSample(), (uint32)s_AudioDecoder->getSamplesPerSec()); //s_StreamSource->setPitch(2.0f); - s_GroupController = s_AudioMixer->getGroupController("dialog"); + s_GroupController = s_AudioMixer->getGroupController("sound:dialog"); } //CMutex *s_Mutex = NULL; @@ -154,10 +154,10 @@ static void runSample() #endif { case '+': - s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f); + s_GroupController->setGain(s_GroupController->getGain() + 0.1f); break; case '-': - s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f); + s_GroupController->setGain(s_GroupController->getGain() - 0.1f); break; default: return; diff --git a/code/nel/src/sound/group_controller.cpp b/code/nel/src/sound/group_controller.cpp index fef67a01b..d01e29252 100644 --- a/code/nel/src/sound/group_controller.cpp +++ b/code/nel/src/sound/group_controller.cpp @@ -42,7 +42,7 @@ using namespace std; namespace NLSOUND { CGroupController::CGroupController(CGroupController *parent) : - m_Parent(parent), m_DevGain(1.0f), m_UserGain(1.0f), m_NbSourcesInclChild(0) + m_Parent(parent), m_Gain(1.0f), m_NbSourcesInclChild(0) { } @@ -81,9 +81,7 @@ std::string CGroupController::getPath() // overridden by root if (it->second == this) { const std::string &name = it->first; - std::string returnPath = m_Parent->getPath() + "/" + name; - if (returnPath[0] == '/') - returnPath = returnPath.substr(1); + std::string returnPath = m_Parent->getPath() + ":" + name; return returnPath; } } diff --git a/code/nel/src/sound/group_controller_root.cpp b/code/nel/src/sound/group_controller_root.cpp index f49a40fff..f1344e195 100644 --- a/code/nel/src/sound/group_controller_root.cpp +++ b/code/nel/src/sound/group_controller_root.cpp @@ -39,6 +39,8 @@ using namespace std; // using namespace NLMISC; +#define NLSOUND_GROUP_CONTROLLER_ROOT_PATH "sound" + namespace NLSOUND { CGroupControllerRoot::CGroupControllerRoot() : CGroupController(NULL) @@ -53,7 +55,8 @@ CGroupControllerRoot::~CGroupControllerRoot() std::string CGroupControllerRoot::getPath() { - return ""; + // The root node is always called sound + return NLSOUND_GROUP_CONTROLLER_ROOT_PATH; } void CGroupControllerRoot::calculateFinalGain() @@ -78,9 +81,13 @@ void CGroupControllerRoot::decreaseSources() CGroupController *CGroupControllerRoot::getGroupController(const std::string &path) { std::vector pathNodes; - NLMISC::splitString(NLMISC::toLower(path), "/", pathNodes); + NLMISC::splitString(NLMISC::toLower(path), ":", pathNodes); CGroupController *active = this; - for (std::vector::iterator it(pathNodes.begin()), end(pathNodes.end()); it != end; ++it) + if (pathNodes[0] != NLSOUND_GROUP_CONTROLLER_ROOT_PATH) + { + nlerror("Root node for group controller must always be 'sound', invalid group '%s' requested", path.c_str()); + } + for (std::vector::iterator it(pathNodes.begin() + 1), end(pathNodes.end()); it != end; ++it) { if (!(*it).empty()) { diff --git a/code/ryzom/client/src/sound_manager.cpp b/code/ryzom/client/src/sound_manager.cpp index a82e4b422..182a28cb1 100644 --- a/code/ryzom/client/src/sound_manager.cpp +++ b/code/ryzom/client/src/sound_manager.cpp @@ -107,6 +107,8 @@ enum TFilterMapping //----------------------------------------------- CSoundManager::CSoundManager(IProgressCallback * /* progressCallBack */) : _AudioMixer(NULL), + _GroupControllerEffects(NULL), + _GroupControllerEffectsGame(NULL), _EnvSoundRoot(NULL), _UserEntitySoundLevel(1.0f), _Sources(NULL) @@ -139,6 +141,7 @@ CSoundManager::~CSoundManager() NL3D::UParticleSystemSound::setPSSound(NULL); _GroupControllerEffects = NULL; + _GroupControllerEffectsGame = NULL; // free the audio mixer (and delete all sources) delete _AudioMixer; @@ -407,6 +410,7 @@ void CSoundManager::reset () NL3D::UParticleSystemSound::setPSSound(NULL); _GroupControllerEffects = NULL; + _GroupControllerEffectsGame = NULL; delete _AudioMixer; _AudioMixer = NULL; @@ -482,7 +486,8 @@ void CSoundManager::init(IProgressCallback *progressCallBack) new CSoundAnimManager(_AudioMixer); // get the controller group for effects - _GroupControllerEffects = _AudioMixer->getGroupController("effects"); + _GroupControllerEffects = _AudioMixer->getGroupController("sound:effects"); + _GroupControllerEffectsGame = _AudioMixer->getGroupController("sound:effects:game"); // restore the volume SoundMngr->setSFXVolume(ClientCfg.SoundSFXVolume); @@ -1543,7 +1548,8 @@ void CSoundManager::updateVolume() _AudioMixer->setEventMusicVolume(_GameMusicVolume); // update sfx volume - _GroupControllerEffects->setGain(_FadeSFXVolume, _SFXVolume); + _GroupControllerEffects->setGain(_SFXVolume); + _GroupControllerEffectsGame->setGain(_FadeSFXVolume); } } diff --git a/code/ryzom/client/src/sound_manager.h b/code/ryzom/client/src/sound_manager.h index e5db85648..80401ea57 100644 --- a/code/ryzom/client/src/sound_manager.h +++ b/code/ryzom/client/src/sound_manager.h @@ -332,9 +332,12 @@ private: /// Pointer on the audio mixer object NLSOUND::UAudioMixer *_AudioMixer; - /// The root effects group controller for volume settings + /// The root effects group controller for effects volume settings by the user NLSOUND::UGroupController *_GroupControllerEffects; + /// The root effects group controller for effects fading by the game + NLSOUND::UGroupController *_GroupControllerEffectsGame; + /// Pointer on the root of the environmental sounds tree (if any) NLSOUND::UEnvSound *_EnvSoundRoot;