From cbce51744c79f823108d86f3c6f2e08609a0434b Mon Sep 17 00:00:00 2001 From: zetaPRIME Date: Tue, 22 Mar 2022 17:49:01 -0400 Subject: [PATCH] easy splice-between for single-input node types --- notes | 3 +-- xybrid/ui/patchboard/nodeobject.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/notes b/notes index 239b111..e1037cf 100644 --- a/notes +++ b/notes @@ -37,8 +37,7 @@ TODO { revert-to-saved menu action - - ringmod (easy!) - splice-between behavior when trying to hook up a command input to something with both a command input and output while already connected + - splice-between behavior when trying to hook up a command input to something with both a command input and output while already connected distortion effect diff --git a/xybrid/ui/patchboard/nodeobject.cpp b/xybrid/ui/patchboard/nodeobject.cpp index 86d62c1..e67e300 100644 --- a/xybrid/ui/patchboard/nodeobject.cpp +++ b/xybrid/ui/patchboard/nodeobject.cpp @@ -48,6 +48,20 @@ void PortObject::connectTo(PortObject* o) { if (port->type == Port::Input) { in = this; out = o; } else { out = this; in = o; } + // splice-between logic + auto dt = port->dataType(); + if (in->port->type == Port::Input && in->port->singleInput() && in->port->isConnected() && out->port->dataType() == dt) { + if (auto oi = out->port->owner.lock()->port(Port::Input, dt, 0); oi) { + auto c = in->port->connections[0].lock(); + if (!oi->isConnected() || oi->connections[0].lock() == in->port->connections[0].lock()) { + if (auto pc = in->connections[c->obj]; pc) delete pc; + in->port->disconnect(c); + + if (!oi->isConnected() && oi->connect(c)) new PortConnectionObject(oi->obj, c->obj); + } + } + } + if (out->port->connect(in->port)) { /*auto* pc =*/ new PortConnectionObject(in, out); }