From 89ba1d6122e244c971e461716a731aefbed73d6e Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Fri, 20 Oct 2023 08:02:41 -0400 Subject: [PATCH] Fix DarkPanel; Fix PolyGnome rounding; Fix warning 1. DarkPanel support had broken us at head because I forgot a widget:;step 2. But also was unfinished since I hadn't actually removed the json read etc 3. While at it, fix a rounding error in seven segment display which closes #102 4. And fix a couple of warnings the docker toolchain shows I'll mark this 2.4.0 --- src/BaconModuleWidget.h | 15 +++++------ src/Components.hpp | 5 ++-- src/KSSynth.hpp | 4 +-- src/Style.cpp | 55 +++++------------------------------------ src/Style.hpp | 2 -- 5 files changed, 17 insertions(+), 64 deletions(-) diff --git a/src/BaconModuleWidget.h b/src/BaconModuleWidget.h index 23f0b48..7de7135 100644 --- a/src/BaconModuleWidget.h +++ b/src/BaconModuleWidget.h @@ -33,20 +33,17 @@ struct BaconModuleWidget : rack::app::ModuleWidget, StyleParticipant } - bool preferDark{false}; void step() override { #ifndef USING_CARDINAL_NOT_RACK auto lpd = rack::settings::preferDarkPanels; - if (lpd != preferDark) - { - if (lpd) - BaconStyle::get()->setStyle(BaconStyle::DARK); - else - BaconStyle::get()->setStyle(BaconStyle::LIGHT); - } - preferDark = lpd; + if (lpd) + BaconStyle::get()->setStyle(BaconStyle::DARK); + else + BaconStyle::get()->setStyle(BaconStyle::LIGHT); #endif + + ModuleWidget::step(); } }; diff --git a/src/Components.hpp b/src/Components.hpp index 2581bac..11ad5e1 100644 --- a/src/Components.hpp +++ b/src/Components.hpp @@ -81,13 +81,14 @@ template struct SevenSegmentLight : T fvalue = this->module->lights[this->firstLightId].value; int value = 1; + auto ifval = (int)std::round(fvalue); if (hexMode) { - value = (int)(fvalue) % 16; + value = ifval % 16; } else { - value = int(fvalue / decimalPos) % 10; + value = int(ifval / decimalPos) % 10; } if (value != pvalue) diff --git a/src/KSSynth.hpp b/src/KSSynth.hpp index 4a47522..d22a7f0 100644 --- a/src/KSSynth.hpp +++ b/src/KSSynth.hpp @@ -122,7 +122,7 @@ class KSSynth { for (int i = 0; i < burstLen; ++i) { - delay[i] = (float)rand() * 1.0 / RAND_MAX; + delay[i] = (float)rand() * 1.0 / (float)RAND_MAX; delay[i] = delay[i] * 2.0 - 1.0; } break; @@ -150,7 +150,7 @@ class KSSynth for (int i = 0; i < burstLen; ++i) { delay[i] = (i * 1.0f / burstLen) - 0.5; - delay[i] += (float)rand() * 1.0f / RAND_MAX - 0.5; + delay[i] += (float)rand() * 1.0f / (float)RAND_MAX - 0.5; } break; } diff --git a/src/Style.cpp b/src/Style.cpp index 01a7841..a575dfb 100644 --- a/src/Style.cpp +++ b/src/Style.cpp @@ -11,37 +11,13 @@ std::shared_ptr BaconStyle::stylePtr{nullptr}; BaconStyle::BaconStyle() { - std::string defaultsDir = rack::asset::user("BaconMusic/"); - if (!rack::system::isDirectory(defaultsDir)) - rack::system::createDirectory(defaultsDir); - std::string defaultsFile = rack::asset::user("BaconMusic/default-skin.json"); - - json_error_t error; - json_t *fd = json_load_file(defaultsFile.c_str(), 0, &error); - if (!fd) - { - setStyle(LIGHT); - } +#ifndef USING_CARDINAL_NOT_RACK + auto lpd = rack::settings::preferDarkPanels; + if (lpd) + setStyle(BaconStyle::DARK); else - { - auto as = json_object_get(fd, "activeStyle"); - if (!as) - { - setStyle(LIGHT); - } - else - { - auto iv = json_integer_value(as); - if (iv == LIGHT || iv == DARK) - { - setStyle((Style)iv); - } - else - { - setStyle(LIGHT); - } - } - } + setStyle(BaconStyle::LIGHT); +#endif } NVGcolor getColorLight(baconpaul::rackplugs::BaconStyle::Colors c) @@ -144,23 +120,4 @@ NVGcolor BaconStyle::getColor(baconpaul::rackplugs::BaconStyle::Colors c) return getColorDark(c); } -void BaconStyle::updateJSON() -{ - std::string defaultsDir = rack::asset::user("BaconMusic/"); - if (!rack::system::isDirectory(defaultsDir)) - rack::system::createDirectory(defaultsDir); - std::string defaultsFile = rack::asset::user("BaconMusic/default-skin.json"); - - json_t *rootJ = json_object(); - json_t *stJ = json_integer(activeStyle); - json_object_set_new(rootJ, "activeStyle", stJ); - FILE *f = std::fopen(defaultsFile.c_str(), "w"); - if (f) - { - json_dumpf(rootJ, f, JSON_INDENT(2)); - std::fclose(f); - } - json_decref(rootJ); -} - } // namespace baconpaul::rackplugs \ No newline at end of file diff --git a/src/Style.hpp b/src/Style.hpp index 74f3226..d90d3b4 100644 --- a/src/Style.hpp +++ b/src/Style.hpp @@ -37,7 +37,6 @@ struct BaconStyle { activeStyle = s; notifyStyleListeners(); - updateJSON(); } friend struct StyleParticipant; @@ -79,7 +78,6 @@ struct BaconStyle std::unordered_set listeners; void addStyleListener(StyleParticipant *l) { listeners.insert(l); } void removeStyleListener(StyleParticipant *l) { listeners.erase(l); } - void updateJSON(); static std::shared_ptr stylePtr; };