2020-11-12 00:53:38 +01:00
|
|
|
#include <signal_path/sink.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
2020-11-22 18:26:48 +01:00
|
|
|
#include <imgui/imgui.h>
|
2020-11-12 00:53:38 +01:00
|
|
|
#include <core.h>
|
|
|
|
|
|
|
|
SinkManager::SinkManager() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate) {
|
|
|
|
_in = in;
|
|
|
|
srChange.bindHandler(srChangeHandler);
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
splitter.init(_in);
|
|
|
|
}
|
|
|
|
|
2020-11-22 18:26:48 +01:00
|
|
|
void SinkManager::Stream::start() {
|
|
|
|
sink->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::Stream::stop() {
|
|
|
|
sink->stop();
|
|
|
|
}
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
void SinkManager::Stream::setInput(dsp::stream<dsp::stereo_t>* in) {
|
|
|
|
std::lock_guard<std::mutex> lck(ctrlMtx);
|
|
|
|
_in = in;
|
|
|
|
splitter.setInput(_in);
|
|
|
|
}
|
|
|
|
|
|
|
|
dsp::stream<dsp::stereo_t>* SinkManager::Stream::bindStream() {
|
|
|
|
dsp::stream<dsp::stereo_t>* stream = new dsp::stream<dsp::stereo_t>;
|
|
|
|
splitter.bindStream(stream);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::Stream::unbindStream(dsp::stream<dsp::stereo_t>* stream) {
|
|
|
|
splitter.unbindStream(stream);
|
|
|
|
delete stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::Stream::setSampleRate(float sampleRate) {
|
|
|
|
std::lock_guard<std::mutex> lck(ctrlMtx);
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
srChange.emit(sampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::registerSinkProvider(std::string name, SinkProvider provider) {
|
|
|
|
if (providers.find(name) != providers.end()) {
|
|
|
|
spdlog::error("Cannot create sink provider '{0}', this name is already taken", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
providers[name] = provider;
|
2020-11-22 18:26:48 +01:00
|
|
|
providerNames.push_back(name);
|
2020-11-12 00:53:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::registerStream(std::string name, SinkManager::Stream* stream) {
|
|
|
|
if (streams.find(name) != streams.end()) {
|
|
|
|
spdlog::error("Cannot register stream '{0}', this name is already taken", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
core::configManager.aquire();
|
|
|
|
std::string providerName = core::configManager.conf["defaultSink"];
|
|
|
|
core::configManager.release();
|
|
|
|
|
|
|
|
SinkManager::SinkProvider provider;
|
|
|
|
if (providers.find(providerName) == providers.end()) {
|
|
|
|
// TODO: get default
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
provider = providers[providerName];
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->sink = provider.create(stream, provider.ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::unregisterStream(std::string name) {
|
|
|
|
if (streams.find(name) == streams.end()) {
|
|
|
|
spdlog::error("Cannot unregister stream '{0}', this stream doesn't exist", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SinkManager::Stream* stream = streams[name];
|
|
|
|
delete stream->sink;
|
|
|
|
delete stream;
|
|
|
|
}
|
|
|
|
|
2020-11-22 18:26:48 +01:00
|
|
|
void SinkManager::startStream(std::string name) {
|
|
|
|
if (streams.find(name) == streams.end()) {
|
|
|
|
spdlog::error("Cannot start stream '{0}', this stream doesn't exist", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
streams[name]->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::stopStream(std::string name) {
|
|
|
|
if (streams.find(name) == streams.end()) {
|
|
|
|
spdlog::error("Cannot stop stream '{0}', this stream doesn't exist", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
streams[name]->stop();
|
|
|
|
}
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
dsp::stream<dsp::stereo_t>* SinkManager::bindStream(std::string name) {
|
|
|
|
if (streams.find(name) == streams.end()) {
|
|
|
|
spdlog::error("Cannot bind to stream '{0}'. Stream doesn't exist", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return streams[name]->bindStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinkManager::unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream) {
|
|
|
|
if (streams.find(name) == streams.end()) {
|
|
|
|
spdlog::error("Cannot unbind from stream '{0}'. Stream doesn't exist", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
streams[name]->unbindStream(stream);
|
|
|
|
}
|
|
|
|
|
2020-11-22 18:26:48 +01:00
|
|
|
void SinkManager::setStreamSink(std::string name, std::string providerName) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
void SinkManager::showMenu() {
|
2020-11-22 18:26:48 +01:00
|
|
|
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
|
|
|
int count = 0;
|
|
|
|
int maxCount = streams.size();
|
|
|
|
|
|
|
|
std::string provStr = "";
|
|
|
|
for (auto const& [name, provider] : providers) {
|
|
|
|
provStr += name;
|
|
|
|
provStr += '\0';
|
|
|
|
}
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
for (auto const& [name, stream] : streams) {
|
2020-11-22 18:26:48 +01:00
|
|
|
ImGui::SetCursorPosX((menuWidth / 2.0f) - (ImGui::CalcTextSize(name.c_str()).x / 2.0f));
|
|
|
|
ImGui::Text("%s", name.c_str());
|
|
|
|
|
|
|
|
if (ImGui::Combo("", &stream->providerId, provStr.c_str())) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->sink->menuHandler();
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
count++;
|
|
|
|
if (count < maxCount) {
|
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
|
|
|
}
|
|
|
|
ImGui::Spacing();
|
2020-11-12 00:53:38 +01:00
|
|
|
}
|
|
|
|
}
|