Skip to content

Commit

Permalink
Merge pull request #28 from 4ms/bypass
Browse files Browse the repository at this point in the history
Add Bypass for FX modules
  • Loading branch information
danngreen authored Sep 16, 2024
2 parents ec7ba7a + 89d928a commit 1e4e75b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
31 changes: 18 additions & 13 deletions src/generic_module.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,32 @@
#include "widgets/vcv_module_creator.hh"
#include "widgets/vcv_widget_creator.hh"

template<Derived<MetaModule::ModuleInfoBase> INFO>
template<Derived<MetaModule::ModuleInfoBase> Info>
struct GenericModule {
static rack::Model *create() {
return rack::createModel<Module, Widget>(INFO::slug.data());
return rack::createModel<Module, Widget>(Info::slug.data());
}

struct Module : CommModule {
Module() {
// Create processing core
core = MetaModule::ModuleFactory::create(INFO::slug);
core = MetaModule::ModuleFactory::create(Info::slug);

// Register with VCV the number of elements of each type
auto cnt = ElementCount::count<INFO>();
auto cnt = ElementCount::count<Info>();
configComm(cnt.num_params, cnt.num_inputs, cnt.num_outputs, cnt.num_lights);

// Configure elements with VCV
// this includes alt parameters
MetaModule::VCVModuleParamCreator<INFO> creator{this};
for (auto &element : INFO::Elements) {
MetaModule::VCVModuleParamCreator<Info> creator{this};
for (auto &element : Info::Elements) {
std::visit([&creator](auto &el) { creator.config_element(el); }, element);
}

// Bypass Routes
for (auto route : Info::bypass_routes) {
configBypass(route.input, route.output);
}
}
};

Expand All @@ -41,7 +46,7 @@ struct GenericModule {
setModule(static_cast<Module *>(module));

// use svg file as panel
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, INFO::svg_filename.data())));
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, Info::svg_filename.data())));

// draw screws
addChild(createWidget<ScrewBlack>(rack::math::Vec(RACK_GRID_WIDTH, 0)));
Expand All @@ -54,35 +59,35 @@ struct GenericModule {
}

// create widgets from all elements
MetaModule::VCVWidgetCreator<INFO> creator(this, module);
for (auto &element : INFO::Elements) {
MetaModule::VCVWidgetCreator<Info> creator(this, module);
for (auto &element : Info::Elements) {
std::visit([&creator](auto &el) { creator.create(el); }, element);
}
}

// custom menu item that draws a child menu populated with entries
// defined by the alt parameter elements of the module
struct AltParamMenuTop : rack::ui::MenuItem {
AltParamMenuTop(MetaModule::VCVWidgetCreator<INFO> creator_)
AltParamMenuTop(MetaModule::VCVWidgetCreator<Info> creator_)
: creator(creator_) {
}

rack::ui::Menu *createChildMenu() override {
auto childMenu = new rack::ui::Menu;

// let each element render itself to the menu
for (auto &element : INFO::Elements) {
for (auto &element : Info::Elements) {
std::visit([&childMenu, this](auto &el) { creator.renderToContextMenu(el, childMenu); }, element);
}
return childMenu;
}

private:
MetaModule::VCVWidgetCreator<INFO> creator;
MetaModule::VCVWidgetCreator<Info> creator;
};

void appendContextMenu(rack::ui::Menu *menu) override {
MetaModule::VCVWidgetCreator<INFO> creator(this, module);
MetaModule::VCVWidgetCreator<Info> creator(this, module);

// add single entry with submenu
// we need to forward the creator so the entry itself is able to create further menu items
Expand Down

0 comments on commit 1e4e75b

Please sign in to comment.