From 16c866f220847ae23012318d2c1a5023076ab5fa Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 11 Sep 2006 19:57:59 +0000 Subject: Bug fixes. git-svn-id: http://svn.drobilla.net/lad/ingen@129 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/NodeModel.cpp | 27 +++++++++++++++++++++------ src/libs/client/NodeModel.h | 2 ++ src/libs/client/ObjectModel.h | 1 + src/libs/client/PatchLibrarian.h | 2 +- src/libs/client/PatchModel.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/libs/client/PatchModel.h | 2 ++ src/libs/client/PortModel.h | 3 ++- src/libs/client/Store.cpp | 38 ++++++++++++-------------------------- 8 files changed, 80 insertions(+), 34 deletions(-) (limited to 'src/libs/client') diff --git a/src/libs/client/NodeModel.cpp b/src/libs/client/NodeModel.cpp index 05b7b43e..80f8f03a 100644 --- a/src/libs/client/NodeModel.cpp +++ b/src/libs/client/NodeModel.cpp @@ -44,8 +44,15 @@ NodeModel::NodeModel(const string& plugin_uri, const Path& path) NodeModel::~NodeModel() { - /*for (PortModelList::iterator i = m_ports.begin(); i != m_ports.end(); ++i) - delete(*i);*/ + clear(); + m_controller.reset(); +} + + +void +NodeModel::remove_port(CountedPtr port) +{ + m_ports.remove(port); } @@ -64,11 +71,7 @@ NodeModel::remove_port(const string& port_path) void NodeModel::clear() { - /*for (PortModelList::iterator i = m_ports.begin(); i != m_ports.end(); ++i) - delete (*i);*/ - m_ports.clear(); - assert(m_ports.empty()); } @@ -99,6 +102,18 @@ NodeModel::add_child(CountedPtr c) } +void +NodeModel::remove_child(CountedPtr c) +{ + assert(c->path().is_child_of(m_path)); + assert(c->parent().get() == this); + + CountedPtr pm = PtrCast(c); + assert(pm); + remove_port(pm); +} + + void NodeModel::add_port(CountedPtr pm) { diff --git a/src/libs/client/NodeModel.h b/src/libs/client/NodeModel.h index f0bede51..60973d95 100644 --- a/src/libs/client/NodeModel.h +++ b/src/libs/client/NodeModel.h @@ -49,9 +49,11 @@ public: virtual ~NodeModel(); void add_child(CountedPtr c); + void remove_child(CountedPtr c); CountedPtr get_port(const string& port_name); void add_port(CountedPtr pm); + void remove_port(CountedPtr pm); void remove_port(const string& port_path); virtual void clear(); diff --git a/src/libs/client/ObjectModel.h b/src/libs/client/ObjectModel.h index 9ee4f8c4..744d78a0 100644 --- a/src/libs/client/ObjectModel.h +++ b/src/libs/client/ObjectModel.h @@ -60,6 +60,7 @@ public: virtual void set_parent(CountedPtr p) { m_parent = p; } virtual void add_child(CountedPtr c) = 0; + virtual void remove_child(CountedPtr c) = 0; CountedPtr controller() const { return m_controller; } diff --git a/src/libs/client/PatchLibrarian.h b/src/libs/client/PatchLibrarian.h index a900b22f..d73912f1 100644 --- a/src/libs/client/PatchLibrarian.h +++ b/src/libs/client/PatchLibrarian.h @@ -48,7 +48,7 @@ public: // FIXME: return booleans and set an errstr that can be checked or something? PatchLibrarian(CountedPtr engine) - : _patch_search_path("."), _engine(_engine) + : _patch_search_path("."), _engine(engine) { assert(_engine); } diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 36e829f3..68a55b40 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -69,6 +69,26 @@ PatchModel::add_child(CountedPtr c) } +void +PatchModel::remove_child(CountedPtr c) +{ + assert(c->path().is_child_of(m_path)); + assert(c->parent().get() == this); + + CountedPtr pm = PtrCast(c); + if (pm) { + remove_port(pm); + return; + } + + CountedPtr nm = PtrCast(c); + if (nm) { + remove_node(nm); + return; + } +} + + CountedPtr PatchModel::get_node(const string& name) { @@ -98,6 +118,25 @@ PatchModel::add_node(CountedPtr nm) } +void +PatchModel::remove_node(CountedPtr nm) +{ + assert(nm->path().is_child_of(m_path)); + assert(nm->parent().get() == this); + + NodeModelMap::iterator i = m_nodes.find(nm->path().name()); + if (i != m_nodes.end()) { + assert(i->second == nm); + m_nodes.erase(i); + removed_node_sig.emit(nm->path().name()); + return; + } + + cerr << "[PatchModel::remove_node] " << m_path + << ": failed to find node " << nm->path().name() << endl; +} + + void PatchModel::remove_node(const string& name) { diff --git a/src/libs/client/PatchModel.h b/src/libs/client/PatchModel.h index db444de2..6ca8ed8f 100644 --- a/src/libs/client/PatchModel.h +++ b/src/libs/client/PatchModel.h @@ -51,10 +51,12 @@ public: virtual void set_path(const Path& path); void add_child(CountedPtr c); + void remove_child(CountedPtr c); CountedPtr get_node(const string& node_name); void add_node(CountedPtr nm); void remove_node(const string& name); + void remove_node(CountedPtr nm); void rename_node(const Path& old_path, const Path& new_path); void rename_node_port(const Path& old_path, const Path& new_path); diff --git a/src/libs/client/PortModel.h b/src/libs/client/PortModel.h index 7b84c95a..1f816748 100644 --- a/src/libs/client/PortModel.h +++ b/src/libs/client/PortModel.h @@ -70,7 +70,8 @@ public: { } - void add_child(CountedPtr c) { throw; } + void add_child(CountedPtr c) { throw; } + void remove_child(CountedPtr c) { throw; } inline float min_val() const { return m_min_val; } inline float user_min() const { return atof(get_metadata("min").c_str()); } // FIXME: haaack diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 36e815d8..c0bc1a31 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -153,7 +153,18 @@ Store::remove_object(const Path& path) CountedPtr result = (*i).second; m_objects.erase(i); //cout << "[Store] Removed " << path << endl; + + if (result) + result->destroyed_sig.emit(); + + if (result->path() != "/") { + CountedPtr parent = this->object(result->path().parent()); + if (parent) { + parent->remove_child(result); + } + } return result; + } else { cerr << "[Store] Unable to find object " << path << " to remove." << endl; return CountedPtr(); @@ -200,32 +211,7 @@ Store::add_plugin(CountedPtr pm) void Store::destruction_event(const Path& path) { - // Hopefully the compiler will optimize all these const pointers into one... - - CountedPtr obj_ptr = remove_object(path); - ObjectModel* const object = obj_ptr.get(); - - // FIXME: Why does this need to be specific? Just make a remove_child - // for everything - - // Succeeds for (Plugin) Nodes and Patches - NodeModel* const node = dynamic_cast(object); - if (node) { - cerr << "Node\n"; - PatchModel* const parent = dynamic_cast(object->parent().get()); - if (parent) - parent->remove_node(node->path().name()); - } - - PortModel* const port = dynamic_cast(object); - if (port) { - NodeModel* const parent = dynamic_cast(object->parent().get()); - assert(parent); - parent->remove_port(port->path().name()); - } - - if (object) - object->destroyed_sig.emit(); + remove_object(path); } void -- cgit v1.2.1