From 747b6bfbc6d1f5915f897cde7e47a4d97090a8b0 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 31 Mar 2022 20:16:21 +0200 Subject: [PATCH] Added FFT hold feature --- core/src/core.cpp | 2 ++ core/src/gui/menus/display.cpp | 28 ++++++++++++++++++++++++++++ core/src/gui/theme_manager.cpp | 8 +++++++- core/src/gui/theme_manager.h | 2 +- core/src/gui/widgets/waterfall.cpp | 12 ++++++++---- core/src/gui/widgets/waterfall.h | 2 ++ root/res/themes/dark.json | 1 + root/res/themes/light.json | 1 + 8 files changed, 50 insertions(+), 6 deletions(-) diff --git a/core/src/core.cpp b/core/src/core.cpp index 350df093..a47601c2 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -108,6 +108,8 @@ int sdrpp_main(int argc, char* argv[]) { defConfig["bandPlanPos"] = 0; defConfig["centerTuning"] = false; defConfig["colorMap"] = "Classic"; + defConfig["fftHold"] = false; + defConfig["fftHoldSpeed"] = 60; defConfig["fastFFT"] = false; defConfig["fftHeight"] = 300; defConfig["fftRate"] = 20; diff --git a/core/src/gui/menus/display.cpp b/core/src/gui/menus/display.cpp index cf298f8f..40a6c52d 100644 --- a/core/src/gui/menus/display.cpp +++ b/core/src/gui/menus/display.cpp @@ -21,6 +21,8 @@ namespace displaymenu { int fftRate = 20; int uiScaleId = 0; bool restartRequired = false; + bool fftHold = false; + int fftHoldSpeed = 60; OptionList uiScales; @@ -50,6 +52,10 @@ namespace displaymenu { int fftSizeId = 0; + void updateFFTHoldSpeed() { + gui::waterfall.setFFTHoldSpeed(fftHoldSpeed / (fftRate * 10.0f)); + } + void init() { showWaterfall = core::configManager.conf["showWaterfall"]; showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall(); @@ -93,6 +99,11 @@ namespace displaymenu { gui::menu.locked = core::configManager.conf["lockMenuOrder"]; + fftHold = core::configManager.conf["fftHold"]; + fftHoldSpeed = core::configManager.conf["fftHoldSpeed"]; + gui::waterfall.setFFTHold(fftHold); + updateFFTHoldSpeed(); + // Define and load UI scales uiScales.define(1.0f, "100%", 1.0f); uiScales.define(2.0f, "200%", 2.0f); @@ -132,6 +143,22 @@ namespace displaymenu { core::configManager.release(true); } + if (ImGui::Checkbox("FFT Hold##_sdrpp", &fftHold)) { + gui::waterfall.setFFTHold(fftHold); + core::configManager.acquire(); + core::configManager.conf["fftHold"] = fftHold; + core::configManager.release(true); + } + + ImGui::LeftLabel("FFT Hold Speed"); + ImGui::FillWidth(); + if (ImGui::InputInt("##sdrpp_fft_hold_speed", &fftHoldSpeed)) { + updateFFTHoldSpeed(); + core::configManager.acquire(); + core::configManager.conf["fftHoldSpeed"] = fftHoldSpeed; + core::configManager.release(true); + } + ImGui::LeftLabel("High-DPI Scaling"); ImGui::FillWidth(); if (ImGui::Combo("##sdrpp_ui_scale", &uiScaleId, uiScales.txt)) { @@ -146,6 +173,7 @@ namespace displaymenu { if (ImGui::InputInt("##sdrpp_fft_rate", &fftRate, 1, 10)) { fftRate = std::max(1, fftRate); sigpath::signalPath.setFFTRate(fftRate); + updateFFTHoldSpeed(); core::configManager.acquire(); core::configManager.conf["fftRate"] = fftRate; core::configManager.release(true); diff --git a/core/src/gui/theme_manager.cpp b/core/src/gui/theme_manager.cpp index ca121608..f55d53da 100644 --- a/core/src/gui/theme_manager.cpp +++ b/core/src/gui/theme_manager.cpp @@ -84,7 +84,7 @@ bool ThemeManager::loadTheme(std::string path) { if (param == "name" || param == "author") { continue; } // Exception for non-imgu colors - if (param == "WaterfallBackground" || param == "ClearColor") { + if (param == "WaterfallBackground" || param == "ClearColor" || param == "FFTHoldColor") { if (val[0] != '#' || !std::all_of(val.begin() + 1, val.end(), ::isxdigit) || val.length() != 9) { spdlog::error("Theme {0} contains invalid {1} field. Expected hex RGBA color", path, param); return false; @@ -152,6 +152,12 @@ bool ThemeManager::applyTheme(std::string name) { continue; } + if (param == "FFTHoldColor") { + decodeRGBA(val, ret); + fftHoldColor = ImVec4((float)ret[0] / 255.0f, (float)ret[1] / 255.0f, (float)ret[2] / 255.0f, (float)ret[3] / 255.0f); + continue; + } + // If param is a color, check that it's a valid RGBA hex value if (IMGUI_COL_IDS.find(param) != IMGUI_COL_IDS.end()) { decodeRGBA(val, ret); diff --git a/core/src/gui/theme_manager.h b/core/src/gui/theme_manager.h index f36c6013..cb17af20 100644 --- a/core/src/gui/theme_manager.h +++ b/core/src/gui/theme_manager.h @@ -21,7 +21,7 @@ public: std::vector getThemeNames(); ImVec4 waterfallBg = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - ; + ImVec4 fftHoldColor = ImVec4(0.0f, 1.0f, 0.75f, 1.0f); ImVec4 clearColor = ImVec4(0.0666f, 0.0666f, 0.0666f, 1.0f); private: diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 3fbef32a..12f41c93 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -76,8 +76,8 @@ namespace ImGui { lastWidgetPos.y = 0; lastWidgetSize.x = 0; lastWidgetSize.y = 0; - latestFFT = new float[1]; - latestFFTHold = new float[1]; + latestFFT = new float[dataWidth]; + latestFFTHold = new float[dataWidth]; waterfallFb = new uint32_t[1]; viewBandwidth = 1.0; @@ -98,7 +98,7 @@ namespace ImGui { char buf[100]; ImU32 trace = ImGui::GetColorU32(ImGuiCol_PlotLines); - ImU32 traceHold = ImGui::ColorConvertFloat4ToU32(ImVec4(1.0, 1.0, 0.0, 1.0)); + ImU32 traceHold = ImGui::ColorConvertFloat4ToU32(gui::themeManager.fftHoldColor); ImU32 shadow = ImGui::GetColorU32(ImGuiCol_PlotLines, 0.2); ImU32 text = ImGui::GetColorU32(ImGuiCol_Text); float textVOffset = 10.0f * style::uiScale; @@ -888,7 +888,7 @@ namespace ImGui { // If FFT hold is enabled, update it if (fftHold && latestFFT != NULL && latestFFTHold != NULL && fftLines != 0) { for (int i = 1; i < dataWidth; i++) { - latestFFTHold[i] = std::max(latestFFT[i], latestFFTHold[i] - 0.3f); + latestFFTHold[i] = std::max(latestFFT[i], latestFFTHold[i] - fftHoldSpeed); } } @@ -1112,6 +1112,10 @@ namespace ImGui { } } + void WaterFall::setFFTHoldSpeed(float speed) { + fftHoldSpeed = speed; + } + void WaterfallVFO::setOffset(double offset) { generalOffset = offset; if (reference == REF_CENTER) { diff --git a/core/src/gui/widgets/waterfall.h b/core/src/gui/widgets/waterfall.h index fdc06e52..c196e098 100644 --- a/core/src/gui/widgets/waterfall.h +++ b/core/src/gui/widgets/waterfall.h @@ -177,6 +177,7 @@ namespace ImGui { void setBandPlanPos(int pos); void setFFTHold(bool hold); + void setFFTHoldSpeed(float speed); bool centerFreqMoved = false; bool vfoFreqChanged = false; @@ -328,6 +329,7 @@ namespace ImGui { int bandPlanPos = BANDPLAN_POS_BOTTOM; bool fftHold = false; + float fftHoldSpeed = 0.3f; // UI Select elements bool fftResizeSelect = false; diff --git a/root/res/themes/dark.json b/root/res/themes/dark.json index a69a5f3f..666b8f14 100644 --- a/root/res/themes/dark.json +++ b/root/res/themes/dark.json @@ -9,6 +9,7 @@ "CheckMark": "#3D84E0FF", "ChildBg": "#FFFFFF00", "DragDropTarget": "#FFFF00E5", + "FFTHoldColor": "#FFFF00FF", "FrameBg": "#33353889", "FrameBgActive": "#33353889", "FrameBgHovered": "#33353889", diff --git a/root/res/themes/light.json b/root/res/themes/light.json index 79c17764..051e2ce8 100644 --- a/root/res/themes/light.json +++ b/root/res/themes/light.json @@ -9,6 +9,7 @@ "CheckMark": "#3D84E0FF", "ChildBg": "#00000000", "DragDropTarget": "#0000FFE5", + "FFTHoldColor": "#C08000FF", "FrameBg": "#ACA7A389", "FrameBgActive": "#ACA7A389", "FrameBgHovered": "#ACA7A389",