mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-25 12:07:49 +02:00
More work on the sink interface
This commit is contained in:
12
core/src/gui/menus/sink.cpp
Normal file
12
core/src/gui/menus/sink.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <gui/menus/sink.h>
|
||||
#include <signal_path/signal_path.h>
|
||||
|
||||
namespace sinkmenu {
|
||||
void init() {
|
||||
|
||||
}
|
||||
|
||||
void draw(void* ctx) {
|
||||
sigpath::sinkManager.showMenu();
|
||||
}
|
||||
};
|
6
core/src/gui/menus/sink.h
Normal file
6
core/src/gui/menus/sink.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace sinkmenu {
|
||||
void init();
|
||||
void draw(void* ctx);
|
||||
};
|
@ -1,5 +1,6 @@
|
||||
#include <signal_path/sink.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <core.h>
|
||||
|
||||
SinkManager::SinkManager() {
|
||||
@ -13,6 +14,14 @@ SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::
|
||||
splitter.init(_in);
|
||||
}
|
||||
|
||||
void SinkManager::Stream::start() {
|
||||
sink->start();
|
||||
}
|
||||
|
||||
void SinkManager::Stream::stop() {
|
||||
sink->stop();
|
||||
}
|
||||
|
||||
void SinkManager::Stream::setInput(dsp::stream<dsp::stereo_t>* in) {
|
||||
std::lock_guard<std::mutex> lck(ctrlMtx);
|
||||
_in = in;
|
||||
@ -42,6 +51,7 @@ void SinkManager::registerSinkProvider(std::string name, SinkProvider provider)
|
||||
return;
|
||||
}
|
||||
providers[name] = provider;
|
||||
providerNames.push_back(name);
|
||||
}
|
||||
|
||||
void SinkManager::registerStream(std::string name, SinkManager::Stream* stream) {
|
||||
@ -75,6 +85,22 @@ void SinkManager::unregisterStream(std::string name) {
|
||||
delete stream;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
@ -91,8 +117,37 @@ void SinkManager::unbindStream(std::string name, dsp::stream<dsp::stereo_t>* str
|
||||
streams[name]->unbindStream(stream);
|
||||
}
|
||||
|
||||
void SinkManager::setStreamSink(std::string name, std::string providerName) {
|
||||
|
||||
}
|
||||
|
||||
void SinkManager::showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
int count = 0;
|
||||
int maxCount = streams.size();
|
||||
|
||||
std::string provStr = "";
|
||||
for (auto const& [name, provider] : providers) {
|
||||
provStr += name;
|
||||
provStr += '\0';
|
||||
}
|
||||
|
||||
for (auto const& [name, stream] : streams) {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
#include <dsp/routing.h>
|
||||
#include <mutex>
|
||||
#include <event.h>
|
||||
#include <vector>
|
||||
|
||||
class SinkManager {
|
||||
public:
|
||||
@ -13,6 +14,8 @@ public:
|
||||
|
||||
class Sink {
|
||||
public:
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void menuHandler() = 0;
|
||||
};
|
||||
|
||||
@ -20,6 +23,9 @@ public:
|
||||
public:
|
||||
Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
void setInput(dsp::stream<dsp::stereo_t>* in);
|
||||
|
||||
dsp::stream<dsp::stereo_t>* bindStream();
|
||||
@ -29,13 +35,14 @@ public:
|
||||
friend SinkManager::Sink;
|
||||
|
||||
Event<float> srChange;
|
||||
SinkManager::Sink* sink;
|
||||
int providerId = 0;
|
||||
|
||||
private:
|
||||
void setSampleRate(float sampleRate);
|
||||
|
||||
dsp::stream<dsp::stereo_t>* _in;
|
||||
dsp::Splitter<dsp::stereo_t> splitter;
|
||||
SinkManager::Sink* sink;
|
||||
std::mutex ctrlMtx;
|
||||
float _sampleRate;
|
||||
|
||||
@ -51,15 +58,19 @@ public:
|
||||
void registerStream(std::string name, Stream* stream);
|
||||
void unregisterStream(std::string name);
|
||||
|
||||
void startStream(std::string name);
|
||||
void stopStream(std::string name);
|
||||
|
||||
void setStreamSink(std::string name, std::string providerName);
|
||||
|
||||
dsp::stream<dsp::stereo_t>* bindStream(std::string name);
|
||||
void unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream);
|
||||
|
||||
void showMenu();
|
||||
|
||||
private:
|
||||
// TODO: Replace with std::unordered_map
|
||||
std::map<std::string, SinkProvider> providers;
|
||||
std::map<std::string, Stream*> streams;
|
||||
|
||||
std::vector<std::string> providerNames;
|
||||
|
||||
};
|
Reference in New Issue
Block a user