Browse Source

Use menu item helpers for Streams.

pull/114/head
Andrew Belt 3 years ago
parent
commit
698b8eb0b0
3 changed files with 56 additions and 91 deletions
  1. +10
    -17
      src/Branches.cpp
  2. +14
    -14
      src/Marbles.cpp
  3. +32
    -60
      src/Streams.cpp

+ 10
- 17
src/Branches.cpp View File

@@ -158,26 +158,19 @@ struct BranchesWidget : ModuleWidget {
} }


void appendContextMenu(Menu* menu) override { void appendContextMenu(Menu* menu) override {
Branches* branches = dynamic_cast<Branches*>(module);
assert(branches);

struct BranchesModeItem : MenuItem {
Branches* branches;
int i;
void onAction(const event::Action& e) override {
branches->modes[i] ^= 1;
}
void step() override {
rightText = branches->modes[i] ? "Latch" : "Toggle";
MenuItem::step();
}
};
Branches* module = dynamic_cast<Branches*>(this->module);


menu->addChild(new MenuSeparator); menu->addChild(new MenuSeparator);


menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Channels"));
menu->addChild(construct<BranchesModeItem>(&MenuItem::text, "Channel 1 mode", &BranchesModeItem::branches, branches, &BranchesModeItem::i, 0));
menu->addChild(construct<BranchesModeItem>(&MenuItem::text, "Channel 2 mode", &BranchesModeItem::branches, branches, &BranchesModeItem::i, 1));
menu->addChild(createIndexPtrSubmenuItem("Channel 1 mode", {
"Latch",
"Toggle",
}, &module->modes[0]));

menu->addChild(createIndexPtrSubmenuItem("Channel 2 mode", {
"Latch",
"Toggle",
}, &module->modes[1]));
} }
}; };




+ 14
- 14
src/Marbles.cpp View File

@@ -591,7 +591,7 @@ struct MarblesWidget : ModuleWidget {


menu->addChild(new MenuSeparator); menu->addChild(new MenuSeparator);


menu->addChild(createIndexMenuItem(&module->t_mode, "t mode", {
menu->addChild(createIndexPtrSubmenuItem("t mode", {
"Complementary Bernoulli", "Complementary Bernoulli",
"Clusters", "Clusters",
"Drums", "Drums",
@@ -599,43 +599,43 @@ struct MarblesWidget : ModuleWidget {
"Divider", "Divider",
"Three states", "Three states",
"Markov", "Markov",
}));
}, &module->t_mode));


menu->addChild(createIndexMenuItem(&module->t_range, "t range", {
menu->addChild(createIndexPtrSubmenuItem("t range", {
"1/4x", "1/4x",
"1x", "1x",
"4x", "4x",
}));
}, &module->t_range));


menu->addChild(createIndexMenuItem(&module->x_mode, "X mode", {
menu->addChild(createIndexPtrSubmenuItem("X mode", {
"Identical", "Identical",
"Bump", "Bump",
"Tilt", "Tilt",
}));
}, &module->x_mode));


menu->addChild(createIndexMenuItem(&module->x_range, "X range", {
menu->addChild(createIndexPtrSubmenuItem("X range", {
"Narrow", "Narrow",
"Positive", "Positive",
"Full", "Full",
}));
}, &module->x_range));


menu->addChild(createIndexMenuItem(&module->x_scale, "Scales", {
menu->addChild(createIndexPtrSubmenuItem("Scales", {
"Major", "Major",
"Minor", "Minor",
"Pentatonic", "Pentatonic",
"Pelog", "Pelog",
"Raag Bhairav That", "Raag Bhairav That",
"Raag Shri", "Raag Shri",
}));
}, &module->x_scale));


menu->addChild(createIndexMenuItem(&module->x_clock_source_internal, "Internal X clock source", {
menu->addChild(createIndexPtrSubmenuItem("Internal X clock source", {
"T₁ → X₁, T₂ → X₂, T₃ → X₃", "T₁ → X₁, T₂ → X₂, T₃ → X₃",
"T₁ → X₁, X₂, X₃", "T₁ → X₁, X₂, X₃",
"T₂ → X₁, X₂, X₃", "T₂ → X₁, X₂, X₃",
"T₃ → X₁, X₂, X₃", "T₃ → X₁, X₂, X₃",
}));
}, &module->x_clock_source_internal));


menu->addChild(createIndexMenuItem(&module->y_divider_index, "Y divider ratio", {
menu->addChild(createIndexPtrSubmenuItem("Y divider ratio", {
"1/64", "1/64",
"1/48", "1/48",
"1/32", "1/32",
@@ -648,7 +648,7 @@ struct MarblesWidget : ModuleWidget {
"1/3", "1/3",
"1/2", "1/2",
"1", "1",
}));
}, &module->y_divider_index));
} }
}; };




+ 32
- 60
src/Streams.cpp View File

@@ -193,15 +193,26 @@ struct Streams : Module {
} }
} }


void toggleLink() {
void setLinked(bool linked) {
streams::UiSettings settings = engines[0].ui_settings(); streams::UiSettings settings = engines[0].ui_settings();
settings.linked ^= 1;
settings.linked = linked;


for (int c = 0; c < PORT_MAX_CHANNELS; c++) { for (int c = 0; c < PORT_MAX_CHANNELS; c++) {
engines[c].ApplySettings(settings); engines[c].ApplySettings(settings);
} }
} }


int getChannelMode(int channel) {
streams::UiSettings settings = engines[0].ui_settings();
// Search channel mode index in table
for (int i = 0; i < streams::kNumChannelModes; i++) {
if (settings.function[channel] == streams::kChannelModeTable[i].function
&& settings.alternate[channel] == streams::kChannelModeTable[i].alternate)
return i;
}
return -1;
}

void setChannelMode(int channel, int mode_id) { void setChannelMode(int channel, int mode_id) {
streams::UiSettings settings = engines[0].ui_settings(); streams::UiSettings settings = engines[0].ui_settings();
settings.function[channel] = streams::kChannelModeTable[mode_id].function; settings.function[channel] = streams::kChannelModeTable[mode_id].function;
@@ -326,6 +337,7 @@ struct Streams : Module {
} }
}; };



struct StreamsWidget : ModuleWidget { struct StreamsWidget : ModuleWidget {
StreamsWidget(Streams* module) { StreamsWidget(Streams* module) {
setModule(module); setModule(module);
@@ -373,72 +385,32 @@ struct StreamsWidget : ModuleWidget {
void appendContextMenu(Menu* menu) override { void appendContextMenu(Menu* menu) override {
Streams* module = dynamic_cast<Streams*>(this->module); Streams* module = dynamic_cast<Streams*>(this->module);


struct LinkItem : MenuItem {
Streams* module;
void onAction(const event::Action& e) override {
module->toggleLink();
}
};

struct ChannelModeItem : MenuItem {
Streams* module;
int channel;
int mode;
void onAction(const event::Action& e) override {
module->setChannelMode(channel, mode);
}
};

struct MonitorModeItem : MenuItem {
Streams* module;
int mode;
void onAction(const event::Action& e) override {
module->setMonitorMode(mode);
}
};

menu->addChild(new MenuSeparator); menu->addChild(new MenuSeparator);
LinkItem* linkItem = createMenuItem<LinkItem>(
"Link channels", CHECKMARK(module->linked()));
linkItem->module = module;
menu->addChild(linkItem);


menu->addChild(new MenuSeparator);
menu->addChild(createMenuLabel("Channel 1"));
for (int i = 0; i < streams::kNumChannelModes; i++) {
auto modeItem = createMenuItem<ChannelModeItem>(
streams::kChannelModeTable[i].label, CHECKMARK(
module->function(0) == streams::kChannelModeTable[i].function &&
module->alternate(0) == streams::kChannelModeTable[i].alternate));
modeItem->module = module;
modeItem->channel = 0;
modeItem->mode = i;
menu->addChild(modeItem);
}
menu->addChild(createBoolMenuItem("Link channels",
[=]() {return module->linked();},
[=](bool val) {module->setLinked(val);}
));


menu->addChild(new MenuSeparator);
menu->addChild(createMenuLabel("Channel 2"));
std::vector<std::string> modeLabels;
for (int i = 0; i < streams::kNumChannelModes; i++) { for (int i = 0; i < streams::kNumChannelModes; i++) {
auto modeItem = createMenuItem<ChannelModeItem>(
streams::kChannelModeTable[i].label, CHECKMARK(
module->function(1) == streams::kChannelModeTable[i].function &&
module->alternate(1) == streams::kChannelModeTable[i].alternate));
modeItem->module = module;
modeItem->channel = 1;
modeItem->mode = i;
menu->addChild(modeItem);
modeLabels.push_back(streams::kChannelModeTable[i].label);
}
for (int c = 0; c < 2; c++) {
menu->addChild(createIndexSubmenuItem(string::f("Channel %d mode", c + 1), modeLabels,
[=]() {return module->getChannelMode(c);},
[=](int index) {module->setChannelMode(c, index);}
));
} }


menu->addChild(new MenuSeparator);
menu->addChild(createMenuLabel("Meter"));
std::vector<std::string> meterLabels;
for (int i = 0; i < streams::kNumMonitorModes; i++) { for (int i = 0; i < streams::kNumMonitorModes; i++) {
auto modeItem = createMenuItem<MonitorModeItem>(
streams::kMonitorModeTable[i].label, CHECKMARK(
module->monitorMode() == streams::kMonitorModeTable[i].mode));
modeItem->module = module;
modeItem->mode = i;
menu->addChild(modeItem);
meterLabels.push_back(streams::kMonitorModeTable[i].label);
} }
menu->addChild(createIndexSubmenuItem("Meter", meterLabels,
[=]() {return module->monitorMode();},
[=](int index) {module->setMonitorMode(index);}
));
} }
}; };




Loading…
Cancel
Save