fix
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include <signal_path/sink.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <gui/style.h>
|
||||
#include <gui/icons.h>
|
||||
#include <core.h>
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
@@ -12,16 +14,26 @@ SinkManager::SinkManager() {
|
||||
}
|
||||
|
||||
SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate) {
|
||||
init(in, srChangeHandler, sampleRate);
|
||||
}
|
||||
|
||||
void SinkManager::Stream::init(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate) {
|
||||
_in = in;
|
||||
srChange.bindHandler(srChangeHandler);
|
||||
_sampleRate = sampleRate;
|
||||
splitter.init(_in);
|
||||
splitter.bindStream(&volumeInput);
|
||||
volumeAjust.init(&volumeInput, 1.0f);
|
||||
sinkOut = &volumeAjust.out;
|
||||
}
|
||||
|
||||
void SinkManager::Stream::start() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
|
||||
splitter.start();
|
||||
volumeAjust.start();
|
||||
sink->start();
|
||||
running = true;
|
||||
}
|
||||
@@ -30,10 +42,25 @@ void SinkManager::Stream::stop() {
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
splitter.stop();
|
||||
volumeAjust.stop();
|
||||
sink->stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
void SinkManager::Stream::setVolume(float volume) {
|
||||
guiVolume = volume;
|
||||
volumeAjust.setVolume(volume);
|
||||
}
|
||||
|
||||
float SinkManager::Stream::getVolume() {
|
||||
return guiVolume;
|
||||
}
|
||||
|
||||
float SinkManager::Stream::getSampleRate() {
|
||||
return _sampleRate;
|
||||
}
|
||||
|
||||
void SinkManager::Stream::setInput(dsp::stream<dsp::stereo_t>* in) {
|
||||
std::lock_guard<std::mutex> lck(ctrlMtx);
|
||||
_in = in;
|
||||
@@ -71,20 +98,15 @@ void SinkManager::registerStream(std::string name, SinkManager::Stream* stream)
|
||||
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];
|
||||
}
|
||||
|
||||
provider = providers["None"];
|
||||
|
||||
stream->sink = provider.create(stream, name, provider.ctx);
|
||||
|
||||
streams[name] = stream;
|
||||
streamNames.push_back(name);
|
||||
}
|
||||
|
||||
void SinkManager::unregisterStream(std::string name) {
|
||||
@@ -92,6 +114,7 @@ void SinkManager::unregisterStream(std::string name) {
|
||||
spdlog::error("Cannot unregister stream '{0}', this stream doesn't exist", name);
|
||||
return;
|
||||
}
|
||||
spdlog::error("unregisterStream NOT IMPLEMENTED!!!!!!!");
|
||||
SinkManager::Stream* stream = streams[name];
|
||||
delete stream->sink;
|
||||
delete stream;
|
||||
@@ -113,6 +136,14 @@ void SinkManager::stopStream(std::string name) {
|
||||
streams[name]->stop();
|
||||
}
|
||||
|
||||
float SinkManager::getStreamSampleRate(std::string name) {
|
||||
if (streams.find(name) == streams.end()) {
|
||||
spdlog::error("Cannot get sample rate of stream '{0}', this stream doesn't exist", name);
|
||||
return -1.0f;
|
||||
}
|
||||
return streams[name]->getSampleRate();
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -130,7 +161,93 @@ void SinkManager::unbindStream(std::string name, dsp::stream<dsp::stereo_t>* str
|
||||
}
|
||||
|
||||
void SinkManager::setStreamSink(std::string name, std::string providerName) {
|
||||
spdlog::warn("setStreamSink is NOT implemented!!!");
|
||||
}
|
||||
|
||||
void SinkManager::showVolumeSlider(std::string name, std::string prefix, float width) {
|
||||
// TODO: Replace map with some hashmap for it to be faster
|
||||
float height = ImGui::GetTextLineHeightWithSpacing() + 2;
|
||||
|
||||
if (streams.find(name) == streams.end()) {
|
||||
float dummy = 0.0f;
|
||||
style::beginDisabled();
|
||||
ImGui::SetNextItemWidth(width - height);
|
||||
ImGui::SliderFloat((prefix + name).c_str(), &dummy, 0.0f, 1.0f, "");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushID(ImGui::GetID(("sdrpp_dummy_mute_btn_" + name).c_str()));
|
||||
ImGui::ImageButton(icons::STOP, ImVec2(height, height), ImVec2(0, 0), ImVec2(1, 1), 0);
|
||||
ImGui::PopID();
|
||||
style::endDisabled();
|
||||
}
|
||||
|
||||
SinkManager::Stream* stream = streams[name];
|
||||
ImGui::SetNextItemWidth(width - height - 10);
|
||||
if (ImGui::SliderFloat((prefix + name).c_str(), &stream->guiVolume, 0.0f, 1.0f, "")) {
|
||||
stream->setVolume(stream->guiVolume);
|
||||
core::configManager.aquire();
|
||||
saveStreamConfig(name);
|
||||
core::configManager.release(true);
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (stream->volumeAjust.getMuted()) {
|
||||
ImGui::PushID(ImGui::GetID(("sdrpp_unmute_btn_" + name).c_str()));
|
||||
if (ImGui::ImageButton(icons::PLAY, ImVec2(height, height), ImVec2(0, 0), ImVec2(1, 1), 0)) {
|
||||
stream->volumeAjust.setMuted(false);
|
||||
core::configManager.aquire();
|
||||
saveStreamConfig(name);
|
||||
core::configManager.release(true);
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
else {
|
||||
ImGui::PushID(ImGui::GetID(("sdrpp_mute_btn_" + name).c_str()));
|
||||
if (ImGui::ImageButton(icons::STOP, ImVec2(height, height), ImVec2(0, 0), ImVec2(1, 1), 0)) {
|
||||
stream->volumeAjust.setMuted(true);
|
||||
core::configManager.aquire();
|
||||
saveStreamConfig(name);
|
||||
core::configManager.release(true);
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
|
||||
void SinkManager::loadStreamConfig(std::string name) {
|
||||
json conf = core::configManager.conf["streams"][name];
|
||||
SinkManager::Stream* stream = streams[name];
|
||||
std::string provName = conf["sink"];
|
||||
if (providers.find(provName) == providers.end()) {
|
||||
provName = providerNames[0];
|
||||
}
|
||||
if (stream->running) {
|
||||
stream->sink->stop();
|
||||
}
|
||||
delete stream->sink;
|
||||
SinkManager::SinkProvider prov = providers[provName];
|
||||
stream->providerId = std::distance(providerNames.begin(), std::find(providerNames.begin(), providerNames.end(), provName));
|
||||
stream->sink = prov.create(stream, name, prov.ctx);
|
||||
if (stream->running) {
|
||||
stream->sink->start();
|
||||
}
|
||||
stream->setVolume(conf["volume"]);
|
||||
stream->volumeAjust.setMuted(conf["muted"]);
|
||||
}
|
||||
|
||||
void SinkManager::saveStreamConfig(std::string name) {
|
||||
SinkManager::Stream* stream = streams[name];
|
||||
json conf;
|
||||
conf["sink"] = providerNames[stream->providerId];
|
||||
conf["volume"] = stream->getVolume();
|
||||
conf["muted"] = stream->volumeAjust.getMuted();
|
||||
core::configManager.conf["streams"][name] = conf;
|
||||
}
|
||||
|
||||
// Note: aquire and release config before running this
|
||||
void SinkManager::loadSinksFromConfig() {
|
||||
for (auto const& [name, stream] : streams) {
|
||||
if (!core::configManager.conf["streams"].contains(name)) { continue; }
|
||||
loadStreamConfig(name);
|
||||
}
|
||||
}
|
||||
|
||||
void SinkManager::showMenu() {
|
||||
@@ -139,7 +256,7 @@ void SinkManager::showMenu() {
|
||||
int maxCount = streams.size();
|
||||
|
||||
std::string provStr = "";
|
||||
for (auto const& [name, provider] : providers) {
|
||||
for (auto const& name : providerNames) {
|
||||
provStr += name;
|
||||
provStr += '\0';
|
||||
}
|
||||
@@ -148,6 +265,7 @@ void SinkManager::showMenu() {
|
||||
ImGui::SetCursorPosX((menuWidth / 2.0f) - (ImGui::CalcTextSize(name.c_str()).x / 2.0f));
|
||||
ImGui::Text("%s", name.c_str());
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::Combo(CONCAT("##_sdrpp_sink_select_", name), &stream->providerId, provStr.c_str())) {
|
||||
if (stream->running) {
|
||||
stream->sink->stop();
|
||||
@@ -158,11 +276,15 @@ void SinkManager::showMenu() {
|
||||
if (stream->running) {
|
||||
stream->sink->start();
|
||||
}
|
||||
core::configManager.aquire();
|
||||
saveStreamConfig(name);
|
||||
core::configManager.release(true);
|
||||
}
|
||||
|
||||
stream->sink->menuHandler();
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
showVolumeSlider(name, "##_sdrpp_sink_menu_vol_", menuWidth);
|
||||
|
||||
count++;
|
||||
if (count < maxCount) {
|
||||
ImGui::Spacing();
|
||||
@@ -170,4 +292,8 @@ void SinkManager::showMenu() {
|
||||
}
|
||||
ImGui::Spacing();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> SinkManager::getStreamNames() {
|
||||
return streamNames;
|
||||
}
|
||||
Reference in New Issue
Block a user