audio-river/river/io/Manager.cpp

99 lines
2.9 KiB
C++
Raw Normal View History

2015-01-25 22:17:06 +01:00
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include "Manager.h"
#include <memory>
2015-02-05 19:10:53 +01:00
#include <river/debug.h>
2015-01-25 22:17:06 +01:00
#include "Node.h"
2015-01-27 21:01:52 +01:00
#undef __class__
#define __class__ "io::Manager"
2015-02-05 19:10:53 +01:00
river::io::Manager::Manager() {
if (m_config.load("DATA:hardware.json") == false) {
RIVER_ERROR("you must set a basic configuration file for harware configuration: DATA:hardware.json");
}
2015-02-12 22:08:23 +01:00
// TODO : Load virtual.json and check if all is correct ...
};
2015-02-05 19:10:53 +01:00
std::shared_ptr<river::io::Manager> river::io::Manager::getInstance() {
static std::shared_ptr<river::io::Manager> manager(new Manager());
2015-01-25 22:17:06 +01:00
return manager;
}
2015-02-05 19:10:53 +01:00
std::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string& _name) {
2015-02-12 22:08:23 +01:00
for (auto &it : m_list) {
std::shared_ptr<river::io::Node> tmppp = it.lock();
if ( tmppp != nullptr
&& _name == tmppp->getName()) {
2015-01-25 22:17:06 +01:00
return tmppp;
}
}
// check if the node can be open :
const std::shared_ptr<const ejson::Object> tmpObject = m_config.getObject(_name);
if (tmpObject != nullptr) {
2015-02-05 19:10:53 +01:00
std::shared_ptr<river::io::Node> tmp = river::io::Node::create(_name, tmpObject);
m_list.push_back(tmp);
return tmp;
}
RIVER_ERROR("Can not create the interface : '" << _name << "' the node is not DEFINED in the configuration file availlable : " << m_config.getKeys());
return nullptr;
}
2015-02-05 19:10:53 +01:00
std::shared_ptr<drain::VolumeElement> river::io::Manager::getVolumeGroup(const std::string& _name) {
if (_name == "") {
RIVER_ERROR("Try to create an audio group with no name ...");
return nullptr;
}
for (auto &it : m_volumeGroup) {
if (it == nullptr) {
continue;
}
if (it->getName() == _name) {
2015-02-04 21:08:06 +01:00
return it;
}
}
RIVER_DEBUG("Add a new volume group : '" << _name << "'");
2015-02-05 19:10:53 +01:00
std::shared_ptr<drain::VolumeElement> tmpVolume = std::make_shared<drain::VolumeElement>(_name);
m_volumeGroup.push_back(tmpVolume);
return tmpVolume;
2015-02-03 23:29:34 +01:00
}
2015-02-05 19:10:53 +01:00
bool river::io::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
std::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName);
2015-02-04 21:08:06 +01:00
if (volume == nullptr) {
RIVER_ERROR("Can not set volume ... : '" << _volumeName << "'");
return false;
}
if ( _valuedB < -300
|| _valuedB > 300) {
RIVER_ERROR("Can not set volume ... : '" << _volumeName << "' out of range : [-300..300]");
2015-02-04 21:08:06 +01:00
return false;
}
volume->setVolume(_valuedB);
for (auto &it2 : m_list) {
2015-02-05 19:10:53 +01:00
std::shared_ptr<river::io::Node> val = it2.lock();
2015-02-04 21:08:06 +01:00
if (val != nullptr) {
val->volumeChange();
2015-02-03 23:29:34 +01:00
}
}
2015-02-04 21:08:06 +01:00
return true;
2015-02-03 23:29:34 +01:00
}
2015-02-05 19:10:53 +01:00
float river::io::Manager::getVolume(const std::string& _volumeName) {
std::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName);
2015-02-04 21:08:06 +01:00
if (volume == nullptr) {
RIVER_ERROR("Can not get volume ... : '" << _volumeName << "'");
2015-02-04 21:08:06 +01:00
return 0.0f;
2015-02-03 23:29:34 +01:00
}
2015-02-04 21:08:06 +01:00
return volume->getVolume();
2015-02-03 23:29:34 +01:00
}
2015-02-05 19:10:53 +01:00
std::pair<float,float> river::io::Manager::getVolumeRange(const std::string& _volumeName) const {
2015-02-04 21:08:06 +01:00
return std::make_pair<float,float>(-300, 300);
2015-02-03 23:29:34 +01:00
}