From efee2b08f575e2c216cffa6f08a928223ab2cedb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Jun 2006 04:48:20 +0000 Subject: Store memory bug fixes (multiple ref ptr's to the same object, bad), control panel fixes git-svn-id: http://svn.drobilla.net/lad/grauph@32 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/NodeModel.cpp | 8 ++++---- src/libs/client/NodeModel.h | 3 --- src/libs/client/ObjectModel.h | 12 ++++++------ src/libs/client/PatchLibrarian.cpp | 6 +++--- src/libs/client/PatchModel.cpp | 9 ++++----- src/libs/client/Store.cpp | 11 +++++++---- src/libs/client/Store.h | 3 --- src/libs/engine/LV2Plugin.cpp | 8 ++------ 8 files changed, 26 insertions(+), 34 deletions(-) (limited to 'src/libs') diff --git a/src/libs/client/NodeModel.cpp b/src/libs/client/NodeModel.cpp index 3e060401..22b20858 100644 --- a/src/libs/client/NodeModel.cpp +++ b/src/libs/client/NodeModel.cpp @@ -81,22 +81,22 @@ NodeModel::set_path(const Path& p) for (PortModelList::iterator i = m_ports.begin(); i != m_ports.end(); ++i) (*i)->set_path(m_path + "/" + (*i)->name()); - if (parent_patch() != NULL && old_path.length() > 0) - parent_patch()->rename_node(old_path, p); + //if (m_parent && old_path.length() > 0) + // parent_patch()->rename_node(old_path, p); } void NodeModel::add_port(CountedPtr pm) { + assert(pm); assert(pm->name() != ""); assert(pm->path().length() > m_path.length()); assert(pm->path().substr(0, m_path.length()) == m_path); - assert(pm->parent() == NULL); + assert(pm->parent().get() == this); assert(!get_port(pm->name())); m_ports.push_back(pm); - pm->set_parent(this); new_port_sig.emit(pm); } diff --git a/src/libs/client/NodeModel.h b/src/libs/client/NodeModel.h index 05df5ed5..1b79905a 100644 --- a/src/libs/client/NodeModel.h +++ b/src/libs/client/NodeModel.h @@ -33,7 +33,6 @@ using std::cout; using std::cerr; using std::endl; namespace LibOmClient { -class PatchModel; class PluginModel; @@ -71,8 +70,6 @@ public: float y() const { return m_y; } void y(float a) { m_y = a; } - PatchModel* parent_patch() const { return (PatchModel*)m_parent; } - // Signals sigc::signal > new_port_sig; diff --git a/src/libs/client/ObjectModel.h b/src/libs/client/ObjectModel.h index 94103c53..b9a6d75d 100644 --- a/src/libs/client/ObjectModel.h +++ b/src/libs/client/ObjectModel.h @@ -25,7 +25,7 @@ #include #include #include "util/Path.h" - +#include "util/CountedPtr.h" using std::string; using std::map; using std::find; using std::cout; using std::cerr; using std::endl; using Om::Path; @@ -55,8 +55,8 @@ public: inline const Path& path() const { return m_path; } virtual void set_path(const Path& p) { m_path = p; } - ObjectModel* parent() const { return m_parent; } - virtual void set_parent(ObjectModel* p) { m_parent = p; } + CountedPtr parent() const { return m_parent; } + virtual void set_parent(CountedPtr p) { m_parent = p; } ObjectController* controller() const { return m_controller; } @@ -69,9 +69,9 @@ public: // Signals sigc::signal metadata_update_sig; protected: - Path m_path; - ObjectModel* m_parent; - ObjectController* m_controller; + Path m_path; + CountedPtr m_parent; + ObjectController* m_controller; // FIXME: remove map m_metadata; diff --git a/src/libs/client/PatchLibrarian.cpp b/src/libs/client/PatchLibrarian.cpp index 532f512b..930cdccf 100644 --- a/src/libs/client/PatchLibrarian.cpp +++ b/src/libs/client/PatchLibrarian.cpp @@ -359,8 +359,8 @@ PatchLibrarian::load_patch(PatchModel* pm, bool wait, bool existing) { string filename = pm->filename(); - string additional_path = (pm->parent() == NULL) - ? "" : ((PatchModel*)pm->parent())->filename(); + string additional_path = (!pm->parent()) + ? "" : ((PatchModel*)pm->parent().get())->filename(); additional_path = additional_path.substr(0, additional_path.find_last_of("/")); filename = find_file(pm->filename(), additional_path); @@ -409,7 +409,7 @@ PatchLibrarian::load_patch(PatchModel* pm, bool wait, bool existing) if ((!xmlStrcmp(cur->name, (const xmlChar*)"name"))) { if (load_name) { assert(key != NULL); - if (pm->parent() != NULL) { + if (pm->parent()) { path = pm->parent()->base_path() + string((char*)key); } else { path = string("/") + string((char*)key); diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index b19f7606..877f5df0 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -63,11 +63,10 @@ PatchModel::add_node(CountedPtr nm) { assert(nm); assert(nm->name().find("/") == string::npos); - assert(nm->parent() == NULL); + assert(nm->parent().get() == this); assert(m_nodes.find(nm->name()) == m_nodes.end()); - m_nodes[nm->name()] = nm;//CountedPtr(nm); - nm->set_parent(this); + m_nodes[nm->name()] = nm; new_node_sig.emit(nm); } @@ -222,9 +221,9 @@ PatchModel::remove_connection(const string& src_port_path, const string& dst_por bool PatchModel::polyphonic() const { - return (m_parent == NULL) + return (!m_parent) ? (m_poly > 1) - : (m_poly > 1) && m_poly == parent_patch()->poly() && m_poly > 1; + : (m_poly > 1) && m_poly == ((PatchModel*)m_parent.get())->poly() && m_poly > 1; } diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index cd52af70..21470f41 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -207,11 +207,13 @@ Store::new_node_event(const string& plugin_type, const string& plugin_uri, const std::map >::iterator pi = m_objects.find(n->path().parent()); if (pi != m_objects.end()) { - PatchModel* parent = dynamic_cast((*pi).second.get()); - if (parent) + CountedPtr parent = (*pi).second; + if (parent) { + n->set_parent(parent); parent->add_node(n); - else + } else { cerr << "ERROR: new node with no parent" << endl; + } } } } @@ -251,7 +253,8 @@ Store::new_port_event(const string& path, const string& type, bool is_output) std::map >::iterator pi = m_objects.find(p->path().parent()); if (pi != m_objects.end()) { - NodeModel* parent = dynamic_cast((*pi).second.get()); + CountedPtr parent = (*pi).second; + p->set_parent(parent); if (parent) parent->add_port(p); else diff --git a/src/libs/client/Store.h b/src/libs/client/Store.h index ebcf8d8e..b17d30c2 100644 --- a/src/libs/client/Store.h +++ b/src/libs/client/Store.h @@ -17,9 +17,6 @@ #ifndef STORE_H #define STORE_H -// FIXME: for CountedPtr -#define WITH_RTTI - #include #include #include diff --git a/src/libs/engine/LV2Plugin.cpp b/src/libs/engine/LV2Plugin.cpp index 1c74bca9..4cb7348d 100644 --- a/src/libs/engine/LV2Plugin.cpp +++ b/src/libs/engine/LV2Plugin.cpp @@ -82,14 +82,10 @@ LV2Plugin::instantiate() Port* port = NULL; for (size_t j=0; j < m_num_ports; ++j) { - // LV2 shortnames are guaranteed to be unique + // LV2 shortnames are guaranteed to be unique, valid C identifiers port_name = (char*)slv2_port_get_symbol(m_lv2_plugin, j); - string::size_type slash_index; - - // Replace all slashes with "-" (so they don't screw up paths) - while ((slash_index = port_name.find("/")) != string::npos) - port_name[slash_index] = '-'; + assert(port_name.find("/") == string::npos); port_path = path() + "/" + port_name; -- cgit v1.2.1