From 6039b44c0a0dea471dd81c3bc2878fd6049de238 Mon Sep 17 00:00:00 2001 From: "Julien \"_FrnchFrgg_\" RIVAUD" Date: Mon, 28 Aug 2017 12:13:01 +0200 Subject: Make Bundle::connected_to() able to check only a single DataType Also use the same iteration logic than in Bundle::connect to avoid mismatched port types. --- libs/ardour/bundle.cc | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'libs/ardour/bundle.cc') diff --git a/libs/ardour/bundle.cc b/libs/ardour/bundle.cc index bdf2446077..33f71dcecd 100644 --- a/libs/ardour/bundle.cc +++ b/libs/ardour/bundle.cc @@ -434,30 +434,49 @@ Bundle::emit_changed (Change c) } } +/* @return true if a Bundle is connected to another. + * @param type: if not NIL, restrict the check to channels of that type. */ bool -Bundle::connected_to (boost::shared_ptr other, AudioEngine & engine) +Bundle::connected_to (boost::shared_ptr other, AudioEngine & engine, + DataType type, bool exclusive) { - if (_ports_are_inputs == other->_ports_are_inputs || nchannels() != other->nchannels()) { + if (_ports_are_inputs == other->_ports_are_inputs) return false; + + if (type == DataType::NIL) { + for (DataType::iterator t = DataType::begin(); + t != DataType::end(); ++t) { + if (!connected_to(other, engine, *t)) + return false; + } + return true; } - for (uint32_t i = 0; i < n_total(); ++i) { - Bundle::PortList const & A = channel_ports (i); - Bundle::PortList const & B = other->channel_ports (i); + uint32_t N = nchannels().n(type); + if (other->nchannels().n(type) != N) + return false; + + for (uint32_t i = 0; i < N; ++i) { + Bundle::PortList const & our_ports = + channel_ports (type_channel_to_overall(type, i)); + Bundle::PortList const & other_ports = + other->channel_ports (other->type_channel_to_overall(type, i)); - for (uint32_t j = 0; j < A.size(); ++j) { - for (uint32_t k = 0; k < B.size(); ++k) { + for (Bundle::PortList::const_iterator j = our_ports.begin(); + j != our_ports.end(); ++j) { + boost::shared_ptr p = engine.get_port_by_name(*j); - boost::shared_ptr p = engine.get_port_by_name (A[j]); - boost::shared_ptr q = engine.get_port_by_name (B[k]); + for (Bundle::PortList::const_iterator k = other_ports.begin(); + k != other_ports.end(); ++k) { + boost::shared_ptr q = engine.get_port_by_name(*k); if (!p && !q) { return false; } - if (p && !p->connected_to (B[k])) { + if (p && !p->connected_to (*k)) { return false; - } else if (q && !q->connected_to (A[j])) { + } else if (q && !q->connected_to (*j)) { return false; } } -- cgit v1.2.3