From 62d76290ae0eb783db0e24338c17adb08d845a73 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 3 Jul 2006 22:13:38 +0000 Subject: Fixes for connecting directly from a patch input to a patch output git-svn-id: http://svn.drobilla.net/lad/ingen@81 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ConnectionModel.cpp | 54 +++++++++++++++++++++++++++---------- src/libs/client/ConnectionModel.h | 25 ++++++++--------- src/libs/client/PatchModel.cpp | 18 ++++++------- src/libs/client/PatchModel.h | 2 +- src/libs/client/Store.cpp | 19 ++++++++----- src/libs/client/Store.h | 4 +-- 6 files changed, 77 insertions(+), 45 deletions(-) (limited to 'src/libs/client') diff --git a/src/libs/client/ConnectionModel.cpp b/src/libs/client/ConnectionModel.cpp index 3f9a6441..b65f4824 100644 --- a/src/libs/client/ConnectionModel.cpp +++ b/src/libs/client/ConnectionModel.cpp @@ -16,46 +16,72 @@ #include "ConnectionModel.h" #include "PortModel.h" +#include "PatchModel.h" namespace LibOmClient { ConnectionModel::ConnectionModel(const Path& src_port, const Path& dst_port) -: m_src_port_path(src_port), - m_dst_port_path(dst_port), - m_src_port(NULL), - m_dst_port(NULL) +: _src_port_path(src_port), + _dst_port_path(dst_port), + _src_port(NULL), + _dst_port(NULL) { // Be sure connection is within one patch - //assert(m_src_port_path.parent().parent() - // == m_dst_port_path.parent().parent()); + //assert(_src_port_path.parent().parent() + // == _dst_port_path.parent().parent()); +} + + +ConnectionModel::ConnectionModel(CountedPtr src, CountedPtr dst) +: _src_port_path(src->path()), + _dst_port_path(dst->path()), + _src_port(src), + _dst_port(dst) +{ + // Be sure connection is within one patch + //assert(_src_port_path.parent().parent() + // == _dst_port_path.parent().parent()); } const Path& ConnectionModel::src_port_path() const { - if (m_src_port == NULL) - return m_src_port_path; + if (!_src_port) + return _src_port_path; else - return m_src_port->path(); + return _src_port->path(); } const Path& ConnectionModel::dst_port_path() const { - if (m_dst_port == NULL) - return m_dst_port_path; + if (!_dst_port) + return _dst_port_path; else - return m_dst_port->path(); + return _dst_port->path(); } const Path ConnectionModel::patch_path() const { - const Path& src_node = m_src_port_path.parent(); - const Path& dst_node = m_dst_port_path.parent(); + // Resolved + if (_src_port && _dst_port) { + // Direct connection from patch input to patch output (pass through) + // (parent patch is parent of ports) + if (_src_port->parent() == _dst_port->parent()) { + CountedPtr parent_patch = _src_port->parent(); + if (parent_patch) + return parent_patch->path(); + } + } + + // Aside from the above special case, parent patch is parent of parent of ports + + const Path& src_node = _src_port_path.parent(); + const Path& dst_node = _dst_port_path.parent(); Path patch_path = src_node.parent(); if (src_node.parent() != dst_node.parent()) { diff --git a/src/libs/client/ConnectionModel.h b/src/libs/client/ConnectionModel.h index ad517777..3a9f0007 100644 --- a/src/libs/client/ConnectionModel.h +++ b/src/libs/client/ConnectionModel.h @@ -20,14 +20,14 @@ #include #include "util/Path.h" +#include "util/CountedPtr.h" +#include "PortModel.h" #include using std::string; using Om::Path; namespace LibOmClient { -class PortModel; - /** Class to represent a port->port connection in the engine. * @@ -43,25 +43,26 @@ class ConnectionModel { public: ConnectionModel(const Path& src_port, const Path& dst_port); + ConnectionModel(CountedPtr src, CountedPtr dst); - PortModel* src_port() const { return m_src_port; } - PortModel* dst_port() const { return m_dst_port; } + CountedPtr src_port() const { return _src_port; } + CountedPtr dst_port() const { return _dst_port; } - void set_src_port(PortModel* port) { m_src_port = port; m_src_port_path = ""; } - void set_dst_port(PortModel* port) { m_dst_port = port; m_dst_port_path = ""; } + void set_src_port(CountedPtr port) { _src_port = port; _src_port_path = port->path(); } + void set_dst_port(CountedPtr port) { _dst_port = port; _dst_port_path = port->path(); } - void src_port_path(const string& s) { m_src_port_path = s; } - void dst_port_path(const string& s) { m_dst_port_path = s; } + void src_port_path(const string& s) { _src_port_path = s; } + void dst_port_path(const string& s) { _dst_port_path = s; } const Path& src_port_path() const; const Path& dst_port_path() const; const Path patch_path() const; private: - Path m_src_port_path; ///< Only used if m_src_port == NULL - Path m_dst_port_path; ///< Only used if m_dst_port == NULL - PortModel* m_src_port; - PortModel* m_dst_port; + Path _src_port_path; ///< Only used if _src_port == NULL + Path _dst_port_path; ///< Only used if _dst_port == NULL + CountedPtr _src_port; + CountedPtr _dst_port; }; diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 659fca23..d79fa74b 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -154,7 +154,7 @@ PatchModel::get_connection(const string& src_port_path, const string& dst_port_p /** Add a connection to this patch. * - * Ownership of @a cm is taken, it will be deleted along with this PatchModel. + * A reference to @a cm is taken, released on deletion or removal. * If @a cm only contains paths (not pointers to the actual ports), the ports * will be found and set. The ports referred to not existing as children of * this patch is a fatal error. @@ -177,28 +177,28 @@ PatchModel::add_connection(CountedPtr cm) NodeModel* src_node = (cm->src_port_path().parent() == path()) ? this : get_node(cm->src_port_path().parent().name()).get(); - PortModel* src_port = (src_node == NULL) ? NULL : src_node->get_port(cm->src_port_path().name()).get(); + CountedPtr src_port = src_node->get_port(cm->src_port_path().name()); NodeModel* dst_node = (cm->dst_port_path().parent() == path()) ? this : get_node(cm->dst_port_path().parent().name()).get(); - PortModel* dst_port = (dst_node == NULL) ? NULL : dst_node->get_port(cm->dst_port_path().name()).get(); + CountedPtr dst_port = dst_node->get_port(cm->dst_port_path().name()); - assert(src_port != NULL); - assert(dst_port != NULL); + assert(src_port); + assert(dst_port); // Find source port pointer to 'resolve' connection if necessary - if (cm->src_port() != NULL) + if (cm->src_port()) assert(cm->src_port() == src_port); else cm->set_src_port(src_port); // Find dest port pointer to 'resolve' connection if necessary - if (cm->dst_port() != NULL) + if (cm->dst_port()) assert(cm->dst_port() == dst_port); else cm->set_dst_port(dst_port); - assert(cm->src_port() != NULL); - assert(cm->dst_port() != NULL); + assert(cm->src_port()); + assert(cm->dst_port()); m_connections.push_back(cm); diff --git a/src/libs/client/PatchModel.h b/src/libs/client/PatchModel.h index a6f786d3..34ed9024 100644 --- a/src/libs/client/PatchModel.h +++ b/src/libs/client/PatchModel.h @@ -91,7 +91,7 @@ private: size_t m_poly; }; -typedef map PatchModelMap; +typedef map > PatchModelMap; } // namespace LibOmClient diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 5bf8175d..a8dd69e8 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -95,7 +95,7 @@ Store::object(const string& path) return (*i).second; } - +#if 0 CountedPtr Store::patch(const string& path) { @@ -146,7 +146,7 @@ Store::port(const string& path) return NULL; } - +#endif void Store::add_plugin(CountedPtr pm) @@ -345,11 +345,16 @@ Store::control_change_event(const string& port_path, float value) void Store::connection_event(const Path& src_port_path, const Path& dst_port_path) { - // ConnectionModel has the clever patch-path-figuring-out stuff in it, so - // just make one right away to get at that - ConnectionModel* cm = new ConnectionModel(src_port_path, dst_port_path); + CountedPtr src_port = object(src_port_path); + CountedPtr dst_port = object(dst_port_path); + + assert(src_port); + assert(dst_port); - CountedPtr patch = this->patch(cm->patch_path()); + CountedPtr cm = new ConnectionModel(src_port, dst_port); + + CountedPtr patch = this->object(cm->patch_path()); + if (patch) patch->add_connection(cm); else @@ -366,7 +371,7 @@ Store::disconnection_event(const Path& src_port_path, const Path& dst_port_path) assert(src.parent().parent() == dst.parent().parent()); const Path& patch_path = src.parent().parent(); - CountedPtr patch = this->patch(patch_path); + CountedPtr patch = this->object(patch_path); if (patch) patch->remove_connection(src, dst); else diff --git a/src/libs/client/Store.h b/src/libs/client/Store.h index 7ee1388d..d89bcc8f 100644 --- a/src/libs/client/Store.h +++ b/src/libs/client/Store.h @@ -43,9 +43,9 @@ class Store : public sigc::trackable { // FIXME: is trackable necessary? public: CountedPtr plugin(const string& uri); CountedPtr object(const string& path); - CountedPtr patch(const string& path); + /*CountedPtr patch(const string& path); CountedPtr node(const string& path); - CountedPtr port(const string& path); + CountedPtr port(const string& path);*/ size_t num_objects() { return m_objects.size(); } -- cgit v1.2.1