207 lines
8.1 KiB
C++
207 lines
8.1 KiB
C++
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
|
* @license APACHE v2.0 (see license file)
|
|
*/
|
|
|
|
#include "Manager.h"
|
|
#include "Interface.h"
|
|
#include <stdexcept>
|
|
|
|
#include "io/Manager.h"
|
|
#include "io/Node.h"
|
|
#include "debug.h"
|
|
#include <ejson/ejson.h>
|
|
|
|
#undef __class__
|
|
#define __class__ "Manager"
|
|
|
|
std11::shared_ptr<river::Manager> river::Manager::create(const std::string& _applicationUniqueId) {
|
|
return std11::shared_ptr<river::Manager>(new river::Manager(_applicationUniqueId));
|
|
}
|
|
|
|
river::Manager::Manager(const std::string& _applicationUniqueId) :
|
|
m_applicationUniqueId(_applicationUniqueId),
|
|
m_listOpenInterface() {
|
|
|
|
}
|
|
|
|
river::Manager::~Manager() {
|
|
// TODO : Stop all interfaces...
|
|
|
|
}
|
|
|
|
std::vector<std::string> river::Manager::getListStreamInput() {
|
|
std::vector<std::string> output;
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
} else {
|
|
output = manager->getListStreamInput();
|
|
}
|
|
return output;
|
|
}
|
|
|
|
std::vector<std::string> river::Manager::getListStreamOutput() {
|
|
std::vector<std::string> output;
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
} else {
|
|
output = manager->getListStreamOutput();
|
|
}
|
|
return output;
|
|
}
|
|
|
|
std::vector<std::string> river::Manager::getListStreamVirtual() {
|
|
std::vector<std::string> output;
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
} else {
|
|
output = manager->getListStreamVirtual();
|
|
}
|
|
return output;
|
|
}
|
|
|
|
std::vector<std::string> river::Manager::getListStream() {
|
|
std::vector<std::string> output;
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
} else {
|
|
output = manager->getListStream();
|
|
}
|
|
return output;
|
|
}
|
|
|
|
bool river::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
return false;
|
|
}
|
|
return manager->setVolume(_volumeName, _valuedB);
|
|
}
|
|
|
|
float river::Manager::getVolume(const std::string& _volumeName) const {
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
return false;
|
|
}
|
|
return manager->getVolume(_volumeName);
|
|
}
|
|
|
|
std::pair<float,float> river::Manager::getVolumeRange(const std::string& _volumeName) const {
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
return std::make_pair<float,float>(0.0f,0.0f);
|
|
}
|
|
return manager->getVolumeRange(_volumeName);
|
|
}
|
|
|
|
std11::shared_ptr<river::Interface> river::Manager::createOutput(float _freq,
|
|
const std::vector<audio::channel>& _map,
|
|
audio::format _format,
|
|
const std::string& _streamName,
|
|
const std::string& _options) {
|
|
// get global hardware interface:
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
// get the output or input channel :
|
|
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
|
if (node == nullptr) {
|
|
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
if (node->isOutput() != true) {
|
|
RIVER_ERROR("Can not Connect output on other thing than output ... for stream '" << _streamName << "'");;
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
// create user iterface:
|
|
std11::shared_ptr<river::Interface> interface;
|
|
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
|
|
tmpOption->addString("io", "output");
|
|
interface = river::Interface::create(_freq, _map, _format, node, tmpOption);
|
|
// store it in a list (needed to apply some parameters).
|
|
m_listOpenInterface.push_back(interface);
|
|
return interface;
|
|
}
|
|
|
|
std11::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
|
|
const std::vector<audio::channel>& _map,
|
|
audio::format _format,
|
|
const std::string& _streamName,
|
|
const std::string& _options) {
|
|
// get global hardware interface:
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
// get the output or input channel :
|
|
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
|
if (node == nullptr) {
|
|
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
if (node->isInput() != true) {
|
|
RIVER_ERROR("Can not Connect input on other thing than input ... for stream '" << _streamName << "'");;
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
// create user iterface:
|
|
std11::shared_ptr<river::Interface> interface;
|
|
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
|
|
tmpOption->addString("io", "input");
|
|
interface = river::Interface::create(_freq, _map, _format, node, tmpOption);
|
|
// store it in a list (needed to apply some parameters).
|
|
m_listOpenInterface.push_back(interface);
|
|
return interface;
|
|
}
|
|
|
|
|
|
std11::shared_ptr<river::Interface> river::Manager::createFeedback(float _freq,
|
|
const std::vector<audio::channel>& _map,
|
|
audio::format _format,
|
|
const std::string& _streamName,
|
|
const std::string& _options) {
|
|
// get global hardware interface:
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
// get the output or input channel :
|
|
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
|
if (node == nullptr) {
|
|
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
if (node->isOutput() != true) {
|
|
RIVER_ERROR("Can not Connect feedback on other thing than output ... for stream '" << _streamName << "'");;
|
|
return std11::shared_ptr<river::Interface>();
|
|
}
|
|
// create user iterface:
|
|
std11::shared_ptr<river::Interface> interface;
|
|
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
|
|
tmpOption->addString("io", "feedback");
|
|
interface = river::Interface::create(_freq, _map, _format, node, tmpOption);
|
|
// store it in a list (needed to apply some parameters).
|
|
m_listOpenInterface.push_back(interface);
|
|
return interface;
|
|
}
|
|
|
|
void river::Manager::generateDotAll(const std::string& _filename) {
|
|
// get global hardware interface:
|
|
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
|
if (manager == nullptr) {
|
|
RIVER_ERROR("Can not get the harware manager");
|
|
return;
|
|
}
|
|
manager->generateDot(_filename);
|
|
} |