From 7042795c8138f03124539f0efc892fe45eb2979f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 20 Apr 2011 01:36:34 +0000 Subject: Factor out duplicated code. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3178 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/events/DisconnectAll.cpp | 34 +++++++++++++++++++--------------- src/engine/events/DisconnectAll.hpp | 2 ++ 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src/engine/events') diff --git a/src/engine/events/DisconnectAll.cpp b/src/engine/events/DisconnectAll.cpp index cc5bf42d..c49cd9d7 100644 --- a/src/engine/events/DisconnectAll.cpp +++ b/src/engine/events/DisconnectAll.cpp @@ -73,6 +73,17 @@ DisconnectAll::~DisconnectAll() delete (*i); } +void +DisconnectAll::remove_connection(ConnectionImpl* c) +{ + const bool reconnect_input = !_deleting || (c->dst_port()->parent_node() != _node); + Disconnect* ev = new Disconnect(_engine, SharedPtr(), _time, + c->src_port(), c->dst_port(), reconnect_input); + ev->pre_process(); + _disconnect_events.push_back(new Raul::List::Node(ev)); + c->pending_disconnection(true); +} + void DisconnectAll::pre_process() { @@ -110,27 +121,20 @@ DisconnectAll::pre_process() for (PatchImpl::Connections::const_iterator i = _parent->connections().begin(); i != _parent->connections().end(); ++i) { ConnectionImpl* c = (ConnectionImpl*)i->second.get(); - const bool reconnect_input = !_deleting || (c->dst_port()->parent_node() != _node); - if ((c->src_port()->parent_node() == _node || c->dst_port()->parent_node() == _node) - && !c->pending_disconnection()) { - Disconnect* ev = new Disconnect(_engine, - SharedPtr(), _time, c->src_port(), c->dst_port(), reconnect_input); - ev->pre_process(); - _disconnect_events.push_back(new Raul::List::Node(ev)); - c->pending_disconnection(true); + if (!c->pending_disconnection() + && (c->src_port()->parent_node() == _node + || c->dst_port()->parent_node() == _node)) { + remove_connection(c); } } } else { // _port for (PatchImpl::Connections::const_iterator i = _parent->connections().begin(); i != _parent->connections().end(); ++i) { ConnectionImpl* c = (ConnectionImpl*)i->second.get(); - const bool reconnect_input = !_deleting || (c->dst_port()->parent_node() != _node); - if ((c->src_port() == _port || c->dst_port() == _port) && !c->pending_disconnection()) { - Disconnect* ev = new Disconnect(_engine, - SharedPtr(), _time, c->src_port(), c->dst_port(), reconnect_input); - ev->pre_process(); - _disconnect_events.push_back(new Raul::List::Node(ev)); - c->pending_disconnection(true); + if (!c->pending_disconnection() + && (c->src_port() == _port + || c->dst_port() == _port)) { + remove_connection(c); } } } diff --git a/src/engine/events/DisconnectAll.hpp b/src/engine/events/DisconnectAll.hpp index 0d89901d..ee8fbade 100644 --- a/src/engine/events/DisconnectAll.hpp +++ b/src/engine/events/DisconnectAll.hpp @@ -67,6 +67,8 @@ private: OBJECT_NOT_FOUND, }; + void remove_connection(ConnectionImpl* c); + Raul::Path _parent_path; Raul::Path _path; PatchImpl* _parent; -- cgit v1.2.1