Make track sends etc. appear in the same bundle as the track. Tidy up bundle channel...
authorCarl Hetherington <carl@carlh.net>
Tue, 27 Jan 2009 18:36:40 +0000 (18:36 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 27 Jan 2009 18:36:40 +0000 (18:36 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@4448 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/port_group.cc
libs/ardour/ardour/bundle.h
libs/ardour/ardour/io.h
libs/ardour/bundle.cc
libs/ardour/io.cc

index 2544268586d3e769c712011d6fd4b92782cea106..af2fd24bc5f4adf8095347279b8f41418f167650 100644 (file)
@@ -139,15 +139,40 @@ PortGroupList::gather (ARDOUR::Session& session)
 {
        clear_list ();
 
-       /* Find the bundles for routes */
+       /* Find the bundles for routes.  We take their bundles, copy them,
+          and add ports from the route's processors */
 
        boost::shared_ptr<ARDOUR::Session::RouteList> routes = session.get_routes ();
 
        for (ARDOUR::Session::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
+               /* Copy the appropriate bundle from the route */
+               boost::shared_ptr<ARDOUR::Bundle> bundle (
+                       new ARDOUR::Bundle (
+                               _offer_inputs ? (*i)->bundle_for_inputs() : (*i)->bundle_for_outputs ()
+                               )
+                       );
 
-               /* Route IO */
-               PortGroup* g = 0;
+               /* Add ports from the route's processors */
+               uint32_t n = 0;
+               while (1) {
+                       boost::shared_ptr<ARDOUR::Processor> p = (*i)->nth_processor (n);
+                       if (p == 0) {
+                               break;
+                       }
 
+                       boost::shared_ptr<ARDOUR::IOProcessor> iop = boost::dynamic_pointer_cast<ARDOUR::IOProcessor> (p);
+
+                       if (iop) {
+                               boost::shared_ptr<ARDOUR::Bundle> pb = _offer_inputs ?
+                                       iop->io()->bundle_for_inputs() : iop->io()->bundle_for_outputs();
+                               bundle->add_channels_from_bundle (pb);
+                       }
+
+                       ++n;
+               }
+                       
+               /* Work out which group to put this bundle in */
+               PortGroup* g = 0;
                if (_type == ARDOUR::DataType::AUDIO) {
 
                        if (boost::dynamic_pointer_cast<ARDOUR::AudioTrack> (*i)) {
@@ -167,24 +192,7 @@ PortGroupList::gather (ARDOUR::Session& session)
                } 
                        
                if (g) {
-                       g->add_bundle (_offer_inputs ? (*i)->bundle_for_inputs() : (*i)->bundle_for_outputs ());
-               }
-
-               /* Ports from this route's processors */
-
-               uint32_t n = 0;
-               while (1) {
-                       boost::shared_ptr<ARDOUR::Processor> p = (*i)->nth_processor (n);
-                       if (p == 0) {
-                               break;
-                       }
-
-                       boost::shared_ptr<ARDOUR::IOProcessor> iop = boost::dynamic_pointer_cast<ARDOUR::IOProcessor> (p);
-                       if (iop) {
-                               g->add_bundle (_offer_inputs ? iop->io()->bundle_for_inputs() : iop->io()->bundle_for_outputs());
-                       }
-
-                       ++n;
+                       g->add_bundle (bundle);
                }
        }
 
index f9971ddf155239c1107323e93c47b08de6bb1637..ac5928fc34be1f989be9a3d1122707d6f25e0e82 100644 (file)
@@ -24,6 +24,7 @@
 #include <vector>
 #include <glibmm/thread.h>
 #include <sigc++/signal.h>
+#include <boost/shared_ptr.hpp>
 #include "ardour/data_type.h"
 
 namespace ARDOUR {
@@ -72,6 +73,8 @@ class Bundle : public sigc::trackable
         */
        Bundle (std::string const & n, DataType t, bool i = true) : _name (n), _type (t), _ports_are_inputs (i) {}
 
+       Bundle (boost::shared_ptr<Bundle>);
+       
        virtual ~Bundle() {}
 
        /** @return Number of channels that this Bundle has */
@@ -93,6 +96,7 @@ class Bundle : public sigc::trackable
        bool offers_port_alone (std::string) const;
        void remove_channel (uint32_t);
        void remove_channels ();
+       void add_channels_from_bundle (boost::shared_ptr<ARDOUR::Bundle>);
 
        /** Set the name.
         *  @param n New name.
index 1918a9a41a224528e068238778af1c4e31fc90bd..2d5b55c50296c25f5adea9b6ad0d4eacf203efc7 100644 (file)
@@ -380,6 +380,7 @@ class IO : public SessionObject, public AutomatableControls, public Latent
 
        void create_bundles_for_inputs_and_outputs ();
        void setup_bundles_for_inputs_and_outputs ();
+       std::string bundle_channel_name (uint32_t, uint32_t) const;
 };
 
 } // namespace ARDOUR
index 53fc2f1930635fa30b4536a144c454508686a663..48c0ead6e61319043c1b440c9a18d03bd329f624 100644 (file)
 using namespace ARDOUR;
 using namespace PBD;
 
+Bundle::Bundle (boost::shared_ptr<Bundle> other)
+       : _channel (other->_channel),
+         _name (other->_name),
+         _type (other->_type),
+         _ports_are_inputs (other->_ports_are_inputs)
+{
+       
+}
+
 uint32_t
 Bundle::nchannels () const
 {
@@ -211,3 +220,26 @@ Bundle::set_channel_name (uint32_t ch, std::string const & n)
 
        NameChanged (); /* EMIT SIGNAL */
 }
+
+/** Take the channels from another bundle and add them to this bundle,
+ *  so that channels from other are added to this (with their ports)
+ *  and are named "<other_bundle_name> <other_channel_name>".
+ */
+void
+Bundle::add_channels_from_bundle (boost::shared_ptr<Bundle> other)
+{
+       uint32_t const ch = nchannels ();
+       
+       for (uint32_t i = 0; i < other->nchannels(); ++i) {
+
+               std::stringstream s;
+               s << other->name() << " " << other->channel_name(i);
+
+               add_channel (s.str());
+
+               PortList const& pl = other->channel_ports (i);
+               for (uint32_t j = 0; j < pl.size(); ++j) {
+                       add_port_to_channel (ch + i, pl[j]);
+               }
+       }
+}
index b86462472a5d8b9ed572964e09b3017422d78515..a5a330cc3628006ee897cb4e7eea6f0017944240 100644 (file)
@@ -2601,8 +2601,7 @@ IO::setup_bundles_for_inputs_and_outputs ()
         _bundle_for_inputs->set_name (buf);
        uint32_t const ni = inputs().num_ports();
        for (uint32_t i = 0; i < ni; ++i) {
-               snprintf (buf, sizeof(buf), _("in %d"), (i + 1));
-               _bundle_for_inputs->add_channel (buf);
+               _bundle_for_inputs->add_channel (bundle_channel_name (i, ni));
                _bundle_for_inputs->set_port (i, _session.engine().make_port_name_non_relative (inputs().port(i)->name()));
        }
 
@@ -2610,8 +2609,7 @@ IO::setup_bundles_for_inputs_and_outputs ()
         _bundle_for_outputs->set_name (buf);
        uint32_t const no = outputs().num_ports();
        for (uint32_t i = 0; i < no; ++i) {
-               snprintf (buf, sizeof(buf), _("out %d"), (i + 1));
-               _bundle_for_outputs->add_channel (buf);
+               _bundle_for_outputs->add_channel (bundle_channel_name (i, no));
                _bundle_for_outputs->set_port (i, _session.engine().make_port_name_non_relative (outputs().port(i)->name()));
        }
 }
@@ -2725,3 +2723,21 @@ IO::flush_outputs (nframes_t nframes, nframes_t offset)
        }
                
 }
+
+std::string
+IO::bundle_channel_name (uint32_t c, uint32_t n) const
+{
+       char buf[32];
+       
+       switch (n) {
+       case 1:
+               return _("mono");
+       case 2:
+               return c == 0 ? _("L") : _("R");
+       default:
+               snprintf (buf, sizeof(buf), _("%d"), (c + 1));
+               return buf;
+       }
+
+       return "";
+}