Added: #1459 Group controllers for sound sources
--HG-- branch : sound_devhg/feature/gsoc2012-fabien
parent
57411c0a7b
commit
0b64102ab8
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* \file group_controller.h
|
||||
* \brief CGroupController
|
||||
* \date 2012-04-10 09:29GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CGroupController
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 by authors
|
||||
*
|
||||
* This file is part of RYZOM CORE.
|
||||
* RYZOM CORE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* RYZOM CORE is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with RYZOM CORE. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NLSOUND_GROUP_CONTROLLER_H
|
||||
#define NLSOUND_GROUP_CONTROLLER_H
|
||||
#include <nel/misc/types_nl.h>
|
||||
|
||||
// STL includes
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/common.h>
|
||||
#include <nel/sound/audio_mixer_user.h>
|
||||
#include <nel/sound/u_group_controller.h>
|
||||
|
||||
// Project includes
|
||||
|
||||
namespace NLSOUND {
|
||||
class CSourceCommon;
|
||||
class CGroupControllerRoot;
|
||||
|
||||
/**
|
||||
* \brief CGroupController
|
||||
* \date 2012-04-10 09:29GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CGroupController
|
||||
*/
|
||||
class CGroupController : public UGroupController
|
||||
{
|
||||
public:
|
||||
friend CGroupControllerRoot;
|
||||
|
||||
private:
|
||||
CGroupController *m_Parent;
|
||||
std::map<std::string, CGroupController *> m_Children;
|
||||
|
||||
float m_DevGain;
|
||||
float m_UserGain;
|
||||
float m_FinalGain;
|
||||
|
||||
int m_NbSourcesInclChild;
|
||||
CAudioMixerUser::TSourceContainer m_Sources;
|
||||
|
||||
public:
|
||||
CGroupController(CGroupController *parent);
|
||||
|
||||
/// \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; }
|
||||
//@}
|
||||
|
||||
inline float getFinalGain() const { return m_FinalGain; }
|
||||
|
||||
void addSource(CSourceCommon *source);
|
||||
void removeSource(CSourceCommon *source);
|
||||
|
||||
private:
|
||||
virtual ~CGroupController(); // subnodes can only be deleted by the root
|
||||
inline float calculateTotalGain() { return m_DevGain * m_UserGain; }
|
||||
virtual void calculateFinalGain();
|
||||
virtual void increaseSources();
|
||||
virtual void decreaseSources();
|
||||
void updateSourceGain();
|
||||
|
||||
}; /* class CGroupController */
|
||||
|
||||
} /* namespace NLSOUND */
|
||||
|
||||
#endif /* #ifndef NLSOUND_GROUP_CONTROLLER_H */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* \file group_controller_root.h
|
||||
* \brief CGroupControllerRoot
|
||||
* \date 2012-04-10 09:44GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CGroupControllerRoot
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 by authors
|
||||
*
|
||||
* This file is part of RYZOM CORE.
|
||||
* RYZOM CORE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* RYZOM CORE is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with RYZOM CORE. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NLSOUND_GROUP_CONTROLLER_ROOT_H
|
||||
#define NLSOUND_GROUP_CONTROLLER_ROOT_H
|
||||
#include <nel/misc/types_nl.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
|
||||
// Project includes
|
||||
#include <nel/sound/group_controller.h>
|
||||
|
||||
namespace NLSOUND {
|
||||
|
||||
/**
|
||||
* \brief CGroupControllerRoot
|
||||
* \date 2012-04-10 09:44GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CGroupControllerRoot
|
||||
*/
|
||||
class CGroupControllerRoot : public CGroupController
|
||||
{
|
||||
public:
|
||||
CGroupControllerRoot();
|
||||
virtual ~CGroupControllerRoot();
|
||||
|
||||
/// Gets the group controller in a certain path with separator '/', if it doesn't exist yet it will be created.
|
||||
CGroupController *getGroupController(const std::string &path);
|
||||
|
||||
protected:
|
||||
virtual void calculateFinalGain();
|
||||
virtual void increaseSources();
|
||||
virtual void decreaseSources();
|
||||
|
||||
}; /* class CGroupControllerRoot */
|
||||
|
||||
} /* namespace NLSOUND */
|
||||
|
||||
#endif /* #ifndef NLSOUND_GROUP_CONTROLLER_ROOT_H */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* \file u_group_controller.h
|
||||
* \brief UGroupController
|
||||
* \date 2012-04-10 12:49GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* UGroupController
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 by authors
|
||||
*
|
||||
* This file is part of RYZOM CORE.
|
||||
* RYZOM CORE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* RYZOM CORE is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with RYZOM CORE. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NLSOUND_U_GROUP_CONTROLLER_H
|
||||
#define NLSOUND_U_GROUP_CONTROLLER_H
|
||||
#include <nel/misc/types_nl.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
|
||||
// Project includes
|
||||
|
||||
namespace NLSOUND {
|
||||
|
||||
/**
|
||||
* \brief UGroupController
|
||||
* \date 2012-04-10 12:49GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* UGroupController
|
||||
*/
|
||||
class UGroupController
|
||||
{
|
||||
virtual void setDevGain(float gain) = 0;
|
||||
virtual float getDevGain() = 0;
|
||||
|
||||
virtual void setUserGain(float gain) = 0;
|
||||
virtual float getUserGain() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~UGroupController();
|
||||
|
||||
}; /* class UGroupController */
|
||||
|
||||
} /* namespace NLSOUND */
|
||||
|
||||
#endif /* #ifndef NLSOUND_U_GROUP_CONTROLLER_H */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,112 @@
|
||||
/**
|
||||
* \file group_controller.cpp
|
||||
* \brief CGroupController
|
||||
* \date 2012-04-10 09:29GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CGroupController
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 by authors
|
||||
*
|
||||
* This file is part of RYZOM CORE.
|
||||
* RYZOM CORE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* RYZOM CORE is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with RYZOM CORE. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stdsound.h"
|
||||
#include <nel/sound/group_controller.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
// #include <nel/misc/debug.h>
|
||||
#include <nel/sound/source_common.h>
|
||||
|
||||
// Project includes
|
||||
|
||||
using namespace std;
|
||||
// using namespace NLMISC;
|
||||
|
||||
namespace NLSOUND {
|
||||
|
||||
CGroupController::CGroupController(CGroupController *parent) :
|
||||
m_Parent(parent), m_DevGain(1.0f), m_UserGain(1.0f), m_NbSourcesInclChild(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CGroupController::~CGroupController()
|
||||
{
|
||||
// If m_Sources is not empty, a crash is very likely.
|
||||
nlassert(m_Sources.empty());
|
||||
|
||||
for (std::map<std::string, CGroupController *>::iterator it(m_Children.begin()), end(m_Children.end()); it != end; ++it)
|
||||
{
|
||||
delete it->second;
|
||||
it->second = NULL;
|
||||
}
|
||||
m_Parent = NULL;
|
||||
}
|
||||
|
||||
void CGroupController::addSource(CSourceCommon *source)
|
||||
{
|
||||
m_Sources.insert(source);
|
||||
increaseSources();
|
||||
}
|
||||
|
||||
void CGroupController::removeSource(CSourceCommon *source)
|
||||
{
|
||||
decreaseSources();
|
||||
m_Sources.erase(source);
|
||||
}
|
||||
|
||||
void CGroupController::calculateFinalGain() // overridden by root
|
||||
{
|
||||
m_FinalGain = calculateTotalGain() * m_Parent->getFinalGain();
|
||||
}
|
||||
|
||||
void CGroupController::updateSourceGain()
|
||||
{
|
||||
// Dont update source gain when this controller is inactive.
|
||||
if (m_NbSourcesInclChild)
|
||||
{
|
||||
calculateFinalGain();
|
||||
for (CAudioMixerUser::TSourceContainer::iterator it(m_Sources.begin()), end(m_Sources.end()); it != end; ++it)
|
||||
(*it)->updateFinalGain();
|
||||
for (std::map<std::string, CGroupController *>::iterator it(m_Children.begin()), end(m_Children.end()); it != end; ++it)
|
||||
(*it).second->updateSourceGain();
|
||||
}
|
||||
}
|
||||
|
||||
void CGroupController::increaseSources() // overridden by root
|
||||
{
|
||||
++m_NbSourcesInclChild;
|
||||
m_Parent->increaseSources();
|
||||
|
||||
// Update source gain when this controller was inactive before but the parent was active before.
|
||||
// Thus, when this controller was the root of inactive controllers.
|
||||
if (m_NbSourcesInclChild == 1 && m_Parent->m_NbSourcesInclChild > 1)
|
||||
updateSourceGain();
|
||||
}
|
||||
|
||||
void CGroupController::decreaseSources() // overridden by root
|
||||
{
|
||||
--m_NbSourcesInclChild;
|
||||
m_Parent->decreaseSources();
|
||||
}
|
||||
|
||||
} /* namespace NLSOUND */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,99 @@
|
||||
/**
|
||||
* \file group_controller_root.cpp
|
||||
* \brief CGroupControllerRoot
|
||||
* \date 2012-04-10 09:44GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CGroupControllerRoot
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 by authors
|
||||
*
|
||||
* This file is part of RYZOM CORE.
|
||||
* RYZOM CORE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* RYZOM CORE is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with RYZOM CORE. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stdsound.h"
|
||||
#include <nel/sound/group_controller_root.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
// #include <nel/misc/debug.h>
|
||||
#include <nel/misc/algo.h>
|
||||
|
||||
// Project includes
|
||||
|
||||
using namespace std;
|
||||
// using namespace NLMISC;
|
||||
|
||||
namespace NLSOUND {
|
||||
|
||||
CGroupControllerRoot::CGroupControllerRoot() : CGroupController(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CGroupControllerRoot::~CGroupControllerRoot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CGroupControllerRoot::calculateFinalGain()
|
||||
{
|
||||
m_FinalGain = calculateTotalGain();
|
||||
}
|
||||
|
||||
void CGroupController::increaseSources()
|
||||
{
|
||||
++m_NbSourcesInclChild;
|
||||
|
||||
// Update source gain when this controller was inactive before.
|
||||
if (m_NbSourcesInclChild == 1)
|
||||
updateSourceGain();
|
||||
}
|
||||
|
||||
void CGroupController::decreaseSources()
|
||||
{
|
||||
--m_NbSourcesInclChild;
|
||||
}
|
||||
|
||||
CGroupController *CGroupControllerRoot::getGroupController(const std::string &path)
|
||||
{
|
||||
std::vector<std::string> pathNodes;
|
||||
NLMISC::splitString(NLMISC::toLower(path), "/", pathNodes);
|
||||
CGroupController *active = this;
|
||||
for (std::vector<std::string>::iterator it(pathNodes.begin()), end(pathNodes.end()); it != end; ++it)
|
||||
{
|
||||
if (!(*it).empty())
|
||||
{
|
||||
std::map<std::string, CGroupController *>::iterator found = active->m_Children.find(*it);
|
||||
if (found == active->m_Children.end())
|
||||
{
|
||||
active = new CGroupController(active);
|
||||
active->m_Parent->m_Children[*it] = active;
|
||||
}
|
||||
else
|
||||
{
|
||||
active = (*found).second;
|
||||
}
|
||||
}
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
} /* namespace NLSOUND */
|
||||
|
||||
/* end of file */
|
Loading…
Reference in New Issue