diff options
author | David Robillard <d@drobilla.net> | 2021-04-01 16:38:12 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-04-01 16:38:12 -0400 |
commit | 7fcd07e25150bf5dbcded3334aff5c845926391e (patch) | |
tree | 71205dd2b4d83992d5fd5ae84fe09fdc2d1e9aa6 | |
parent | 0e4a1979afb7258e48da941caffedf7034176bd0 (diff) | |
download | ingen-7fcd07e25150bf5dbcded3334aff5c845926391e.tar.gz ingen-7fcd07e25150bf5dbcded3334aff5c845926391e.tar.bz2 ingen-7fcd07e25150bf5dbcded3334aff5c845926391e.zip |
Factor out finding adjacent arcs for disconnection
-rw-r--r-- | src/server/events/DisconnectAll.cpp | 50 | ||||
-rw-r--r-- | src/server/events/DisconnectAll.hpp | 4 |
2 files changed, 32 insertions, 22 deletions
diff --git a/src/server/events/DisconnectAll.cpp b/src/server/events/DisconnectAll.cpp index 86a38d7b..0442ddd9 100644 --- a/src/server/events/DisconnectAll.cpp +++ b/src/server/events/DisconnectAll.cpp @@ -113,28 +113,13 @@ DisconnectAll::pre_process(PreProcessContext& ctx) } } - // Find set of arcs to remove - std::set<ArcImpl*> to_remove; - for (const auto& a : _parent->arcs()) { - auto* const arc = static_cast<ArcImpl*>(a.second.get()); - if (_block) { - if (arc->tail()->parent_block() == _block - || arc->head()->parent_block() == _block) { - to_remove.insert(arc); - } - } else if (_port) { - if (arc->tail() == _port || arc->head() == _port) { - to_remove.insert(arc); - } - } - } - - // Create disconnect events (which erases from _parent->arcs()) - for (const auto& a : to_remove) { - _impls.push_back(new Disconnect::Impl( - _engine, _parent, - dynamic_cast<PortImpl*>(a->tail()), - dynamic_cast<InputPort*>(a->head()))); + // Create disconnect events to erase adjacent arcs in parent + for (const auto& a : adjacent_arcs(_parent)) { + _impls.push_back( + new Disconnect::Impl(_engine, + _parent, + dynamic_cast<PortImpl*>(a->tail()), + dynamic_cast<InputPort*>(a->head()))); } if (!_deleting && ctx.must_compile(*_parent)) { @@ -178,6 +163,27 @@ DisconnectAll::undo(Interface& target) } } +std::set<ArcImpl*> +DisconnectAll::adjacent_arcs(GraphImpl* const graph) +{ + std::set<ArcImpl*> arcs; + for (const auto& a : graph->arcs()) { + auto* const arc = static_cast<ArcImpl*>(a.second.get()); + if (_block) { + if (arc->tail()->parent_block() == _block + || arc->head()->parent_block() == _block) { + arcs.insert(arc); + } + } else if (_port) { + if (arc->tail() == _port || arc->head() == _port) { + arcs.insert(arc); + } + } + } + + return arcs; +} + } // namespace events } // namespace server } // namespace ingen diff --git a/src/server/events/DisconnectAll.hpp b/src/server/events/DisconnectAll.hpp index a527dc34..70da5dd6 100644 --- a/src/server/events/DisconnectAll.hpp +++ b/src/server/events/DisconnectAll.hpp @@ -26,6 +26,7 @@ #include <list> #include <memory> +#include <set> namespace ingen { @@ -34,6 +35,7 @@ class Node; namespace server { +class ArcImpl; class BlockImpl; class CompiledGraph; class Engine; @@ -70,6 +72,8 @@ public: private: using Impls = std::list<Disconnect::Impl*>; + std::set<ArcImpl*> adjacent_arcs(GraphImpl* graph); + const ingen::DisconnectAll _msg; GraphImpl* _parent; BlockImpl* _block; |