From 2c729bf646add5268ba7c43f547fecf2168fb2a9 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 9 Dec 2020 19:45:32 +0100 Subject: [PATCH] Added persistant settings to recorder module --- core/src/gui/widgets/waterfall.cpp | 5 ++--- recorder/src/main.cpp | 33 ++++++++++++++++++++++++++---- root_dev/config.json | 6 +++--- root_dev/recorder_config.json | 6 ++++++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 root_dev/recorder_config.json diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 961fae2c..f668e9e0 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -5,6 +5,8 @@ #include #include +#include + float COLOR_MAP[][3] = { {0x00, 0x00, 0x20}, {0x00, 0x00, 0x30}, @@ -152,9 +154,6 @@ namespace ImGui { for (int i = 1; i < dataWidth; i++) { double aPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i - 1] - fftMin) * scaleFactor); double bPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i] - fftMin) * scaleFactor); - if (aPos < fftMin && bPos < fftMin) { - continue; - } aPos = std::clamp(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); bPos = std::clamp(bPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)), diff --git a/recorder/src/main.cpp b/recorder/src/main.cpp index 815bd66c..9ad50fde 100644 --- a/recorder/src/main.cpp +++ b/recorder/src/main.cpp @@ -25,6 +25,8 @@ SDRPP_MOD_INFO { // TODO: Fix this and finish module +ConfigManager config; + std::string genFileName(std::string prefix) { time_t now = time(0); tm *ltm = localtime(&now); @@ -54,7 +56,17 @@ public: selectedStreamName = ""; selectedStreamId = 0; lastNameList = ""; - strcpy(path, "%ROOT%/recordings"); + + config.aquire(); + if (!config.conf.contains(name)) { + config.conf[name]["recMode"] = 1; + config.conf[name]["directory"] = "%ROOT%/recordings"; + } + recMode = config.conf[name]["recMode"]; + std::string recPath = config.conf[name]["directory"]; + strcpy(path, recPath.c_str()); + config.release(true); + gui::menu.registerEntry(name, menuHandler, this); } @@ -122,6 +134,9 @@ private: } else { _this->pathValid = true; + config.aquire(); + config.conf[_this->name]["directory"] = _this->path; + config.release(true); } } if (!lastPathValid) { @@ -133,10 +148,16 @@ private: ImGui::Columns(2, CONCAT("RecordModeColumns##_", _this->name), false); if (ImGui::RadioButton(CONCAT("Baseband##_", _this->name), _this->recMode == 0) && _this->recMode != 0) { _this->recMode = 0; + config.aquire(); + config.conf[_this->name]["recMode"] = _this->recMode; + config.release(true); } ImGui::NextColumn(); if (ImGui::RadioButton(CONCAT("Audio##_", _this->name), _this->recMode == 1) && _this->recMode != 1) { _this->recMode = 1; + config.aquire(); + config.conf[_this->name]["recMode"] = _this->recMode; + config.release(true); } if (_this->recording) { style::endDisabled(); } ImGui::Columns(1, CONCAT("EndRecordModeColumns##_", _this->name), false); @@ -275,7 +296,7 @@ private: uint64_t samplesWritten; float sampleRate; float vfoSampleRate = 200000; - int recMode = 0; + int recMode = 1; }; @@ -284,7 +305,10 @@ struct RecorderContext_t { }; MOD_EXPORT void _INIT_() { - // Nothing here + json def = json({}); + config.setPath(ROOT_DIR "/recorder_config.json"); + config.load(def); + config.enableAutoSave(); } MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { @@ -296,5 +320,6 @@ MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* inst) { } MOD_EXPORT void _END_(RecorderContext_t* ctx) { - + config.disableAutoSave(); + config.save(); } \ No newline at end of file diff --git a/root_dev/config.json b/root_dev/config.json index 0cf291fb..92c23a3c 100644 --- a/root_dev/config.json +++ b/root_dev/config.json @@ -3,7 +3,7 @@ "bandPlanEnabled": true, "centerTuning": false, "fftHeight": 300, - "frequency": 99808000, + "frequency": 99716000, "max": 0.0, "maximized": false, "menuOrder": [ @@ -17,7 +17,7 @@ "Display" ], "menuWidth": 300, - "min": -70.0, + "min": -65.44117736816406, "moduleInstances": { "Audio Sink": "audio_sink", "PlutoSDR Source": "plutosdr_source", @@ -41,7 +41,7 @@ "Radio": { "muted": false, "sink": "Audio", - "volume": 0.41326531767845154 + "volume": 0.4285714328289032 }, "Radio 1": { "muted": false, diff --git a/root_dev/recorder_config.json b/root_dev/recorder_config.json new file mode 100644 index 00000000..4a5ca25e --- /dev/null +++ b/root_dev/recorder_config.json @@ -0,0 +1,6 @@ +{ + "Recorder": { + "directory": "%ROOT%/recordings", + "recMode": 1 + } +} \ No newline at end of file