diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/client/PatchLibrarian.cpp | 6 | ||||
-rw-r--r-- | src/libs/client/PatchModel.cpp | 36 | ||||
-rw-r--r-- | src/libs/client/PatchModel.h | 14 | ||||
-rw-r--r-- | src/libs/client/Store.cpp | 18 | ||||
-rw-r--r-- | src/libs/client/Store.h | 1 | ||||
-rw-r--r-- | src/progs/gtk/PatchController.cpp | 11 | ||||
-rw-r--r-- | src/progs/gtk/PatchController.h | 4 |
7 files changed, 55 insertions, 35 deletions
diff --git a/src/libs/client/PatchLibrarian.cpp b/src/libs/client/PatchLibrarian.cpp index 5c8619f5..532f512b 100644 --- a/src/libs/client/PatchLibrarian.cpp +++ b/src/libs/client/PatchLibrarian.cpp @@ -273,11 +273,11 @@ PatchLibrarian::save_patch(PatchModel* patch_model, const string& filename, bool // Save connections - const list<ConnectionModel*>& cl = patch_model->connections(); + const list<CountedPtr<ConnectionModel> >& cl = patch_model->connections(); const ConnectionModel* c = NULL; - for (list<ConnectionModel*>::const_iterator i = cl.begin(); i != cl.end(); ++i) { - c = (*i); + for (list<CountedPtr<ConnectionModel> >::const_iterator i = cl.begin(); i != cl.end(); ++i) { + c = (*i).get(); xml_node = xmlNewChild(xml_root_node, NULL, (xmlChar*)"connection", NULL); xml_child_node = xmlNewChild(xml_node, NULL, (xmlChar*)"source-node", (xmlChar*)c->src_port_path().parent().name().c_str()); diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 4257dd30..b19f7606 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -40,7 +40,7 @@ PatchModel::set_path(const Path& new_path) #ifdef DEBUG // Be sure connection paths are updated and sane - for (list<ConnectionModel*>::iterator j = m_connections.begin(); + for (list<CountedPtr<ConnectionModel> >::iterator j = m_connections.begin(); j != m_connections.end(); ++j) { assert((*j)->src_port_path().parent().parent() == new_path); assert((*j)->src_port_path().parent().parent() == new_path); @@ -64,8 +64,9 @@ PatchModel::add_node(CountedPtr<NodeModel> nm) assert(nm); assert(nm->name().find("/") == string::npos); assert(nm->parent() == NULL); + assert(m_nodes.find(nm->name()) == m_nodes.end()); - m_nodes[nm->name()] = CountedPtr<NodeModel>(nm); + m_nodes[nm->name()] = nm;//CountedPtr<NodeModel>(nm); nm->set_parent(this); new_node_sig.emit(nm); @@ -90,8 +91,8 @@ PatchModel::remove_node(const string& name) void PatchModel::clear() { - for (list<ConnectionModel*>::iterator j = m_connections.begin(); j != m_connections.end(); ++j) - delete (*j); + //for (list<CountedPtr<ConnectionModel> >::iterator j = m_connections.begin(); j != m_connections.end(); ++j) + // delete (*j); for (NodeModelMap::iterator i = m_nodes.begin(); i != m_nodes.end(); ++i) { (*i).second->clear(); @@ -125,7 +126,7 @@ PatchModel::rename_node(const Path& old_path, const Path& new_path) if (i != m_nodes.end()) { nm = (*i).second.get(); - for (list<ConnectionModel*>::iterator j = m_connections.begin(); j != m_connections.end(); ++j) { + for (list<CountedPtr<ConnectionModel> >::iterator j = m_connections.begin(); j != m_connections.end(); ++j) { if ((*j)->src_port_path().parent() == old_path) (*j)->src_port_path(new_path.base_path() + (*j)->src_port_path().name()); if ((*j)->dst_port_path().parent() == old_path) @@ -141,10 +142,10 @@ PatchModel::rename_node(const Path& old_path, const Path& new_path) } -ConnectionModel* +CountedPtr<ConnectionModel> PatchModel::get_connection(const string& src_port_path, const string& dst_port_path) { - for (list<ConnectionModel*>::iterator i = m_connections.begin(); i != m_connections.end(); ++i) + for (list<CountedPtr<ConnectionModel> >::iterator i = m_connections.begin(); i != m_connections.end(); ++i) if ((*i)->src_port_path() == src_port_path && (*i)->dst_port_path() == dst_port_path) return (*i); return NULL; @@ -159,17 +160,16 @@ PatchModel::get_connection(const string& src_port_path, const string& dst_port_p * this patch is a fatal error. */ void -PatchModel::add_connection(ConnectionModel* cm) +PatchModel::add_connection(CountedPtr<ConnectionModel> cm) { - assert(cm != NULL); + assert(cm); assert(cm->src_port_path().parent().parent() == m_path); assert(cm->dst_port_path().parent().parent() == m_path); assert(cm->patch_path() == path()); - ConnectionModel* existing = get_connection(cm->src_port_path(), cm->dst_port_path()); + CountedPtr<ConnectionModel> existing = get_connection(cm->src_port_path(), cm->dst_port_path()); - if (existing != NULL) { - delete cm; + if (existing) { return; } @@ -197,19 +197,19 @@ PatchModel::add_connection(ConnectionModel* cm) assert(cm->dst_port() != NULL); m_connections.push_back(cm); + + new_connection_sig.emit(cm); } void PatchModel::remove_connection(const string& src_port_path, const string& dst_port_path) { - ConnectionModel* cm = NULL; - for (list<ConnectionModel*>::iterator i = m_connections.begin(); i != m_connections.end(); ++i) { - cm = (*i); + for (list<CountedPtr<ConnectionModel> >::iterator i = m_connections.begin(); i != m_connections.end(); ++i) { + CountedPtr<ConnectionModel> cm = (*i); if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) { - delete cm; - m_connections.erase(i); - assert(get_connection(src_port_path, dst_port_path) == NULL); // no duplicates + m_connections.erase(i); // cuts our reference + assert(!get_connection(src_port_path, dst_port_path)); // no duplicates return; } } diff --git a/src/libs/client/PatchModel.h b/src/libs/client/PatchModel.h index 15677c50..0f8dcd12 100644 --- a/src/libs/client/PatchModel.h +++ b/src/libs/client/PatchModel.h @@ -24,13 +24,12 @@ #include <sigc++/sigc++.h> #include "NodeModel.h" #include "util/CountedPtr.h" +#include "ConnectionModel.h" using std::list; using std::string; using std::map; namespace LibOmClient { -class ConnectionModel; - /** Client's model of a patch. * @@ -46,7 +45,7 @@ public: {} const NodeModelMap& nodes() const { return m_nodes; } - const list<ConnectionModel*>& connections() const { return m_connections; } + const list<CountedPtr<ConnectionModel> >& connections() const { return m_connections; } virtual void set_path(const Path& path); @@ -56,8 +55,8 @@ public: void rename_node(const Path& old_path, const Path& new_path); void rename_node_port(const Path& old_path, const Path& new_path); - ConnectionModel* get_connection(const string& src_port_path, const string& dst_port_path); - void add_connection(ConnectionModel* cm); + CountedPtr<ConnectionModel> get_connection(const string& src_port_path, const string& dst_port_path); + void add_connection(CountedPtr<ConnectionModel> cm); void remove_connection(const string& src_port_path, const string& dst_port_path); virtual void clear(); @@ -71,7 +70,8 @@ public: bool polyphonic() const; // Signals - sigc::signal<void, CountedPtr<NodeModel> > new_node_sig; + sigc::signal<void, CountedPtr<NodeModel> > new_node_sig; + sigc::signal<void, CountedPtr<ConnectionModel> > new_connection_sig; private: // Prevent copies (undefined) @@ -79,7 +79,7 @@ private: PatchModel& operator=(const PatchModel& copy); NodeModelMap m_nodes; - list<ConnectionModel*> m_connections; + list<CountedPtr<ConnectionModel> > m_connections; string m_filename; bool m_enabled; size_t m_poly; diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 65b3080e..cd52af70 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -33,6 +33,7 @@ Store::Store(SigClientInterface& emitter) emitter.new_patch_sig.connect(sigc::mem_fun(this, &Store::new_patch_event)); emitter.new_node_sig.connect(sigc::mem_fun(this, &Store::new_node_event)); emitter.new_port_sig.connect(sigc::mem_fun(this, &Store::new_port_event)); + emitter.connection_sig.connect(sigc::mem_fun(this, &Store::connection_event)); emitter.metadata_update_sig.connect(sigc::mem_fun(this, &Store::metadata_update_event)); } @@ -271,5 +272,22 @@ Store::metadata_update_event(const string& subject_path, const string& predicate } +void +Store::connection_event(const string& src_port_path, const string& dst_port_path) +{ + const Path& src = src_port_path; + const Path& dst = dst_port_path; + + assert(src.parent().parent() == dst.parent().parent()); + const Path& patch_path = src.parent().parent(); + + CountedPtr<PatchModel> patch = this->patch(patch_path); + if (patch) + patch->add_connection(new ConnectionModel(src, dst)); + else + cerr << "ERROR: connection in nonexistant patch" << endl; +} + + } // namespace LibOmClient diff --git a/src/libs/client/Store.h b/src/libs/client/Store.h index 3c3f72fa..ebcf8d8e 100644 --- a/src/libs/client/Store.h +++ b/src/libs/client/Store.h @@ -74,6 +74,7 @@ private: void new_node_event(const string& plugin_type, const string& plugin_uri, const string& node_path, bool is_polyphonic, uint32_t num_ports); void new_port_event(const string& path, const string& data_type, bool is_output); void metadata_update_event(const string& subject_path, const string& predicate, const string& value); + void connection_event(const string& src_port_path, const string& dst_port_path); map<string, CountedPtr<ObjectModel> > m_objects; ///< Keyed by Om path map<string, CountedPtr<PluginModel> > m_plugins; ///< Keyed by URI diff --git a/src/progs/gtk/PatchController.cpp b/src/progs/gtk/PatchController.cpp index 90ffe005..ada6b003 100644 --- a/src/progs/gtk/PatchController.cpp +++ b/src/progs/gtk/PatchController.cpp @@ -72,6 +72,7 @@ PatchController::PatchController(CountedPtr<PatchModel> model) }*/ model->new_node_sig.connect(sigc::mem_fun(this, &PatchController::add_node)); + model->new_connection_sig.connect(sigc::mem_fun(this, &PatchController::connection)); } @@ -338,7 +339,7 @@ PatchController::create_view() } // Create connections - for (list<ConnectionModel*>::const_iterator i = patch_model()->connections().begin(); + for (list<CountedPtr<ConnectionModel> >::const_iterator i = patch_model()->connections().begin(); i != patch_model()->connections().end(); ++i) { create_connection(*i); } @@ -351,7 +352,7 @@ PatchController::create_view() /** Create a connection in the view (canvas). */ void -PatchController::create_connection(const ConnectionModel* cm) +PatchController::create_connection(CountedPtr<ConnectionModel> cm) { m_patch_view->canvas()->add_connection( cm->src_port_path().parent().name(), @@ -575,11 +576,11 @@ PatchController::remove_port(const Path& path, bool resize_module) void -PatchController::connection(ConnectionModel* const cm) +PatchController::connection(CountedPtr<ConnectionModel> cm) { - assert(cm != NULL); + assert(cm); - patch_model()->add_connection(cm); + //patch_model()->add_connection(cm); if (m_patch_view != NULL) create_connection(cm); diff --git a/src/progs/gtk/PatchController.h b/src/progs/gtk/PatchController.h index 553a35e1..840d5fe3 100644 --- a/src/progs/gtk/PatchController.h +++ b/src/progs/gtk/PatchController.h @@ -74,7 +74,7 @@ public: virtual void add_port(CountedPtr<PortModel> pm); virtual void remove_port(const Path& path, bool resize_module); - void connection(ConnectionModel* const cm); + void connection(CountedPtr<ConnectionModel> cm); void disconnection(const Path& src_port_path, const Path& dst_port_path); void clear(); @@ -111,7 +111,7 @@ private: void add_node(CountedPtr<NodeModel> nm); void remove_node(const string& name); - void create_connection(const ConnectionModel* cm); + void create_connection(CountedPtr<ConnectionModel> cm); PatchWindow* m_window; ///< Window currently showing this patch PatchView* m_patch_view; ///< View (canvas) of this patch |