From 7acb080b92af090b1ab7d1636d3c2f0946c112b2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 7 May 2024 10:19:34 -0400 Subject: [PATCH] When duplicating module with cables, duplicate cables connected to outputs as well as inputs. --- src/app/ModuleWidget.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 7caf318e..86e65c2c 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -860,19 +860,30 @@ void ModuleWidget::cloneAction(bool cloneCables) { h->push(hma); if (cloneCables) { - // Clone cables attached to input ports - for (PortWidget* pw : getInputs()) { + // Clone cables attached to input/output ports + for (PortWidget* pw : getPorts()) { for (CableWidget* cw : APP->scene->rack->getCompleteCablesOnPort(pw)) { + // Skip input ports self-patched to this module's outputs, to avoid double-cloning them. + if (pw->type == engine::Port::OUTPUT && cw->cable->inputModule == module) + continue; + // Create cable attached to cloned ModuleWidget's input engine::Cable* clonedCable = new engine::Cable; - clonedCable->inputModule = clonedModule; + clonedCable->inputModule = cw->cable->inputModule; clonedCable->inputId = cw->cable->inputId; - // If cable is self-patched, attach to cloned module instead - if (cw->cable->outputModule == module) - clonedCable->outputModule = clonedModule; - else - clonedCable->outputModule = cw->cable->outputModule; + clonedCable->outputModule = cw->cable->outputModule; clonedCable->outputId = cw->cable->outputId; + + if (pw->type == engine::Port::INPUT) { + clonedCable->inputModule = clonedModule; + // If cable is self-patched, attach to cloned module instead + if (cw->cable->outputModule == module) + clonedCable->outputModule = clonedModule; + } + else { + clonedCable->outputModule = clonedModule; + } + APP->engine->addCable(clonedCable); app::CableWidget* clonedCw = new app::CableWidget;