Oops. Fix XML stuff in GUI as well.
[ardour.git] / gtk2_ardour / mixer_strip.cc
index 68b53da86c32f5025bb8009a6f695232fe82d574..39e23a99a4d708235bc4689edc819a0afaf9bb60 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <pbd/convert.h>
 #include <pbd/enumwriter.h>
+#include <pbd/replace_all.h>
 
 #include <gtkmm2ext/gtk_ui.h>
 #include <gtkmm2ext/utils.h>
@@ -36,6 +37,7 @@
 #include <ardour/session.h>
 #include <ardour/audioengine.h>
 #include <ardour/route.h>
+#include <ardour/route_group.h>
 #include <ardour/audio_track.h>
 #include <ardour/audio_diskstream.h>
 #include <ardour/panner.h>
@@ -43,7 +45,6 @@
 #include <ardour/processor.h>
 #include <ardour/profile.h>
 #include <ardour/ladspa_plugin.h>
-#include <ardour/auto_bundle.h>
 #include <ardour/user_bundle.h>
 
 #include "ardour_ui.h"
@@ -154,16 +155,18 @@ MixerStrip::init ()
        hide_button.add (*img);
 
        input_label.set_text (_("Input"));
-       ARDOUR_UI::instance()->set_tip (&input_button, _("Click to choose inputs"), "");
+       ARDOUR_UI::instance()->set_tip (&input_button, _("Button 1 to choose inputs from a port matrix, button 3 to select inputs from a menu"), "");
        input_button.add (input_label);
        input_button.set_name ("MixerIOButton");
        input_label.set_name ("MixerIOButtonLabel");
+       Gtkmm2ext::set_size_request_to_display_given_text (input_button, "longest label", 4, 4);
 
        output_label.set_text (_("Output"));
-       ARDOUR_UI::instance()->set_tip (&output_button, _("Click to choose outputs"), "");
+       ARDOUR_UI::instance()->set_tip (&output_button, _("Button 1 to choose outputs from a port matrix, button 3 to select inputs from a menu"), "");
        output_button.add (output_label);
        output_button.set_name ("MixerIOButton");
        output_label.set_name ("MixerIOButtonLabel");
+       Gtkmm2ext::set_size_request_to_display_given_text (output_button, "longest label", 4, 4);
 
        ARDOUR_UI::instance()->set_tip (&meter_point_button, _("Select metering point"), "");
        meter_point_button.add (meter_point_label);
@@ -323,15 +326,11 @@ MixerStrip::set_route (boost::shared_ptr<Route> rt)
 
        RouteUI::set_route (rt);
 
-       if (input_selector) {
-               delete input_selector;
-               input_selector = 0;
-       }
+       delete input_selector;
+       input_selector = 0;
 
-       if (output_selector) {
-               delete output_selector;
-               output_selector = 0;
-       }
+       delete output_selector;
+       output_selector = 0;
 
        panners.set_io (rt);
        gpm.set_io (rt);
@@ -625,25 +624,38 @@ MixerStrip::output_press (GdkEventButton *ev)
        switch (ev->button) {
 
        case 1:
+               edit_output_configuration ();
+               break;
+               
+       case 3:
        {
                output_menu.set_name ("ArdourContextMenu");
                citems.clear();
                
-               citems.push_back (MenuElem (_("Edit"), mem_fun(*this, &MixerStrip::edit_output_configuration)));
-               citems.push_back (SeparatorElem());
                citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_output)));
                citems.push_back (SeparatorElem());
 
-               std::vector<boost::shared_ptr<Bundle> > current = _route->bundles_connected_to_outputs ();
+               ARDOUR::BundleList current = _route->bundles_connected_to_outputs ();
+
+               boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
+               for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
+                       maybe_add_bundle_to_output_menu (*i, current);
+               }
 
-               _session.foreach_bundle (
-                       bind (mem_fun (*this, &MixerStrip::add_bundle_to_output_menu), current)
-                       );
+               boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes ();
+               for (ARDOUR::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
+                       maybe_add_bundle_to_output_menu ((*i)->bundle_for_inputs(), current);
+               }
+
+               if (citems.size() == 2) {
+                       /* no routes added; remove the separator */
+                       citems.pop_back ();
+               }
 
                output_menu.popup (1, ev->time);
                break;
        }
-               
+
        default:
                break;
        }
@@ -696,17 +708,30 @@ MixerStrip::input_press (GdkEventButton *ev)
        switch (ev->button) {
 
        case 1:
+               edit_input_configuration ();
+               break;
+
+       case 3:
        {
-               citems.push_back (MenuElem (_("Edit"), mem_fun(*this, &MixerStrip::edit_input_configuration)));
-               citems.push_back (SeparatorElem());
                citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_input)));
                citems.push_back (SeparatorElem());
 
-               std::vector<boost::shared_ptr<Bundle> > current = _route->bundles_connected_to_inputs ();
+               ARDOUR::BundleList current = _route->bundles_connected_to_inputs ();
 
-               _session.foreach_bundle (
-                       bind (mem_fun (*this, &MixerStrip::add_bundle_to_input_menu), current)
-                       );
+               boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
+               for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
+                       maybe_add_bundle_to_input_menu (*i, current);
+               }
+
+               boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes ();
+               for (ARDOUR::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
+                       maybe_add_bundle_to_input_menu ((*i)->bundle_for_outputs(), current);
+               }
+
+               if (citems.size() == 2) {
+                       /* no routes added; remove the separator */
+                       citems.pop_back ();
+               }
 
                input_menu.popup (1, ev->time);
                break;
@@ -718,83 +743,86 @@ MixerStrip::input_press (GdkEventButton *ev)
 }
 
 void
-MixerStrip::bundle_input_chosen (boost::shared_ptr<ARDOUR::Bundle> c)
+MixerStrip::bundle_input_toggled (boost::shared_ptr<ARDOUR::Bundle> c)
 {
-       if (!ignore_toggle) {
+       if (ignore_toggle) {
+               return;
+       }
 
-               try { 
-                       _route->connect_input_ports_to_bundle (c, this);
-               }
+       ARDOUR::BundleList current = _route->bundles_connected_to_inputs ();
 
-               catch (AudioEngine::PortRegistrationFailure& err) {
-                       error << _("could not register new ports required for that bundle")
-                             << endmsg;
-               }
+       if (std::find (current.begin(), current.end(), c) == current.end()) {
+               _route->connect_input_ports_to_bundle (c, this);
+       } else {
+               _route->disconnect_input_ports_from_bundle (c, this);
        }
 }
 
 void
-MixerStrip::bundle_output_chosen (boost::shared_ptr<ARDOUR::Bundle> c)
+MixerStrip::bundle_output_toggled (boost::shared_ptr<ARDOUR::Bundle> c)
 {
-       if (!ignore_toggle) {
+       if (ignore_toggle) {
+               return;
+       }
 
-               try { 
-                       _route->connect_output_ports_to_bundle (c, this);
-               }
+       ARDOUR::BundleList current = _route->bundles_connected_to_outputs ();
 
-               catch (AudioEngine::PortRegistrationFailure& err) {
-                       error << _("could not register new ports required for that bundle")
-                             << endmsg;
-               }
+       if (std::find (current.begin(), current.end(), c) == current.end()) {
+               _route->connect_output_ports_to_bundle (c, this);
+       } else {
+               _route->disconnect_output_ports_from_bundle (c, this);
        }
 }
 
 void
-MixerStrip::add_bundle_to_input_menu (boost::shared_ptr<Bundle> b, std::vector<boost::shared_ptr<Bundle> > const & current)
+MixerStrip::maybe_add_bundle_to_input_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const & current)
 {
        using namespace Menu_Helpers;
 
-       /* the input menu needs to contain only output bundles (that we
-          can connect inputs to */
-       if (b->ports_are_outputs() == false) {
+       if (b->ports_are_outputs() == false ||
+           route()->default_type() != b->type() ||
+           b->nchannels() != _route->n_inputs().get (b->type ())) {
+               
                return;
        }
 
        MenuList& citems = input_menu.items();
        
-       if (b->nchannels() == _route->n_inputs()) {
-
-               citems.push_back (CheckMenuElem (b->name(), bind (mem_fun(*this, &MixerStrip::bundle_input_chosen), b)));
-
-               if (std::find (current.begin(), current.end(), b) != current.end()) {
-                       ignore_toggle = true;
-                       dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
-                       ignore_toggle = false;
-               }
+       std::string n = b->name ();
+       replace_all (n, "_", " ");
+       
+       citems.push_back (CheckMenuElem (n, bind (mem_fun(*this, &MixerStrip::bundle_input_toggled), b)));
+       
+       if (std::find (current.begin(), current.end(), b) != current.end()) {
+               ignore_toggle = true;
+               dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
+               ignore_toggle = false;
        }
 }
 
 void
-MixerStrip::add_bundle_to_output_menu (boost::shared_ptr<Bundle> b, std::vector<boost::shared_ptr<Bundle> > const & current)
+MixerStrip::maybe_add_bundle_to_output_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const & current)
 {
        using namespace Menu_Helpers;
 
-       /* the output menu needs to contain only input bundles (that we
-          can connect outputs to */
-       if (b->ports_are_inputs() == false) {
+       if (b->ports_are_inputs() == false ||
+           route()->default_type() != b->type() ||
+           b->nchannels() != _route->n_outputs().get (b->type ())) {
+               
                return;
        }
 
-       if (b->nchannels() == _route->n_outputs()) {
-
-               MenuList& citems = output_menu.items();
-               citems.push_back (CheckMenuElem (b->name(), bind (mem_fun(*this, &MixerStrip::bundle_output_chosen), b)));
-               
-               if (std::find (current.begin(), current.end(), b) != current.end()) {
-                       ignore_toggle = true;
-                       dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
-                       ignore_toggle = false;
-               }
+       MenuList& citems = output_menu.items();
+       
+       std::string n = b->name ();
+       replace_all (n, "_", " ");
+       
+       citems.push_back (CheckMenuElem (n, bind (mem_fun(*this, &MixerStrip::bundle_output_toggled), b)));
+       
+       if (std::find (current.begin(), current.end(), b) != current.end()) {
+               ignore_toggle = true;
+               dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
+               ignore_toggle = false;
        }
 }
 
@@ -838,11 +866,12 @@ MixerStrip::connect_to_pan ()
 void
 MixerStrip::update_input_display ()
 {
-       std::vector<boost::shared_ptr<ARDOUR::Bundle> > c = _route->bundles_connected_to_inputs ();
+       ARDOUR::BundleList const c = _route->bundles_connected_to_inputs ();
 
-       /* XXX: how do we represent >1 connected bundle? */
-       if (c.empty() == false) {
-               input_label.set_text (c[0]->name());
+       if (c.size() > 1) {
+               input_label.set_text (_("Inputs"));
+       } else if (c.size() == 1) {
+               input_label.set_text (c[0]->name ());
        } else {
                switch (_width) {
                case Wide:
@@ -859,10 +888,12 @@ MixerStrip::update_input_display ()
 void
 MixerStrip::update_output_display ()
 {
-       std::vector<boost::shared_ptr<ARDOUR::Bundle> > c = _route->bundles_connected_to_outputs ();
+       ARDOUR::BundleList const c = _route->bundles_connected_to_outputs ();
 
        /* XXX: how do we represent >1 connected bundle? */
-       if (c.empty() == false) {
+       if (c.size() > 1) {
+               output_label.set_text (_("Outputs"));
+       } else if (c.size() == 1) {
                output_label.set_text (c[0]->name());
        } else {
                switch (_width) {