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 +-- src/libs/engine/ObjectSender.cpp | 15 ++++++--- src/libs/engine/Patch.cpp | 4 ++- src/libs/engine/events/ConnectionEvent.cpp | 14 +++++--- src/progs/ingenuity/ConnectWindow.cpp | 2 +- src/progs/ingenuity/PatchWindow.cpp | 2 +- 11 files changed, 101 insertions(+), 58 deletions(-) (limited to 'src') 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(); } diff --git a/src/libs/engine/ObjectSender.cpp b/src/libs/engine/ObjectSender.cpp index 872c8d92..8a5fc367 100644 --- a/src/libs/engine/ObjectSender.cpp +++ b/src/libs/engine/ObjectSender.cpp @@ -57,14 +57,11 @@ ObjectSender::send_patch(ClientInterface* client, const Patch* patch) send_node(client, node); } - for (List::const_iterator j = patch->connections().begin(); - j != patch->connections().end(); ++j) - client->connection((*j)->src_port()->path(), (*j)->dst_port()->path()); - // Send port information for (size_t i=0; i < patch->num_ports(); ++i) { Port* const port = patch->ports().at(i); - + send_port(client, port); +/* // Send metadata const map& data = port->metadata(); for (map::const_iterator i = data.begin(); i != data.end(); ++i) @@ -74,7 +71,15 @@ ObjectSender::send_patch(ClientInterface* client, const Patch* patch) if (port->type() == DataType::FLOAT && port->buffer_size() == 1) client->control_change(port->path(), dynamic_cast*>(port)->buffer(0)->value_at(0)); +*/ } + + + // Send connections + for (List::const_iterator j = patch->connections().begin(); + j != patch->connections().end(); ++j) + client->connection((*j)->src_port()->path(), (*j)->dst_port()->path()); + // Send metadata const map& data = patch->metadata(); diff --git a/src/libs/engine/Patch.cpp b/src/libs/engine/Patch.cpp index 5cfdd6e3..d96e63b5 100644 --- a/src/libs/engine/Patch.cpp +++ b/src/libs/engine/Patch.cpp @@ -348,9 +348,11 @@ Patch::remove_port(const Port* port) Array* Patch::build_process_order() const { + cerr << "*********** BUILDING PROCESS ORDER FOR " << path() << endl; + Array* const process_order = new Array(_nodes.size()); - // FIXME: tweak algorithm so it just ends up like this and save the iteration? + // FIXME: tweak algorithm so it just ends up like this and save the cost of iteration? for (List::const_iterator i = _nodes.begin(); i != _nodes.end(); ++i) (*i)->traversed(false); diff --git a/src/libs/engine/events/ConnectionEvent.cpp b/src/libs/engine/events/ConnectionEvent.cpp index aedfd881..652fe801 100644 --- a/src/libs/engine/events/ConnectionEvent.cpp +++ b/src/libs/engine/events/ConnectionEvent.cpp @@ -178,29 +178,33 @@ TypedConnectionEvent::pre_process() Node* const src_node = m_src_port->parent_node(); Node* const dst_node = m_dst_port->parent_node(); + // Connection to a patch port from inside the patch if (src_node->parent_patch() != dst_node->parent_patch()) { - // Connection to a patch port from inside the patch + assert(src_node->parent() == dst_node || dst_node->parent() == src_node); if (src_node->parent() == dst_node) m_patch = dynamic_cast(dst_node); else m_patch = dynamic_cast(src_node); + + // Connection from a patch input to a patch output (pass through) + } else if (src_node == dst_node && dynamic_cast(src_node)) { + m_patch = dynamic_cast(src_node); + + // Normal connection between nodes with the same parent } else { - // Normal connection between nodes with the same parent m_patch = src_node->parent_patch(); } assert(m_patch); if (src_node == NULL || dst_node == NULL) { - cerr << "ERR 1\n"; m_succeeded = false; QueuedEvent::pre_process(); return; } - if (src_node->parent() != m_patch && dst_node->parent() != m_patch) { - cerr << "ERR 2\n"; + if (m_patch != src_node && src_node->parent() != m_patch && dst_node->parent() != m_patch) { m_succeeded = false; QueuedEvent::pre_process(); return; diff --git a/src/progs/ingenuity/ConnectWindow.cpp b/src/progs/ingenuity/ConnectWindow.cpp index a064c0bd..46b4b937 100644 --- a/src/progs/ingenuity/ConnectWindow.cpp +++ b/src/progs/ingenuity/ConnectWindow.cpp @@ -224,7 +224,7 @@ ConnectWindow::gtk_callback() ++stage; } else if (stage == 7) { if (Store::instance().num_objects() > 0) { - CountedPtr root = Store::instance().patch("/"); + CountedPtr root = Store::instance().object("/"); assert(root); PatchController* root_controller = new PatchController(root); root_controller->show_patch_window(); diff --git a/src/progs/ingenuity/PatchWindow.cpp b/src/progs/ingenuity/PatchWindow.cpp index 25fe156b..98107946 100644 --- a/src/progs/ingenuity/PatchWindow.cpp +++ b/src/progs/ingenuity/PatchWindow.cpp @@ -287,7 +287,7 @@ PatchWindow::breadcrumb_clicked(BreadCrumb* crumb) // FIXME: check to be sure PatchModel exists, then controller - maybe // even make a controller if there isn't one? PatchController* const pc = dynamic_cast( - Store::instance().patch(crumb->path())->controller()); + Store::instance().object(crumb->path())->controller()); assert(pc != NULL); if (pc == m_patch) { -- cgit v1.2.1