summaryrefslogtreecommitdiffstats
path: root/src/libs/client
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-09-11 19:57:59 +0000
committerDavid Robillard <d@drobilla.net>2006-09-11 19:57:59 +0000
commit16c866f220847ae23012318d2c1a5023076ab5fa (patch)
tree1cd383ecbe4d3b800423b9860691d89eba2e8a52 /src/libs/client
parentb15864870d34a1188eda93ad215734275037278e (diff)
downloadingen-16c866f220847ae23012318d2c1a5023076ab5fa.tar.gz
ingen-16c866f220847ae23012318d2c1a5023076ab5fa.tar.bz2
ingen-16c866f220847ae23012318d2c1a5023076ab5fa.zip
Bug fixes.
git-svn-id: http://svn.drobilla.net/lad/ingen@129 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/client')
-rw-r--r--src/libs/client/NodeModel.cpp27
-rw-r--r--src/libs/client/NodeModel.h2
-rw-r--r--src/libs/client/ObjectModel.h1
-rw-r--r--src/libs/client/PatchLibrarian.h2
-rw-r--r--src/libs/client/PatchModel.cpp39
-rw-r--r--src/libs/client/PatchModel.h2
-rw-r--r--src/libs/client/PortModel.h3
-rw-r--r--src/libs/client/Store.cpp38
8 files changed, 80 insertions, 34 deletions
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<PortModel> 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());
}
@@ -100,6 +103,18 @@ NodeModel::add_child(CountedPtr<ObjectModel> c)
void
+NodeModel::remove_child(CountedPtr<ObjectModel> c)
+{
+ assert(c->path().is_child_of(m_path));
+ assert(c->parent().get() == this);
+
+ CountedPtr<PortModel> pm = PtrCast<PortModel>(c);
+ assert(pm);
+ remove_port(pm);
+}
+
+
+void
NodeModel::add_port(CountedPtr<PortModel> pm)
{
assert(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<ObjectModel> c);
+ void remove_child(CountedPtr<ObjectModel> c);
CountedPtr<PortModel> get_port(const string& port_name);
void add_port(CountedPtr<PortModel> pm);
+ void remove_port(CountedPtr<PortModel> 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<ObjectModel> p) { m_parent = p; }
virtual void add_child(CountedPtr<ObjectModel> c) = 0;
+ virtual void remove_child(CountedPtr<ObjectModel> c) = 0;
CountedPtr<ObjectController> 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<ModelEngineInterface> 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<ObjectModel> c)
}
+void
+PatchModel::remove_child(CountedPtr<ObjectModel> c)
+{
+ assert(c->path().is_child_of(m_path));
+ assert(c->parent().get() == this);
+
+ CountedPtr<PortModel> pm = PtrCast<PortModel>(c);
+ if (pm) {
+ remove_port(pm);
+ return;
+ }
+
+ CountedPtr<NodeModel> nm = PtrCast<NodeModel>(c);
+ if (nm) {
+ remove_node(nm);
+ return;
+ }
+}
+
+
CountedPtr<NodeModel>
PatchModel::get_node(const string& name)
{
@@ -99,6 +119,25 @@ PatchModel::add_node(CountedPtr<NodeModel> nm)
void
+PatchModel::remove_node(CountedPtr<NodeModel> 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)
{
assert(name.find("/") == string::npos);
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<ObjectModel> c);
+ void remove_child(CountedPtr<ObjectModel> c);
CountedPtr<NodeModel> get_node(const string& node_name);
void add_node(CountedPtr<NodeModel> nm);
void remove_node(const string& name);
+ void remove_node(CountedPtr<NodeModel> 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<ObjectModel> c) { throw; }
+ void add_child(CountedPtr<ObjectModel> c) { throw; }
+ void remove_child(CountedPtr<ObjectModel> 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<ObjectModel> result = (*i).second;
m_objects.erase(i);
//cout << "[Store] Removed " << path << endl;
+
+ if (result)
+ result->destroyed_sig.emit();
+
+ if (result->path() != "/") {
+ CountedPtr<ObjectModel> 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<ObjectModel>();
@@ -200,32 +211,7 @@ Store::add_plugin(CountedPtr<PluginModel> pm)
void
Store::destruction_event(const Path& path)
{
- // Hopefully the compiler will optimize all these const pointers into one...
-
- CountedPtr<ObjectModel> 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<NodeModel*>(object);
- if (node) {
- cerr << "Node\n";
- PatchModel* const parent = dynamic_cast<PatchModel* const>(object->parent().get());
- if (parent)
- parent->remove_node(node->path().name());
- }
-
- PortModel* const port = dynamic_cast<PortModel*>(object);
- if (port) {
- NodeModel* const parent = dynamic_cast<NodeModel* const>(object->parent().get());
- assert(parent);
- parent->remove_port(port->path().name());
- }
-
- if (object)
- object->destroyed_sig.emit();
+ remove_object(path);
}
void