Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / sound / group_controller_root.cpp
blob5a4ea4db591507606c56d72ae15e8a66099ba7a4
1 /**
2 * \file group_controller_root.cpp
3 * \brief CGroupControllerRoot
4 * \date 2012-04-10 09:44GMT
5 * \author Jan Boon (Kaetemi)
6 * CGroupControllerRoot
7 */
9 // NeL - MMORPG Framework <https://wiki.ryzom.dev/>
10 // Copyright (C) 2012-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
12 // This program is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU Affero General Public License as
14 // published by the Free Software Foundation, either version 3 of the
15 // License, or (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Affero General Public License for more details.
22 // You should have received a copy of the GNU Affero General Public License
23 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "stdsound.h"
26 #include <nel/sound/group_controller_root.h>
28 // STL includes
30 // NeL includes
31 // #include <nel/misc/debug.h>
32 #include <nel/misc/algo.h>
34 // Project includes
36 using namespace std;
37 // using namespace NLMISC;
39 #define NLSOUND_GROUP_CONTROLLER_ROOT_PATH "sound"
41 namespace NLSOUND {
43 CGroupControllerRoot::CGroupControllerRoot() : CGroupController(NULL), NLMISC::CManualSingleton<CGroupControllerRoot>()
48 CGroupControllerRoot::~CGroupControllerRoot()
53 std::string CGroupControllerRoot::getPath()
55 // The root node is always called sound
56 return NLSOUND_GROUP_CONTROLLER_ROOT_PATH;
59 void CGroupControllerRoot::calculateFinalGain()
61 m_FinalGain = calculateTotalGain();
64 void CGroupControllerRoot::increaseSources()
66 ++m_NbSourcesInclChild;
68 // Update source gain when this controller was inactive before.
69 if (m_NbSourcesInclChild == 1)
70 updateSourceGain();
73 void CGroupControllerRoot::decreaseSources()
75 --m_NbSourcesInclChild;
78 bool CGroupControllerRoot::isReservedName(const std::string &nodeName)
80 // These node names are reserved, in case these category controllers can be integrated with CDB.
81 // I do not forsee any functionality for changing environment effect settings for entire categories.
82 // The nodeName parameter is already lowercase, see CGroupControllerRoot::getGroupController.
83 if (nodeName == NLSOUND_GROUP_CONTROLLER_ROOT_PATH) return true; // Root node name can only used by root.
84 if (nodeName == "gain") return true;
85 if (nodeName == "pitch") return true;
86 if (nodeName == "enable" || nodeName == "enabled") return true;
87 return false;
90 CGroupController *CGroupControllerRoot::getGroupController(const std::string &path)
92 std::vector<std::string> pathNodes;
93 NLMISC::splitString(NLMISC::toLowerAscii(path), ":", pathNodes);
94 CGroupController *active = this;
95 if (pathNodes[0] != NLSOUND_GROUP_CONTROLLER_ROOT_PATH)
97 nlerror("Root node for group controller must always be 'sound', invalid group '%s' requested", path.c_str());
99 for (std::vector<std::string>::iterator it(pathNodes.begin() + 1), end(pathNodes.end()); it != end; ++it)
101 if (!(*it).empty())
103 if (isReservedName(*it))
105 nlerror("Attempt to use reserved node name '%s' in group controller path '%s'", (*it).c_str(), path.c_str());
107 std::map<std::string, CGroupController *>::iterator found = active->m_Children.find(*it);
108 if (found == active->m_Children.end())
110 active = new CGroupController(active);
111 active->m_Parent->m_Children[*it] = active;
113 else
115 active = (*found).second;
119 return active;
122 } /* namespace NLSOUND */
124 /* end of file */