Skip to content

Commit 065d0cb

Browse files
committed
add devkits and simple touch; use SectionedComboBox
1 parent 41a7051 commit 065d0cb

1 file changed

Lines changed: 90 additions & 4 deletions

File tree

‎Source/Heavy/DaisyExporter.h‎

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,89 @@
55
*/
66
#pragma once
77

8+
class SectionedComboComponent : public PropertiesPanelProperty {
9+
public:
10+
SectionedComboComponent(String const& name, Value const& targetValue,
11+
std::vector<std::pair<String, StringArray>> sections, StringArray extra)
12+
: PropertiesPanelProperty(name)
13+
{
14+
// 1. Populate the combo itself with the flat list, ids 1..N.
15+
// This gives the closed combo its selected-item text and keeps
16+
// the id == flat index convention intact.
17+
int id = 1;
18+
for (auto& [title, items] : sections)
19+
for (auto& item : items)
20+
comboBox.addItem(item, id++);
21+
for (auto& item : extra)
22+
comboBox.addItem(item, id++);
23+
24+
comboBox.getProperties().set("Style", "Inspector");
25+
comboBox.getSelectedIdAsValue().referTo(targetValue);
26+
27+
// sections/extra live on the inner combo for showPopup()
28+
comboBox.sections = std::move(sections);
29+
comboBox.extra = std::move(extra);
30+
31+
addAndMakeVisible(comboBox);
32+
}
33+
34+
PropertiesPanelProperty* createCopy() override
35+
{
36+
return new SectionedComboComponent(getName(), comboBox.getSelectedIdAsValue(),
37+
comboBox.sections, comboBox.extra);
38+
}
39+
40+
void resized() override
41+
{
42+
comboBox.setBounds(getLocalBounds().removeFromRight(getWidth() / (2 - hideLabel)));
43+
}
44+
45+
private:
46+
class SectionedComboBox : public ComboBox {
47+
public:
48+
std::vector<std::pair<String, StringArray>> sections;
49+
StringArray extra;
50+
51+
void mouseDown(MouseEvent const& e) override
52+
{
53+
showMenu();
54+
}
55+
56+
private:
57+
void showMenu()
58+
{
59+
PopupMenu menu;
60+
int id = 1;
61+
for (auto& [title, items] : sections) {
62+
PopupMenu sub;
63+
for (auto& item : items)
64+
sub.addItem(id++, item);
65+
menu.addSubMenu(title, sub);
66+
}
67+
if (extra.size()) {
68+
menu.addSeparator();
69+
for (auto& item : extra)
70+
menu.addItem(id++, item);
71+
}
72+
73+
menu.showMenuAsync(
74+
PopupMenu::Options()
75+
.withTargetComponent(this)
76+
.withItemThatMustBeVisible(getSelectedId())
77+
.withInitiallySelectedItem(getSelectedId())
78+
.withMinimumWidth(getWidth())
79+
.withMaximumNumColumns(1)
80+
.withStandardItemHeight(24),
81+
ModalCallbackFunction::create([this](int result) {
82+
if (result != 0)
83+
setSelectedId(result, sendNotificationSync);
84+
}));
85+
}
86+
};
87+
88+
SectionedComboBox comboBox;
89+
};
90+
891
class DaisyExporter final : public ExporterBase {
992
public:
1093
Value targetBoardValue = SynchronousValue(var(1));
@@ -27,7 +110,10 @@ class DaisyExporter final : public ExporterBase {
27110
exportTypeValue = var(3);
28111

29112
PropertiesArray properties;
30-
properties.add(new PropertiesPanel::ComboComponent("Target board", targetBoardValue, { "Pod", "Petal", "Patch", "Patch.Init()", "Field", "Versio", "Terrarium", "Hothouse", "Simple", "Custom JSON..." }));
113+
properties.add(new SectionedComboComponent("Target board", targetBoardValue,
114+
{ { "Official", { "Pod", "Petal", "Patch", "Patch.Init()", "Field", "Desktop Devkit", "Eurorack Devkit", "Pedal Devkit" } },
115+
{ "Community", { "Versio", "Terrarium", "Hothouse", "Simple Touch" } } },
116+
{ "Custom JSON..." }));
31117
properties.add(new PropertiesPanel::ComboComponent("Export type", exportTypeValue, getExportTypes()));
32118
usbMidiProperty = new PropertiesPanel::BoolComponent("USB MIDI", usbMidiValue, { "No", "Yes" });
33119
properties.add(usbMidiProperty);
@@ -135,7 +221,7 @@ class DaisyExporter final : public ExporterBase {
135221
int const idx = getValue<int>(targetBoardValue);
136222

137223
// Custom board option
138-
if (idx == 10 && !blockDialog) {
224+
if (idx == 13 && !blockDialog) {
139225
Dialogs::showOpenDialog([this](URL const& url) {
140226
auto const result = url.getLocalFile();
141227
if (result.existsAsFile()) {
@@ -217,10 +303,10 @@ class DaisyExporter final : public ExporterBase {
217303
}
218304

219305
// set board definition
220-
auto boards = StringArray { "pod", "petal", "patch", "patch_init", "field", "versio", "terrarium", "hothouse", "simple", "custom" };
306+
auto boards = StringArray { "pod", "petal", "patch", "patch_init", "field", "desktop_devkit", "eurorack_devkit", "pedal_devkit", "versio", "terrarium", "hothouse", "simple_touch", "custom" };
221307
auto const& board = boards[target];
222308

223-
auto extra_boards = StringArray { "versio", "terrarium", "hothouse", "simple" };
309+
auto extra_boards = StringArray { "versio", "terrarium", "hothouse", "simple_touch" };
224310

225311
DynamicObject::Ptr metaJson(new DynamicObject());
226312
var metaDaisy(new DynamicObject());

0 commit comments

Comments
 (0)