Skip to content

Commit

Permalink
Make the WaveShaper display system-wide (#888)
Browse files Browse the repository at this point in the history
Make the waveshaper display system wide style level setting.
Default it to the old display (single curve).
  • Loading branch information
baconpaul committed May 23, 2023
1 parent 30ae08c commit de63808
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
22 changes: 9 additions & 13 deletions src/Waveshaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ struct WaveshaperWidget : widgets::XTModuleWidget
[m]() { m->doDCBlock = !m->doDCBlock; }));

menu->addChild(rack::createMenuItem(
"Show Transform and Response", CHECKMARK(m->showTransformCurve),
[m]() { m->showTransformCurve = !m->showTransformCurve; }));
"Show Transform and Response", CHECKMARK(style()->getWaveshaperShowsBothCurves()),
[this]() {
style()->setWaveshaperShowsBothCurves(!style()->getWaveshaperShowsBothCurves());
}));
}
}
};
Expand Down Expand Up @@ -94,7 +96,7 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
auto fac = 2.0;
auto inputRes = (int)box.size.x * fac;
auto dx = 1.0 / inputRes;
auto cmul = module ? (module->showTransformCurve ? 6.0 : 4.0) : 4.0;
auto cmul = module ? (style()->getWaveshaperShowsBothCurves() ? 6.0 : 4.0) : 4.0;
for (int i = 0; i < inputRes; ++i)
{
auto x = dx * i;
Expand Down Expand Up @@ -124,6 +126,9 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty

virtual void onStyleChanged() override
{
// If transform display has changed bounds adjust
calculateInputSignal();
recalcPath();
bdw->dirty = true;
bdwPlot->dirty = true;
bdwResponse->dirty = true;
Expand All @@ -146,7 +151,6 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
int dirtyCount{0};
int sumDeact{-1};
int sumAbs{-1};
bool stc{false};
uint32_t wtloadCompare{842932918};

bool isDirty()
Expand Down Expand Up @@ -176,14 +180,6 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
}

dval = wstype != lastType || ddb != lastDrive || bias != lastBias;

if (module->showTransformCurve != stc)
{
dval = true;
calculateInputSignal();
stc = module->showTransformCurve;
bdw->dirty = true; // special - gotta redo the background
}
}
return dval;
}
Expand Down Expand Up @@ -296,7 +292,7 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
if (!module)
return;

if (!module->showTransformCurve)
if (!style()->getWaveshaperShowsBothCurves())
return;

auto bx = bdwResponse->box;
Expand Down
8 changes: 0 additions & 8 deletions src/Waveshaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ struct Waveshaper : public modules::XTModule
int monoChannelOffset{0};

std::atomic<bool> doDCBlock{true};
std::atomic<bool> showTransformCurve{true};
bool wasDoDCBlock{true};
/*
* This is a bit annoying - i don't want to break 2.0.3.0 patches by turning on
Expand Down Expand Up @@ -571,7 +570,6 @@ struct Waveshaper : public modules::XTModule
{
auto ws = json_object();
json_object_set_new(ws, "doDCBlock", json_boolean(doDCBlock));
json_object_set_new(ws, "showTransformCurve", json_boolean(showTransformCurve));
return ws;
}

Expand All @@ -587,12 +585,6 @@ struct Waveshaper : public modules::XTModule
{
doDCBlock = true;
}

auto stc = json_object_get(modJ, "showTransformCurve");
if (stc)
{
showTransformCurve = json_boolean_value(stc);
}
}
};

Expand Down
15 changes: 15 additions & 0 deletions src/XTStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void XTStyle::initialize()
handleBool("showModulationAnimationOnKnobs", setShowModulationAnimationOnKnobs, true);
handleBool("showModulationAnimationOnDisplay", setShowModulationAnimationOnDisplay, true);
handleBool("showShadows", setShowShadows, true);
handleBool("waveshaperShowsBothCurves", setWaveshaperShowsBothCurves, false);

json_decref(fd);
}
Expand All @@ -161,6 +162,7 @@ static bool showKnobValuesAtRest{true};
static bool showModulationAnimationOnKnobs{true};
static bool showModulationAnimationOnDisplay{true};
static bool showShadows{true};
static bool waveshaperShowsBothCurves{false};

static std::shared_ptr<XTStyle> constructDefaultStyle()
{
Expand Down Expand Up @@ -255,6 +257,17 @@ void XTStyle::setShowShadows(bool b)
}
}

bool XTStyle::getWaveshaperShowsBothCurves() { return waveshaperShowsBothCurves; }
void XTStyle::setWaveshaperShowsBothCurves(bool b)
{
if (b != waveshaperShowsBothCurves)
{
waveshaperShowsBothCurves = b;
updateJSON();
notifyStyleListeners();
}
}

void XTStyle::setGlobalModulationColor(sst::surgext_rack::style::XTStyle::LightColor c)
{
if (c != defaultGlobalModulationColor)
Expand Down Expand Up @@ -319,6 +332,8 @@ void XTStyle::updateJSON()
json_object_set_new(rootJ, "showModulationAnimationOnDisplay",
json_boolean(showModulationAnimationOnDisplay));
json_object_set_new(rootJ, "showShadows", json_boolean(showShadows));
json_object_set_new(rootJ, "waveshaperShowsBothCurves",
json_boolean(waveshaperShowsBothCurves));
FILE *f = std::fopen(defaultsFile.c_str(), "w");
if (f)
{
Expand Down
3 changes: 3 additions & 0 deletions src/XTStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct XTStyle
static bool getShowShadows();
static void setShowShadows(bool b);

static bool getWaveshaperShowsBothCurves();
static void setWaveshaperShowsBothCurves(bool b);

static std::string lightColorName(LightColor c);
static NVGcolor lightColorColor(LightColor c);

Expand Down

0 comments on commit de63808

Please sign in to comment.