mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-25 12:07:49 +02:00
Added module management system
This commit is contained in:
@ -171,7 +171,11 @@ int sdrpp_main(int argc, char *argv[]) {
|
||||
defConfig["showMenu"] = true;
|
||||
defConfig["showWaterfall"] = true;
|
||||
defConfig["source"] = "";
|
||||
defConfig["streams"] = json::object();
|
||||
|
||||
defConfig["streams"]["Radio"]["muted"] = false;
|
||||
defConfig["streams"]["Radio"]["sink"] = "Audio";
|
||||
defConfig["streams"]["Radio"]["volume"] = 1.0f;
|
||||
|
||||
defConfig["windowSize"]["h"] = 720;
|
||||
defConfig["windowSize"]["w"] = 1280;
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <gui/menus/bandplan.h>
|
||||
#include <gui/menus/sink.h>
|
||||
#include <gui/menus/scripting.h>
|
||||
#include <gui/menus/vfo_color.h>
|
||||
#include <gui/menus/module_manager.h>
|
||||
#include <gui/dialogs/credits.h>
|
||||
#include <filesystem>
|
||||
#include <signal_path/source.h>
|
||||
@ -32,7 +34,6 @@
|
||||
#include <options.h>
|
||||
#include <gui/colormaps.h>
|
||||
#include <gui/widgets/snr_meter.h>
|
||||
#include <gui/menus/vfo_color.h>
|
||||
|
||||
int fftSize = 8192 * 8;
|
||||
|
||||
@ -102,6 +103,19 @@ bool demoWindow = false;
|
||||
|
||||
float testSNR = 50;
|
||||
|
||||
EventHandler<VFOManager::VFO*> vfoCreatedHandler;
|
||||
void vfoAddedHandler(VFOManager::VFO* vfo, void* ctx) {
|
||||
std::string name = vfo->getName();
|
||||
core::configManager.aquire();
|
||||
if (!core::configManager.conf["vfoOffsets"].contains(name)) {
|
||||
core::configManager.release();
|
||||
return;
|
||||
}
|
||||
double offset = core::configManager.conf["vfoOffsets"][name];
|
||||
core::configManager.release();
|
||||
sigpath::vfoManager.setOffset(name, std::clamp<double>(offset, -bw/2.0, bw/2.0));
|
||||
}
|
||||
|
||||
void windowInit() {
|
||||
LoadingScreen::show("Initializing UI");
|
||||
gui::waterfall.init();
|
||||
@ -137,6 +151,7 @@ void windowInit() {
|
||||
gui::menu.registerEntry("Band Plan", bandplanmenu::draw, NULL);
|
||||
gui::menu.registerEntry("Display", displaymenu::draw, NULL);
|
||||
gui::menu.registerEntry("VFO Color", vfo_color_menu::draw, NULL);
|
||||
gui::menu.registerEntry("Module Manager", module_manager_menu::draw, NULL);
|
||||
|
||||
gui::freqSelect.init();
|
||||
|
||||
@ -151,6 +166,9 @@ void windowInit() {
|
||||
sigpath::signalPath.init(8000000, 20, fftSize, &dummyStream, (dsp::complex_t*)fft_in, fftHandler);
|
||||
sigpath::signalPath.start();
|
||||
|
||||
vfoCreatedHandler.handler = vfoAddedHandler;
|
||||
sigpath::vfoManager.vfoCreatedEvent.bindHandler(vfoCreatedHandler);
|
||||
|
||||
spdlog::info("Loading modules");
|
||||
|
||||
// Load modules from /module directory
|
||||
@ -217,6 +235,7 @@ void windowInit() {
|
||||
bandplanmenu::init();
|
||||
displaymenu::init();
|
||||
vfo_color_menu::init();
|
||||
module_manager_menu::init();
|
||||
|
||||
// TODO for 0.2.5
|
||||
// Add "select file" option for the file source
|
||||
@ -259,15 +278,6 @@ void windowInit() {
|
||||
|
||||
centerTuning = core::configManager.conf["centerTuning"];
|
||||
|
||||
// Load each VFO's offset
|
||||
for (auto const& [name, _vfo] : gui::waterfall.vfos) {
|
||||
if (!core::configManager.conf["vfoOffsets"].contains(name)) {
|
||||
continue;
|
||||
}
|
||||
double offset = core::configManager.conf["vfoOffsets"][name];
|
||||
sigpath::vfoManager.setOffset(name, std::clamp<double>(offset, -bw/2.0, bw/2.0));
|
||||
}
|
||||
|
||||
core::configManager.release();
|
||||
}
|
||||
|
||||
|
79
core/src/gui/menus/module_manager.cpp
Normal file
79
core/src/gui/menus/module_manager.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include <gui/menus/module_manager.h>
|
||||
#include <imgui.h>
|
||||
#include <core.h>
|
||||
#include <string.h>
|
||||
#include <gui/style.h>
|
||||
|
||||
namespace module_manager_menu {
|
||||
char modName[1024];
|
||||
std::vector<std::string> modTypes;
|
||||
std::string modTypesTxt;
|
||||
int modTypeId;
|
||||
|
||||
void init() {
|
||||
modName[0] = 0;
|
||||
|
||||
modTypes.clear();
|
||||
modTypesTxt = "";
|
||||
for (auto& [name, mod] : core::moduleManager.modules) {
|
||||
// TEMPORARY EXCLUSION FOR SOURCES AND SINKS
|
||||
if (name.find("source") != std::string::npos) { continue; }
|
||||
if (name.find("sink") != std::string::npos) { continue; }
|
||||
if (name.find("recorder") != std::string::npos) { continue; }
|
||||
if (name.find("discord") != std::string::npos) { continue; }
|
||||
modTypes.push_back(name);
|
||||
modTypesTxt += name;
|
||||
modTypesTxt += '\0';
|
||||
}
|
||||
modTypeId = 0;
|
||||
}
|
||||
|
||||
void draw(void* ctx) {
|
||||
ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg);
|
||||
ImGui::TableSetupColumn("Name");
|
||||
ImGui::TableSetupColumn("Type");
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 16);
|
||||
ImGui::TableHeadersRow();
|
||||
for (auto& [name, inst] : core::moduleManager.instances) {
|
||||
// TEMPORARY EXCLUSION FOR SOURCES AND SINKS
|
||||
std::string type = inst.module.info->name;
|
||||
if (type.find("source") != std::string::npos) { continue; }
|
||||
if (type.find("sink") != std::string::npos) { continue; }
|
||||
if (type.find("recorder") != std::string::npos) { continue; }
|
||||
if (type.find("discord") != std::string::npos) { continue; }
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text(name.c_str());
|
||||
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text(inst.module.info->name);
|
||||
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
if (ImGui::Button(("-##module_mgr_"+name).c_str(), ImVec2(16,0))) {
|
||||
core::moduleManager.deleteInstance(name);
|
||||
}
|
||||
}
|
||||
|
||||
// Add module row
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth());
|
||||
ImGui::InputText("##module_mod_name", modName, 1000);
|
||||
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth());
|
||||
ImGui::Combo("##module_mgr_type", &modTypeId, modTypesTxt.c_str());
|
||||
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
if (strlen(modName) == 0) { style::beginDisabled(); }
|
||||
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) {
|
||||
core::moduleManager.createInstance(modName, modTypes[modTypeId]);
|
||||
}
|
||||
if (strlen(modName) == 0) { style::endDisabled(); }
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
6
core/src/gui/menus/module_manager.h
Normal file
6
core/src/gui/menus/module_manager.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace module_manager_menu {
|
||||
void init();
|
||||
void draw(void* ctx);
|
||||
}
|
@ -100,11 +100,17 @@ void ModuleManager::createInstance(std::string name, std::string module) {
|
||||
}
|
||||
|
||||
void ModuleManager::deleteInstance(std::string name) {
|
||||
spdlog::error("DELETE INSTANCE NOT IMPLEMENTED");
|
||||
if (instances.find(name) == instances.end()) {
|
||||
spdlog::error("Tried to remove non-existant instance '{0}'", name);
|
||||
return;
|
||||
}
|
||||
Instance_t inst = instances[name];
|
||||
inst.module.deleteInstance(inst.instance);
|
||||
instances.erase(name);
|
||||
}
|
||||
|
||||
void ModuleManager::deleteInstance(ModuleManager::Instance* instance) {
|
||||
spdlog::error("DELETE INSTANCE NOT IMPLEMENTED");
|
||||
spdlog::error("Delete instance not implemented");
|
||||
}
|
||||
|
||||
void ModuleManager::enableInstance(std::string name) {
|
||||
|
@ -86,7 +86,6 @@ public:
|
||||
|
||||
int countModuleInstances(std::string module);
|
||||
|
||||
private:
|
||||
std::map<std::string, ModuleManager::Module_t> modules;
|
||||
std::map<std::string, ModuleManager::Instance_t> instances;
|
||||
|
||||
|
@ -108,6 +108,14 @@ void SinkManager::registerStream(std::string name, SinkManager::Stream* stream)
|
||||
|
||||
streams[name] = stream;
|
||||
streamNames.push_back(name);
|
||||
|
||||
// Load config
|
||||
core::configManager.aquire();
|
||||
bool available = core::configManager.conf["streams"].contains(name);
|
||||
core::configManager.release();
|
||||
if (available) { loadStreamConfig(name); }
|
||||
|
||||
streamRegisteredEvnt.emit(name);
|
||||
}
|
||||
|
||||
void SinkManager::unregisterStream(std::string name) {
|
||||
@ -115,10 +123,12 @@ void SinkManager::unregisterStream(std::string name) {
|
||||
spdlog::error("Cannot unregister stream '{0}', this stream doesn't exist", name);
|
||||
return;
|
||||
}
|
||||
spdlog::error("unregisterStream NOT IMPLEMENTED!!!!!!!");
|
||||
streamUnregisteredEvnt.emit(name);
|
||||
SinkManager::Stream* stream = streams[name];
|
||||
stream->stop();
|
||||
delete stream->sink;
|
||||
delete stream;
|
||||
streams.erase(name);
|
||||
streamNames.erase(std::remove(streamNames.begin(), streamNames.end(), name), streamNames.end());
|
||||
}
|
||||
|
||||
void SinkManager::startStream(std::string name) {
|
||||
|
@ -110,6 +110,9 @@ public:
|
||||
|
||||
std::vector<std::string> getStreamNames();
|
||||
|
||||
Event<std::string> streamRegisteredEvnt;
|
||||
Event<std::string> streamUnregisteredEvnt;
|
||||
|
||||
private:
|
||||
void loadStreamConfig(std::string name);
|
||||
void saveStreamConfig(std::string name);
|
||||
|
Reference in New Issue
Block a user