From c5218b13bac00fbd8c3ceb99b46063b98bc1fdd3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 8 Jan 2007 02:41:36 +0000 Subject: Fix destruction of nodes with connections to parent patch ports. git-svn-id: http://svn.drobilla.net/lad/ingen@241 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ConnectionModel.h | 4 ++-- src/libs/client/ObjectModel.h | 4 ++-- src/libs/client/PatchModel.cpp | 28 ++++++++++++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src/libs/client') diff --git a/src/libs/client/ConnectionModel.h b/src/libs/client/ConnectionModel.h index 6dc85405..f1112e33 100644 --- a/src/libs/client/ConnectionModel.h +++ b/src/libs/client/ConnectionModel.h @@ -62,8 +62,8 @@ private: void src_port_path(const string& s) { _src_port_path = s; } void dst_port_path(const string& s) { _dst_port_path = s; } - Path _src_port_path; ///< Only used if _src_port == NULL - Path _dst_port_path; ///< Only used if _dst_port == NULL + Path _src_port_path; ///< Only used if _src_port == NULL + Path _dst_port_path; ///< Only used if _dst_port == NULL SharedPtr _src_port; SharedPtr _dst_port; }; diff --git a/src/libs/client/ObjectModel.h b/src/libs/client/ObjectModel.h index 799399e9..12db367b 100644 --- a/src/libs/client/ObjectModel.h +++ b/src/libs/client/ObjectModel.h @@ -55,8 +55,8 @@ public: const Atom& get_metadata(const string& key) const; - const MetadataMap& metadata() const { return _metadata; } - inline const Path& path() const { return _path; } + const MetadataMap& metadata() const { return _metadata; } + inline const Path& path() const { return _path; } SharedPtr parent() const { return _parent; } // Signals diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 22d39d42..1148ff61 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -124,14 +124,31 @@ PatchModel::remove_node(SharedPtr nm) NodeModelMap::iterator i = m_nodes.find(nm->path().name()); if (i != m_nodes.end()) { assert(i->second == nm); + + // Remove any connections which referred to this node, + // since they can't possibly exist anymore + for (list >::iterator i = m_connections.begin(); + i != m_connections.end() ; ) { + list >::iterator next = i; + ++next; + SharedPtr cm = (*i); + if (cm->src_port_path().parent() == nm->path() + || cm->dst_port_path().parent() == nm->path()) { + m_connections.erase(i); // cuts our reference + assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates + removed_connection_sig.emit(cm->src_port_path(), cm->dst_port_path()); + } + i = next; + } + + // Remove the Node itself m_nodes.erase(i); removed_node_sig.emit(nm); - //i->second->parent().reset(); - return; + + } else { + cerr << "[PatchModel::remove_node] " << _path + << ": failed to find node " << nm->path().name() << endl; } - - cerr << "[PatchModel::remove_node] " << _path - << ": failed to find node " << nm->path().name() << endl; } #if 0 @@ -255,7 +272,6 @@ PatchModel::add_connection(SharedPtr cm) void PatchModel::remove_connection(const string& src_port_path, const string& dst_port_path) { - cerr << path() << " PatchModel::remove_connection: " << src_port_path << " -> " << dst_port_path << endl; for (list >::iterator i = m_connections.begin(); i != m_connections.end(); ++i) { SharedPtr cm = (*i); if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) { -- cgit v1.2.1