Skip to content

Commit

Permalink
Fix DarkPanel; Fix PolyGnome rounding; Fix warning
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baconpaul committed Oct 20, 2023
1 parent af520ba commit 89ba1d6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 64 deletions.
15 changes: 6 additions & 9 deletions src/BaconModuleWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

};
Expand Down
5 changes: 3 additions & 2 deletions src/Components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ template <typename T, int px = 4> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/KSSynth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
55 changes: 6 additions & 49 deletions src/Style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,13 @@ std::shared_ptr<BaconStyle> 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)
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/Style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct BaconStyle
{
activeStyle = s;
notifyStyleListeners();
updateJSON();
}

friend struct StyleParticipant;
Expand Down Expand Up @@ -79,7 +78,6 @@ struct BaconStyle
std::unordered_set<StyleParticipant *> listeners;
void addStyleListener(StyleParticipant *l) { listeners.insert(l); }
void removeStyleListener(StyleParticipant *l) { listeners.erase(l); }
void updateJSON();
static std::shared_ptr<BaconStyle> stylePtr;
};

Expand Down

0 comments on commit 89ba1d6

Please sign in to comment.