13
0

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.
This commit is contained in:
Julien "_FrnchFrgg_" RIVAUD 2017-08-28 12:13:01 +02:00
parent e07bb07899
commit 6039b44c0a
2 changed files with 32 additions and 12 deletions

View File

@ -100,7 +100,8 @@ class LIBARDOUR_API Bundle : public PBD::ScopedConnectionList
void connect (boost::shared_ptr<Bundle>, AudioEngine &,
bool allow_partial = false);
void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &);
bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &,
DataType type = DataType::NIL);
bool connected_to_anything (AudioEngine &);
bool has_same_ports (boost::shared_ptr<Bundle>) const;
uint32_t type_channel_to_overall (DataType, uint32_t) const;

View File

@ -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<Bundle> other, AudioEngine & engine)
Bundle::connected_to (boost::shared_ptr<Bundle> 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 j = 0; j < A.size(); ++j) {
for (uint32_t k = 0; k < B.size(); ++k) {
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));
boost::shared_ptr<Port> p = engine.get_port_by_name (A[j]);
boost::shared_ptr<Port> q = engine.get_port_by_name (B[k]);
for (Bundle::PortList::const_iterator j = our_ports.begin();
j != our_ports.end(); ++j) {
boost::shared_ptr<Port> p = engine.get_port_by_name(*j);
for (Bundle::PortList::const_iterator k = other_ports.begin();
k != other_ports.end(); ++k) {
boost::shared_ptr<Port> 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;
}
}