Skip to content

Commit de63808

Browse files
authored
Make the WaveShaper display system-wide (#888)
Make the waveshaper display system wide style level setting. Default it to the old display (single curve).
1 parent 30ae08c commit de63808

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/Waveshaper.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ struct WaveshaperWidget : widgets::XTModuleWidget
5050
[m]() { m->doDCBlock = !m->doDCBlock; }));
5151

5252
menu->addChild(rack::createMenuItem(
53-
"Show Transform and Response", CHECKMARK(m->showTransformCurve),
54-
[m]() { m->showTransformCurve = !m->showTransformCurve; }));
53+
"Show Transform and Response", CHECKMARK(style()->getWaveshaperShowsBothCurves()),
54+
[this]() {
55+
style()->setWaveshaperShowsBothCurves(!style()->getWaveshaperShowsBothCurves());
56+
}));
5557
}
5658
}
5759
};
@@ -94,7 +96,7 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
9496
auto fac = 2.0;
9597
auto inputRes = (int)box.size.x * fac;
9698
auto dx = 1.0 / inputRes;
97-
auto cmul = module ? (module->showTransformCurve ? 6.0 : 4.0) : 4.0;
99+
auto cmul = module ? (style()->getWaveshaperShowsBothCurves() ? 6.0 : 4.0) : 4.0;
98100
for (int i = 0; i < inputRes; ++i)
99101
{
100102
auto x = dx * i;
@@ -124,6 +126,9 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
124126

125127
virtual void onStyleChanged() override
126128
{
129+
// If transform display has changed bounds adjust
130+
calculateInputSignal();
131+
recalcPath();
127132
bdw->dirty = true;
128133
bdwPlot->dirty = true;
129134
bdwResponse->dirty = true;
@@ -146,7 +151,6 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
146151
int dirtyCount{0};
147152
int sumDeact{-1};
148153
int sumAbs{-1};
149-
bool stc{false};
150154
uint32_t wtloadCompare{842932918};
151155

152156
bool isDirty()
@@ -176,14 +180,6 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
176180
}
177181

178182
dval = wstype != lastType || ddb != lastDrive || bias != lastBias;
179-
180-
if (module->showTransformCurve != stc)
181-
{
182-
dval = true;
183-
calculateInputSignal();
184-
stc = module->showTransformCurve;
185-
bdw->dirty = true; // special - gotta redo the background
186-
}
187183
}
188184
return dval;
189185
}
@@ -296,7 +292,7 @@ struct WaveshaperPlotWidget : public rack::widget::TransparentWidget, style::Sty
296292
if (!module)
297293
return;
298294

299-
if (!module->showTransformCurve)
295+
if (!style()->getWaveshaperShowsBothCurves())
300296
return;
301297

302298
auto bx = bdwResponse->box;

src/Waveshaper.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ struct Waveshaper : public modules::XTModule
195195
int monoChannelOffset{0};
196196

197197
std::atomic<bool> doDCBlock{true};
198-
std::atomic<bool> showTransformCurve{true};
199198
bool wasDoDCBlock{true};
200199
/*
201200
* This is a bit annoying - i don't want to break 2.0.3.0 patches by turning on
@@ -571,7 +570,6 @@ struct Waveshaper : public modules::XTModule
571570
{
572571
auto ws = json_object();
573572
json_object_set_new(ws, "doDCBlock", json_boolean(doDCBlock));
574-
json_object_set_new(ws, "showTransformCurve", json_boolean(showTransformCurve));
575573
return ws;
576574
}
577575

@@ -587,12 +585,6 @@ struct Waveshaper : public modules::XTModule
587585
{
588586
doDCBlock = true;
589587
}
590-
591-
auto stc = json_object_get(modJ, "showTransformCurve");
592-
if (stc)
593-
{
594-
showTransformCurve = json_boolean_value(stc);
595-
}
596588
}
597589
};
598590

src/XTStyle.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ void XTStyle::initialize()
146146
handleBool("showModulationAnimationOnKnobs", setShowModulationAnimationOnKnobs, true);
147147
handleBool("showModulationAnimationOnDisplay", setShowModulationAnimationOnDisplay, true);
148148
handleBool("showShadows", setShowShadows, true);
149+
handleBool("waveshaperShowsBothCurves", setWaveshaperShowsBothCurves, false);
149150

150151
json_decref(fd);
151152
}
@@ -161,6 +162,7 @@ static bool showKnobValuesAtRest{true};
161162
static bool showModulationAnimationOnKnobs{true};
162163
static bool showModulationAnimationOnDisplay{true};
163164
static bool showShadows{true};
165+
static bool waveshaperShowsBothCurves{false};
164166

165167
static std::shared_ptr<XTStyle> constructDefaultStyle()
166168
{
@@ -255,6 +257,17 @@ void XTStyle::setShowShadows(bool b)
255257
}
256258
}
257259

260+
bool XTStyle::getWaveshaperShowsBothCurves() { return waveshaperShowsBothCurves; }
261+
void XTStyle::setWaveshaperShowsBothCurves(bool b)
262+
{
263+
if (b != waveshaperShowsBothCurves)
264+
{
265+
waveshaperShowsBothCurves = b;
266+
updateJSON();
267+
notifyStyleListeners();
268+
}
269+
}
270+
258271
void XTStyle::setGlobalModulationColor(sst::surgext_rack::style::XTStyle::LightColor c)
259272
{
260273
if (c != defaultGlobalModulationColor)
@@ -319,6 +332,8 @@ void XTStyle::updateJSON()
319332
json_object_set_new(rootJ, "showModulationAnimationOnDisplay",
320333
json_boolean(showModulationAnimationOnDisplay));
321334
json_object_set_new(rootJ, "showShadows", json_boolean(showShadows));
335+
json_object_set_new(rootJ, "waveshaperShowsBothCurves",
336+
json_boolean(waveshaperShowsBothCurves));
322337
FILE *f = std::fopen(defaultsFile.c_str(), "w");
323338
if (f)
324339
{

src/XTStyle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct XTStyle
8383
static bool getShowShadows();
8484
static void setShowShadows(bool b);
8585

86+
static bool getWaveshaperShowsBothCurves();
87+
static void setWaveshaperShowsBothCurves(bool b);
88+
8689
static std::string lightColorName(LightColor c);
8790
static NVGcolor lightColorColor(LightColor c);
8891

0 commit comments

Comments
 (0)