Added module management system

This commit is contained in:
Ryzerth
2021-05-05 04:31:37 +02:00
parent 85b9649a9a
commit 1b27916c24
20 changed files with 191 additions and 33 deletions

View File

@ -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();
}

View 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();
}
}

View File

@ -0,0 +1,6 @@
#pragma once
namespace module_manager_menu {
void init();
void draw(void* ctx);
}