-
Notifications
You must be signed in to change notification settings - Fork 12
/
Delay.cpp
197 lines (165 loc) · 7.04 KB
/
Delay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* SurgeXT for VCV Rack - a Surge Synth Team product
*
* A set of modules expressing Surge XT into the VCV Rack Module Ecosystem
*
* Copyright 2019 - 2024, Various authors, as described in the github
* transaction log.
*
* Surge XT for VCV Rack is released under the GNU General Public License
* 3.0 or later (GPL-3.0-or-later). A copy of the license is in this
* repository in the file "LICENSE" or at:
*
* or at https://www.gnu.org/licenses/gpl-3.0.en.html
*
* All source for Surge XT for VCV Rack is available at
* https://github.com/surge-synthesizer/surge-rack/
*/
#include "Delay.h"
#include "SurgeXT.h"
#include "XTModuleWidget.h"
#include "XTWidgets.h"
#include "LayoutEngine.h"
namespace sst::surgext_rack::delay::ui
{
struct DelayWidget : widgets::XTModuleWidget
{
typedef delay::Delay M;
DelayWidget(M *module);
std::array<std::array<rack::Widget *, M::n_mod_inputs>, M::n_delay_params> overlays;
std::array<widgets::ModulatableKnob *, M::n_delay_params> underKnobs;
std::array<widgets::ModToggleButton *, M::n_mod_inputs> toggles;
void appendModuleSpecificMenu(rack::ui::Menu *menu) override
{
if (!module)
return;
addClockMenu<Delay>(menu);
menu->addChild(new rack::ui::MenuSeparator);
menu->addChild(rack::createMenuLabel("Delay Line Clipping"));
addSelectionMenu(
menu, module->paramQuantities[M::CLIP_MODE_PARAM],
{{"No Clipper (Potentially Unbounded)", M::ClipMode::TRANSPARENT},
{"Softclip @+/-5V (Surge VST Behavior)", M::ClipMode::SOFTCLIP_DELAYLINE_5V},
{"Softclip @+/-10V", M::ClipMode::SOFTCLIP_DELAYLINE_10V},
{"Hardclip @+/-10V", M::ClipMode::HARDCLIP_DELAYLINE_10V}});
}
void selectModulator(int mod) override
{
if (toggles[mod])
toggles[mod]->onToggle(!toggles[mod]->pressedState);
}
};
struct TimeDisplay : rack::widget::TransparentWidget, style::StyleParticipant
{
Delay *module{nullptr};
widgets::BufferedDrawFunctionWidget *bdw{nullptr};
static TimeDisplay *create(Delay *module)
{
auto res = new TimeDisplay();
res->box.pos.x = rack::mm2px(widgets::LCDBackground::contentPosX_MM);
res->box.pos.y = rack::mm2px(widgets::LCDBackground::contentPosY_MM);
res->box.size.x =
rack::RACK_GRID_WIDTH * 12 - 2 * rack::mm2px(widgets::LCDBackground::contentPosX_MM);
res->box.size.y = rack::mm2px(4.5);
res->module = module;
res->setup();
return res;
}
void setup()
{
bdw = new widgets::BufferedDrawFunctionWidget(rack::Vec(0, 0),
rack::Vec(this->box.size.x, this->box.size.y),
[this](auto *v) { this->drawDelays(v); });
this->addChild(bdw);
}
std::string ll{"1.00 s"}, lr{"0.25 s"};
void step() override
{
if (module)
{
auto l = module->paramQuantities[Delay::TIME_L]->getDisplayValueString();
auto r = module->paramQuantities[Delay::TIME_R]->getDisplayValueString();
if (ll != l || lr != r)
bdw->dirty = true;
ll = l;
lr = r;
}
rack::widget::TransparentWidget::step();
}
void drawDelays(NVGcontext *vg)
{
nvgBeginPath(vg);
nvgStrokeColor(vg, style()->getColor(style::XTStyle::PLOT_MARKS));
nvgMoveTo(vg, box.size.x * 0.5, rack::mm2px(widgets::LCDBackground::padY_MM));
nvgLineTo(vg, box.size.x * 0.5, box.size.y - rack::mm2px(widgets::LCDBackground::padY_MM));
nvgStrokeWidth(vg, 1);
nvgStroke(vg);
nvgBeginPath(vg);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgFontFaceId(vg, style()->fontIdBold(vg));
nvgFontSize(vg, layout::LayoutConstants::labelSize_pt * 96 / 72);
nvgFillColor(vg, style()->getColor(style::XTStyle::PLOT_CURVE));
nvgText(vg, 0, box.size.y * 0.5, ll.c_str(), nullptr);
nvgBeginPath(vg);
nvgTextAlign(vg, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE);
nvgFontFaceId(vg, style()->fontIdBold(vg));
nvgFontSize(vg, layout::LayoutConstants::labelSize_pt * 96 / 72);
nvgFillColor(vg, style()->getColor(style::XTStyle::PLOT_CURVE));
nvgText(vg, box.size.x, box.size.y * 0.5, lr.c_str(), nullptr);
}
void onStyleChanged() override { bdw->dirty = true; }
};
DelayWidget::DelayWidget(DelayWidget::M *module) : XTModuleWidget()
{
setModule(module);
typedef layout::LayoutEngine<DelayWidget, M::TIME_L, M::INPUT_CLOCK> engine_t;
engine_t::initializeModulationToBlank(this);
box.size = rack::Vec(rack::app::RACK_GRID_WIDTH * layout::LayoutConstants::numberOfScrews,
rack::app::RACK_GRID_HEIGHT);
auto bg = new widgets::Background(box.size, "DELAY", "fx", "BlankNoDisplay");
addChild(bg);
auto col = std::vector<float>();
for (int i = 0; i < 4; ++i)
col.push_back(layout::LayoutConstants::firstColumnCenter_MM +
layout::LayoutConstants::columnWidth_MM * i);
const auto row1 = layout::LayoutConstants::rowStart_MM;
const auto row2 = row1 - layout::LayoutConstants::labeledGap_MM;
const auto row2S = row2 - layout::LayoutConstants::labeledGap_MM - 2;
const auto endOfPanel = row2S - 6;
typedef layout::LayoutItem li_t;
// fixme use the enums
// clang-format off
std::vector<li_t> layout = {
{li_t::KNOB14, "LEFT", M::TIME_L, layout::LayoutConstants::bigCol0-3, row2S - 2.5f},
{li_t::KNOB14, "RIGHT", M::TIME_R, layout::LayoutConstants::bigCol1+3, row2S - 2.5f},
{li_t::KNOB9, "FINE", M::TIME_S, (col[2]+col[1]) * 0.5f, row2S},
{li_t::KNOB9, "DEPTH", M::FEEDBACK, col[0], row2},
{li_t::KNOB9, "CROSS", M::CROSSFEED, col[1], row2},
li_t::createGrouplabel("FEEDBACK", col[0], row2, 2),
{li_t::KNOB9, "LO", M::LOCUT, col[2], row2},
{li_t::KNOB9, "HI", M::HICUT, col[3], row2},
li_t::createGrouplabel("EQ", col[2], row2, 2),
{li_t::PORT, "CLOCK", M::INPUT_CLOCK, col[0], row1},
{li_t::KNOB9, "RATE", M::MODRATE, col[1], row1},
{li_t::KNOB9, "DEPTH", M::MODDEPTH, col[2], row1},
li_t::createGrouplabel("MOD", col[1], row1, 2),
{li_t::KNOB9, "MIX", M::MIX, col[3], row1},
li_t::createPresetLCDArea(),
};
// clang-format on
for (const auto &lay : layout)
{
engine_t::layoutItem(this, lay, "Delay");
}
auto t = TimeDisplay::create(module);
addChild(t);
engine_t::addModulationSection(this, M::n_mod_inputs, M::DELAY_MOD_INPUT);
engine_t::createLeftRightInputLabels(this);
engine_t::createInputOutputPorts(this, M::INPUT_L, M::INPUT_R, M::OUTPUT_L, M::OUTPUT_R);
resetStyleCouplingToModule();
}
} // namespace sst::surgext_rack::delay::ui
// namespace sst::surgext_rack::vcf::ui
rack::Model *modelSurgeDelay =
rack::createModel<sst::surgext_rack::delay::ui::DelayWidget::M,
sst::surgext_rack::delay::ui::DelayWidget>("SurgeXTDelay");