finalize fix for MIDI track monitoring
[ardour.git] / gtk2_ardour / monitor_section.cc
index bd12ad306b7e5d6e6be471c1f299bbf438de42f1..359ce0c7963370814563f634211a359d84922ce3 100644 (file)
@@ -8,10 +8,8 @@
 #include "gtkmm2ext/actions.h"
 #include "gtkmm2ext/motionfeedback.h"
 
-#include "ardour/dB.h"
 #include "ardour/monitor_processor.h"
 #include "ardour/route.h"
-#include "ardour/utils.h"
 
 #include "ardour_ui.h"
 #include "gui_thread.h"
@@ -36,18 +34,18 @@ MonitorSection::MonitorSection (Session* s)
         : AxisView (s)
         , RouteUI (s)
         , _tearoff (0)
+       , channel_table_viewport (*channel_table_scroller.get_hadjustment(),
+                                 *channel_table_scroller.get_vadjustment ())
         , gain_control (0)
         , dim_control (0)
         , solo_boost_control (0)
         , solo_cut_control (0)
-        , solo_in_place_button (solo_model_group, _("SiP"))
-        , afl_button (solo_model_group, _("AFL"))
-        , pfl_button (solo_model_group, _("PFL"))
-       , cut_all_button (ArdourButton::led_default_elements)
-       , dim_all_button (ArdourButton::led_default_elements)
-       , mono_button (ArdourButton::led_default_elements)
+        , solo_in_place_button (_("SiP"), ArdourButton::led_default_elements)
+        , afl_button (_("AFL"), ArdourButton::led_default_elements)
+       , pfl_button (_("PFL"), ArdourButton::led_default_elements)
        , exclusive_solo_button (ArdourButton::led_default_elements)
        , solo_mute_override_button (ArdourButton::led_default_elements)
+       , _inhibit_solo_model_update (false)
 {
         Glib::RefPtr<Action> act;
 
@@ -89,6 +87,10 @@ MonitorSection::MonitorSection (Session* s)
        rude_audition_button.signal_button_press_event().connect (sigc::mem_fun(*this, &MonitorSection::cancel_audition));
         UI::instance()->set_tip (rude_audition_button, _("When active, auditioning is active.\nClick to stop the audition"));
 
+       solo_in_place_button.set_name ("monitor section solo model");
+       afl_button.set_name ("monitor section solo model");
+       pfl_button.set_name ("monitor section solo model");
+
         solo_model_box.set_spacing (6);
         solo_model_box.pack_start (solo_in_place_button, true, false);
         solo_model_box.pack_start (afl_button, true, false);
@@ -102,19 +104,19 @@ MonitorSection::MonitorSection (Session* s)
         act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
        ARDOUR_UI::instance()->tooltips().set_tip (solo_in_place_button, _("Solo controls affect solo-in-place"));
         if (act) {
-                act->connect_proxy (solo_in_place_button);
+               solo_in_place_button.set_related_action (act);
         }
 
         act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
        ARDOUR_UI::instance()->tooltips().set_tip (afl_button, _("Solo controls toggle after-fader-listen"));
         if (act) {
-                act->connect_proxy (afl_button);
+               afl_button.set_related_action (act);
         }
 
         act = ActionManager::get_action (X_("Solo"), X_("solo-use-pfl"));
        ARDOUR_UI::instance()->tooltips().set_tip (pfl_button, _("Solo controls toggle pre-fader-listen"));
         if (act) {
-                act->connect_proxy (pfl_button);
+               pfl_button.set_related_action (act);
         }
 
         /* Solo Boost */
@@ -212,7 +214,7 @@ MonitorSection::MonitorSection (Session* s)
         act = ActionManager::get_action (X_("Monitor"), X_("monitor-cut-all"));
         if (act) {
                cut_all_button.set_related_action (act);
-        }
+       }
 
        dim_all_button.set_text (_("dim"));
        dim_all_button.set_name ("monitor section dim");
@@ -255,7 +257,8 @@ MonitorSection::MonitorSection (Session* s)
        channel_table_scroller.set_size_request (-1, 150);
        channel_table_scroller.set_shadow_type (Gtk::SHADOW_NONE);
        channel_table_scroller.show ();
-       
+       channel_table_scroller.add (channel_table_viewport);
+
        channel_size_group  = SizeGroup::create (SIZE_GROUP_HORIZONTAL);
        channel_size_group->add_widget (channel_table_header);
        channel_size_group->add_widget (channel_table);
@@ -264,7 +267,7 @@ MonitorSection::MonitorSection (Session* s)
         Label* l1 = manage (new Label (X_("out")));
        l1->set_name (X_("MonitorSectionLabel"));
         channel_table_header.attach (*l1, 0, 1, 0, 1, EXPAND|FILL);
-        l1 = manage (new Label (X_("cut")));
+        l1 = manage (new Label (X_("mute")));
        l1->set_name (X_("MonitorSectionLabel"));
         channel_table_header.attach (*l1, 1, 2, 0, 1, EXPAND|FILL);
         l1 = manage (new Label (X_("dim")));
@@ -316,7 +319,7 @@ MonitorSection::MonitorSection (Session* s)
 
         /* catch changes that affect us */
 
-        Config->ParameterChanged.connect (config_connection, invalidator (*this), ui_bind (&MonitorSection::parameter_changed, this, _1), gui_context());
+        Config->ParameterChanged.connect (config_connection, invalidator (*this), boost::bind (&MonitorSection::parameter_changed, this, _1), gui_context());
 }
 
 MonitorSection::~MonitorSection ()
@@ -355,23 +358,24 @@ MonitorSection::set_session (Session* s)
                if (channel_table_scroller.get_parent()) {
                        /* scroller is packed, so remove it */
                        channel_table_packer.remove (channel_table_scroller);
-                       /* remove the table_hpacker from the scroller */
-                       channel_table_scroller.remove ();
                } 
 
-               if (table_hpacker.get_parent ()) {
+               if (table_hpacker.get_parent () == &channel_table_packer) {
                        /* this occurs when the table hpacker is directly
                           packed, so remove it.
                        */
                        channel_table_packer.remove (table_hpacker);
+               } else if (table_hpacker.get_parent()) {
+                       channel_table_viewport.remove ();
                }
                
                if (_monitor->output_streams().n_audio() > 7) {
                        /* put the table into a scrolled window, and then put
                         * that into the channel vpacker, after the table header
                         */
-                       channel_table_scroller.add (table_hpacker);
+                       channel_table_viewport.add (table_hpacker);
                        channel_table_packer.pack_start (channel_table_scroller, true, true);
+                       channel_table_viewport.show ();
                        channel_table_scroller.show ();
 
                } else {
@@ -400,10 +404,6 @@ MonitorSection::set_session (Session* s)
 }
 
 MonitorSection::ChannelButtonSet::ChannelButtonSet ()
-       : cut (ArdourButton::just_led_default_elements)
-       , dim (ArdourButton::just_led_default_elements)
-       , solo (ArdourButton::just_led_default_elements)
-       , invert (ArdourButton::just_led_default_elements)
 {
        cut.set_diameter (3);
        dim.set_diameter (3);
@@ -495,14 +495,6 @@ MonitorSection::populate_buttons ()
         channel_table.show_all ();
 }
 
-void
-MonitorSection::set_button_names ()
-{
-        rec_enable_button_label.set_text ("rec");
-        mute_button_label.set_text ("rec");
-        solo_button_label.set_text ("rec");
-}
-
 void
 MonitorSection::toggle_exclusive_solo ()
 {
@@ -559,7 +551,7 @@ MonitorSection::cut_all ()
         if (act) {
                Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
                 _monitor->set_cut_all (tact->get_active());
-        }
+       }
 }
 
 void
@@ -739,7 +731,16 @@ MonitorSection::solo_use_in_place ()
         if (act) {
                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
                 if (ract) {
+                       if (!ract->get_active ()) {
+                               /* We are turning SiP off, which means that AFL or PFL will be turned on
+                                  shortly; don't update the solo model in the mean time, as if the currently
+                                  configured listen position is not the one that is about to be turned on,
+                                  things will go wrong.
+                               */
+                               _inhibit_solo_model_update = true;
+                       }
                         Config->set_solo_control_is_listen_control (!ract->get_active());
+                       _inhibit_solo_model_update = false;
                 }
         }
 }
@@ -757,8 +758,8 @@ MonitorSection::solo_use_afl ()
                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
                 if (ract) {
                         if (ract->get_active()) {
-                                Config->set_listen_position (AfterFaderListen);
                                 Config->set_solo_control_is_listen_control (true);
+                                Config->set_listen_position (AfterFaderListen);
                         }
                 }
         }
@@ -772,13 +773,13 @@ MonitorSection::solo_use_pfl ()
           active.
        */
 
-        Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
+        Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-pfl"));
         if (act) {
                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
                 if (ract) {
                         if (ract->get_active()) {
-                                Config->set_listen_position (PreFaderListen);
                                 Config->set_solo_control_is_listen_control (true);
+                                Config->set_listen_position (PreFaderListen);
                         }
                 }
         }
@@ -826,6 +827,10 @@ MonitorSection::setup_knob_images ()
 void
 MonitorSection::update_solo_model ()
 {
+       if (_inhibit_solo_model_update) {
+               return;
+       }
+       
         const char* action_name = 0;
         Glib::RefPtr<Action> act;
 
@@ -844,10 +849,19 @@ MonitorSection::update_solo_model ()
 
         act = ActionManager::get_action (X_("Solo"), action_name);
         if (act) {
+
                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
                 if (ract) {
+                       /* because these are radio buttons, one of them will be
+                          active no matter what. to trigger a change in the
+                          action so that the view picks it up, toggle it.
+                       */
+                       if (ract->get_active()) {
+                               ract->set_active (false);
+                       }
                         ract->set_active (true);
                 }
+               
         }
 }
 
@@ -947,13 +961,9 @@ MonitorSection::audition_blink (bool onoff)
        }
 
        if (_session->is_auditioning()) {
-               if (onoff) {
-                       rude_audition_button.set_active_state (Gtkmm2ext::Active);
-               } else {
-                       rude_audition_button.unset_active_state ();
-               }
+               rude_audition_button.set_active (onoff);
        } else {
-               rude_audition_button.unset_active_state ();
+               rude_audition_button.set_active (false);
        }
 }
 
@@ -965,22 +975,17 @@ MonitorSection::solo_blink (bool onoff)
        }
 
        if (_session->soloing() || _session->listening()) {
-               if (onoff) {
-                       rude_solo_button.set_active_state (Gtkmm2ext::Active);
-               } else {
-                       rude_solo_button.unset_active_state ();
-               }
+               rude_solo_button.set_active (onoff);
 
                 if (_session->soloing()) {
                        if (_session->solo_isolated()) {
-                               rude_iso_button.set_active_state (Gtkmm2ext::Active);
+                               rude_iso_button.set_active (false);
                        }
-                }
+               }
 
        } else {
-               // rude_solo_button.set_active (false);
-               rude_solo_button.unset_active_state ();
-                rude_iso_button.unset_active_state ();
+               rude_solo_button.set_active (false);
+                rude_iso_button.set_active (false);
        }
 }
 
@@ -1021,8 +1026,9 @@ MonitorSection::cancel_audition (GdkEventButton*)
 void
 MonitorSection::parameter_changed (std::string name)
 {
-        if (name == "solo-control-is-listen-control" ||
-            name == "listen-position") {
+        if (name == "solo-control-is-listen-control") {
+                update_solo_model ();
+       } else if (name == "listen-position") {
                 update_solo_model ();
         }
 }