SDRPlusPlus/core/src/signal_path/source.cpp

84 wiersze
2.2 KiB
C++
Czysty Zwykły widok Historia

2020-09-30 23:21:15 +00:00
#include <signal_path/source.h>
#include <spdlog/spdlog.h>
#include <signal_path/signal_path.h>
SourceManager::SourceManager() {
}
void SourceManager::registerSource(std::string name, SourceHandler* handler) {
if (sources.find(name) != sources.end()) {
spdlog::error("Tried to register new source with existing name: {0}", name);
return;
}
sources[name] = handler;
2021-07-26 01:11:51 +00:00
onSourceRegistered.emit(name);
}
void SourceManager::unregisterSource(std::string name) {
if (sources.find(name) == sources.end()) {
spdlog::error("Tried to unregister non existant source: {0}", name);
return;
}
onSourceUnregister.emit(name);
if (name == selectedName) {
sigpath::signalPath.setInput(&nullSource);
selectedHandler = NULL;
}
sources.erase(name);
onSourceUnregistered.emit(name);
}
std::vector<std::string> SourceManager::getSourceNames() {
std::vector<std::string> names;
for (auto const& [name, src] : sources) { names.push_back(name); }
return names;
2020-09-30 23:21:15 +00:00
}
void SourceManager::selectSource(std::string name) {
if (sources.find(name) == sources.end()) {
spdlog::error("Tried to select non existant source: {0}", name);
return;
}
2021-07-26 01:11:51 +00:00
if (selectedHandler != NULL) {
2020-09-30 23:21:15 +00:00
sources[selectedName]->deselectHandler(sources[selectedName]->ctx);
}
selectedHandler = sources[name];
selectedHandler->selectHandler(selectedHandler->ctx);
selectedName = name;
sigpath::signalPath.setInput(selectedHandler->stream);
}
void SourceManager::showSelectedMenu() {
if (selectedHandler == NULL) {
return;
}
selectedHandler->menuHandler(selectedHandler->ctx);
}
void SourceManager::start() {
if (selectedHandler == NULL) {
return;
}
selectedHandler->startHandler(selectedHandler->ctx);
}
void SourceManager::stop() {
if (selectedHandler == NULL) {
return;
}
selectedHandler->stopHandler(selectedHandler->ctx);
}
void SourceManager::tune(double freq) {
if (selectedHandler == NULL) {
return;
}
2020-10-20 12:59:42 +00:00
selectedHandler->tuneHandler(freq + tuneOffset, selectedHandler->ctx);
currentFreq = freq;
}
void SourceManager::setTuningOffset(double offset) {
tuneOffset = offset;
tune(currentFreq);
2020-09-30 23:21:15 +00:00
}