Skip to content

Commit 47a33ba

Browse files
committed
Interpret rack::app::Switch widgets as momentary button, flip switch (for latching button), or slide switch (for >2 positions)
1 parent eb187c6 commit 47a33ba

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

firmware/vcv_plugin/internal/make_element.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,35 @@ static FlipSwitch make_flipswitch(rack::app::SvgSwitch *widget) {
393393
return element;
394394
}
395395

396+
Element make_element(rack::app::Switch *widget) {
397+
auto pq = widget->getParamQuantity();
398+
399+
if (widget->momentary) {
400+
log_make_element("rack::app::Switch momentary button", widget->paramId);
401+
return MomentaryButton{};
402+
403+
} else if (!pq || (pq->minValue == 0 && pq->maxValue == 1)) {
404+
log_make_element("rack::app::Switch latching button", widget->paramId);
405+
FlipSwitch element{};
406+
element.num_pos = 2;
407+
element.default_value = 0;
408+
if (pq && pq->labels.size() >= 1)
409+
element.pos_names[0] = pq->labels[0];
410+
if (pq && pq->labels.size() >= 2)
411+
element.pos_names[1] = pq->labels[1];
412+
return element;
413+
} else {
414+
// TODO: find examples of plugins using app::Switch for flip or slide switches and
415+
// determine the best way to handle these cases.
416+
// For now, we use Slide Switches since they can be drawn without SVGs.
417+
log_make_element("rack::app::Switch slide", widget->paramId);
418+
SlideSwitch element{};
419+
element.num_pos = std::clamp<unsigned>(pq->maxValue - pq->minValue + 1, 2, element.pos_names.size());
420+
element.default_value = getDefaultValue(widget);
421+
return element;
422+
}
423+
}
424+
396425
Element make_element(rack::app::SvgSwitch *widget) {
397426

398427
bool momentary = widget->momentary;

firmware/vcv_plugin/internal/make_element.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Element make_element(rack::app::SvgSlider *widget);
1818

1919
// Switches
2020
Element make_element(rack::app::SvgSwitch *widget);
21+
Element make_element(rack::app::Switch *widget);
2122

2223
// Lights:
2324
Element make_element(rack::app::MultiLightWidget *widget);

0 commit comments

Comments
 (0)