Make Bundle::connect able to connect only some DataTypes
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Wed, 23 Aug 2017 20:01:08 +0000 (22:01 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Wed, 23 Aug 2017 21:31:28 +0000 (23:31 +0200)
When |allow_partial| is true, only when the number of channels of a
given DataType is the same for both bundles are the corresponding
channels connected together.

When |allow_partial| is false (the default), the number of channels must
match for each DataType (the ChanCounts must be equal) for the
connection to be attempted.

This also fixes the logic in case two bundles have the same number of
channels, or even the same ChanCounts, but not with the DataTypes in the
same order (so connecting the ith channel of the bundle to the ith
channel of the other bundle makes no sense).

libs/ardour/ardour/bundle.h
libs/ardour/bundle.cc

index fe0de29c76286fbcc086f78224cc592beaea543f..704af612566fb3ab9da72e54bcb08f93b0e3b20d 100644 (file)
@@ -97,7 +97,8 @@ class LIBARDOUR_API Bundle : public PBD::ScopedConnectionList
        void remove_channel (uint32_t);
        void remove_channels ();
        void add_channels_from_bundle (boost::shared_ptr<Bundle>);
-       void connect (boost::shared_ptr<Bundle>, AudioEngine &);
+       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_anything (AudioEngine &);
index 5e57eb3e10a4d1eee884219a892d01e429280c7b..bdf24460777590c82f8f716f7834f3615d4af233 100644 (file)
@@ -322,20 +322,37 @@ Bundle::add_channels_from_bundle (boost::shared_ptr<Bundle> other)
  *  with another bundle's channels.
  *  @param other Other bundle.
  *  @param engine AudioEngine to use to make the connections.
+ *  @param allow_partial whether to allow leaving unconnected channels types,
+ *              or require that the ChanCounts match exactly (default false).
  */
 void
-Bundle::connect (boost::shared_ptr<Bundle> other, AudioEngine & engine)
+Bundle::connect (boost::shared_ptr<Bundle> other, AudioEngine & engine,
+                 bool allow_partial)
 {
-       uint32_t const N = n_total();
-       assert (N == other->n_total());
+       ChanCount our_count = nchannels();
+       ChanCount other_count = other->nchannels();
 
-       for (uint32_t i = 0; i < N; ++i) {
-               Bundle::PortList const & our_ports = channel_ports (i);
-               Bundle::PortList const & other_ports = other->channel_ports (i);
+       if (!allow_partial && our_count != other_count) {
+               assert (our_count == other_count);
+               return;
+       }
 
-               for (Bundle::PortList::const_iterator j = our_ports.begin(); j != our_ports.end(); ++j) {
-                       for (Bundle::PortList::const_iterator k = other_ports.begin(); k != other_ports.end(); ++k) {
-                               engine.connect (*j, *k);
+       for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+               uint32_t N = our_count.n(*t);
+               if (N != other_count.n(*t))
+                       continue;
+               for (uint32_t i = 0; i < N; ++i) {
+                       Bundle::PortList const & our_ports =
+                               channel_ports (type_channel_to_overall(*t, i));
+                       Bundle::PortList const & other_ports =
+                               other->channel_ports (other->type_channel_to_overall(*t, i));
+
+                       for (Bundle::PortList::const_iterator j = our_ports.begin();
+                                               j != our_ports.end(); ++j) {
+                               for (Bundle::PortList::const_iterator k = other_ports.begin();
+                                                       k != other_ports.end(); ++k) {
+                                       engine.connect (*j, *k);
+                               }
                        }
                }
        }