From 99c96c1e05cfa43be667aae4fbbff76a4f8b70ef Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 4 Aug 2021 02:21:10 -0400 Subject: [PATCH] Implement RackWidget::bypassSelectedModulesAction() so bypassing the module selection works. --- include/app/RackWidget.hpp | 3 ++- src/app/ModuleWidget.cpp | 17 ++++++++++++----- src/app/RackWidget.cpp | 32 ++++++++++++++++++++++++++++++-- src/engine/Engine.cpp | 5 +++-- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index b866ff90..159fd8eb 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -76,7 +76,8 @@ struct RackWidget : widget::OpaqueWidget { void resetSelectedModulesAction(); void randomizeSelectedModulesAction(); void disconnectSelectedModulesAction(); - void bypassSelectedModulesAction(); + void bypassSelectedModulesAction(bool bypassed); + bool areSelectedModulesBypassed(); void deleteSelectedModulesAction(); bool requestSelectedModulePos(math::Vec delta); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 61b953b5..e4e3d994 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -802,13 +802,15 @@ void ModuleWidget::cloneAction() { void ModuleWidget::bypassAction() { assert(module); - APP->engine->bypassModule(module, !module->isBypassed()); + bool bypassed = !module->isBypassed(); // history::ModuleBypass history::ModuleBypass* h = new history::ModuleBypass; h->moduleId = module->id; - h->bypassed = module->isBypassed(); + h->bypassed = bypassed; APP->history->push(h); + + APP->engine->bypassModule(module, bypassed); } void ModuleWidget::removeAction() { @@ -1085,9 +1087,14 @@ void ModuleWidget::createSelectionContextMenu() { })); // Bypass - menu->addChild(createMenuItem("Bypass", "", [=]() { - APP->scene->rack->bypassSelectedModulesAction(); - })); + menu->addChild(createBoolMenuItem("Bypass", + [=]() { + return APP->scene->rack->areSelectedModulesBypassed(); + }, + [=](bool bypassed) { + APP->scene->rack->bypassSelectedModulesAction(bypassed); + } + )); // Delete menu->addChild(createMenuItem("Delete", "", [=]() { diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index a0f14c7b..af37fcde 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -731,8 +731,36 @@ void RackWidget::disconnectSelectedModulesAction() { delete complexAction; } -void RackWidget::bypassSelectedModulesAction() { - // TODO +void RackWidget::bypassSelectedModulesAction(bool bypassed) { + history::ComplexAction* complexAction = new history::ComplexAction; + complexAction->name = "bypass modules"; + + for (ModuleWidget* mw : getSelectedModules()) { + assert(mw->module); + if (mw->module->isBypassed() == bypassed) + continue; + + // history::ModuleBypass + history::ModuleBypass* h = new history::ModuleBypass; + h->moduleId = mw->module->id; + h->bypassed = bypassed; + complexAction->push(h); + + APP->engine->bypassModule(mw->module, bypassed); + } + + if (!complexAction->isEmpty()) + APP->history->push(complexAction); + else + delete complexAction; +} + +bool RackWidget::areSelectedModulesBypassed() { + for (ModuleWidget* mw : getSelectedModules()) { + if (!mw->getModule()->isBypassed()) + return false; + } + return true; } void RackWidget::deleteSelectedModulesAction() { diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index eef042e8..b24c3a72 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -863,11 +863,12 @@ void Engine::randomizeModule(Module* module) { void Engine::bypassModule(Module* module, bool bypassed) { - WriteLock lock(internal->mutex); assert(module); - if (module->isBypassed() == bypassed) return; + + WriteLock lock(internal->mutex); + // Clear outputs and set to 1 channel for (Output& output : module->outputs) { // This zeros all voltages, but the channel is set to 1 if connected