enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / monitor_section.cc
index 0bc5b98bc72bcb315d696c364ad5d88ac4eccca5..2fcc5812b7d049494d30275283a10b7acd252059 100644 (file)
@@ -1,19 +1,19 @@
 /*
-    Copyright (C) 2012 Paul Davis
+  Copyright (C) 2012 Paul Davis
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 */
 
 #include "ardour/monitor_processor.h"
 #include "ardour/port.h"
 #include "ardour/route.h"
+#include "ardour/solo_isolate_control.h"
 #include "ardour/user_bundle.h"
 #include "ardour/plugin_manager.h"
 
+#include "ardour_ui.h"
 #include "gui_thread.h"
 #include "monitor_section.h"
 #include "public_editor.h"
@@ -47,7 +49,7 @@
 #include "ui_config.h"
 #include "utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace ARDOUR_UI_UTILS;
@@ -61,11 +63,11 @@ Glib::RefPtr<ActionGroup> MonitorSection::monitor_actions;
 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
 
 MonitorSection::MonitorSection (Session* s)
-       : AxisView (s)
+       : SessionHandlePtr (s)
        , RouteUI (s)
        , _tearoff (0)
        , channel_table_viewport (*channel_table_scroller.get_hadjustment()
-       , *channel_table_scroller.get_vadjustment ())
+                                 , *channel_table_scroller.get_vadjustment ())
        , gain_control (0)
        , dim_control (0)
        , solo_boost_control (0)
@@ -83,6 +85,8 @@ MonitorSection::MonitorSection (Session* s)
        , toggle_processorbox_button (ArdourButton::default_elements)
        , _inhibit_solo_model_update (false)
        , _ui_initialized (false)
+       , myactions (X_("monitor section"))
+       , bindings (0)
 {
 
        using namespace Menu_Helpers;
@@ -91,8 +95,10 @@ MonitorSection::MonitorSection (Session* s)
 
        if (!monitor_actions) {
                register_actions ();
-       } else {
-               connect_actions ();
+               load_bindings ();
+               if (bindings) {
+                       set_data ("ardour-bindings", bindings);
+               }
        }
 
        _plugin_selector = new PluginSelector (PluginManager::instance());
@@ -184,9 +190,8 @@ MonitorSection::MonitorSection (Session* s)
        toggle_processorbox_button.set_name (X_("monitor section processors toggle"));
        set_tooltip (&toggle_processorbox_button, _("Allow one to add monitor effect processors"));
 
-       proctoggle = ToggleAction::create ();
+       proctoggle = ActionManager::get_action (X_("Monitor"), X_("toggle-monitor-processor-box"));
        toggle_processorbox_button.set_related_action (proctoggle);
-       proctoggle->signal_toggled().connect (sigc::mem_fun(*this, &MonitorSection::update_processor_box), false);
 
        /* Knobs */
        Label* solo_boost_label;
@@ -390,7 +395,7 @@ MonitorSection::MonitorSection (Session* s)
        mono_dim_box->pack_start (mono_button, true, true);
        mono_dim_box->pack_end (dim_all_button, true, true);
 
-       // master gain 
+       // master gain
        Label* spin_label = manage (new Label (_("Monitor")));
        VBox* spin_packer = manage (new VBox);
        spin_packer->set_spacing (PX_SCALE(2));
@@ -407,7 +412,7 @@ MonitorSection::MonitorSection (Session* s)
        lower_packer->pack_start (*mono_dim_box,        false, false, PX_SCALE(2));
        lower_packer->pack_start (cut_all_button,       false, false, PX_SCALE(2));
 
-               // output port select
+       // output port select
        VBox* out_packer = manage (new VBox);
        out_packer->set_spacing (PX_SCALE(2));
        out_packer->pack_start (*output_label, false, false);
@@ -429,6 +434,8 @@ MonitorSection::MonitorSection (Session* s)
        hpacker.set_spacing (0);
        hpacker.pack_start (vpacker, true, true);
 
+       add (hpacker);
+
        gain_control->show_all ();
        gain_display->show_all ();
        dim_control->show_all ();
@@ -457,7 +464,11 @@ MonitorSection::MonitorSection (Session* s)
        output_button->signal_button_press_event().connect (sigc::mem_fun(*this, &MonitorSection::output_press), false);
        output_button->signal_button_release_event().connect (sigc::mem_fun(*this, &MonitorSection::output_release), false);
 
-       _tearoff = new TearOff (hpacker);
+       signal_enter_notify_event().connect (sigc::mem_fun (*this, &MonitorSection::enter_handler));
+       signal_leave_notify_event().connect (sigc::mem_fun (*this, &MonitorSection::leave_handler));
+       set_flags (CAN_FOCUS);
+
+       _tearoff = new TearOff (*this);
 
        if (!UIConfiguration::instance().get_floating_monitor_section()) {
                /* if torn off, make this a normal window
@@ -466,7 +477,7 @@ MonitorSection::MonitorSection (Session* s)
                _tearoff->tearoff_window().set_type_hint (Gdk::WINDOW_TYPE_HINT_NORMAL);
        }
        _tearoff->tearoff_window().set_title (X_("Monitor"));
-       _tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), (Gtk::Window*) 0), false);
+       _tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), (Gtk::Window*) &_tearoff->tearoff_window()), false);
 
        update_output_display ();
        update_processor_box ();
@@ -488,26 +499,55 @@ MonitorSection::~MonitorSection ()
        _channel_buttons.clear ();
        _output_changed_connection.disconnect ();
 
-       delete insert_box;
-       delete output_button;
-       delete gain_control;
-       delete gain_display;
-       delete dim_control;
-       delete dim_display;
-       delete solo_boost_control;
-       delete solo_boost_display;
-       delete solo_cut_control;
-       delete solo_cut_display;
-       delete _tearoff;
-       delete _output_selector;
-       _output_selector = 0;
+       delete insert_box; insert_box = 0;
+       delete output_button; output_button = 0;
+       delete gain_control; gain_control = 0;
+       delete gain_display; gain_display = 0;
+       delete dim_control; dim_control = 0;
+       delete dim_display; dim_display = 0;
+       delete solo_boost_control; solo_boost_control = 0;
+       delete solo_boost_display; solo_boost_display = 0;
+       delete solo_cut_control; solo_cut_control = 0;
+       delete solo_cut_display; solo_cut_display = 0;
+       delete _tearoff; _tearoff = 0;
+       delete _output_selector; _output_selector = 0;
 }
 
+bool
+MonitorSection::enter_handler (GdkEventCrossing* ev)
+{
+       grab_focus ();
+       return false;
+}
+
+bool
+MonitorSection::leave_handler (GdkEventCrossing* ev)
+{
+       switch (ev->detail) {
+       case GDK_NOTIFY_INFERIOR:
+               return false;
+       default:
+               break;
+       }
+
+       /* cancel focus if we're not torn off. With X11 WM's that do
+        * focus-follows-mouse, focus will be taken from us anyway.
+        */
+
+       Widget* top = get_toplevel();
+
+       if (top->is_toplevel() && top != &_tearoff->tearoff_window()) {
+               Window* win = dynamic_cast<Window*> (top);
+               gtk_window_set_focus (win->gobj(), 0);
+       }
+
+       return false;
+}
 
 void
 MonitorSection::update_processor_box ()
 {
-       bool show_processor_box = proctoggle->get_active ();
+       bool show_processor_box = Glib::RefPtr<ToggleAction>::cast_dynamic (proctoggle)->get_active ();
 
        if (count_processors () > 0 && !show_processor_box) {
                toggle_processorbox_button.set_name (X_("monitor section processors present"));
@@ -537,7 +577,7 @@ MonitorSection::update_processor_box ()
 void
 MonitorSection::set_session (Session* s)
 {
-       AxisView::set_session (s);
+       RouteUI::set_session (s);
        _plugin_selector->set_session (_session);
 
        if (_session) {
@@ -851,25 +891,25 @@ MonitorSection::register_actions ()
        string action_name;
        string action_descr;
        Glib::RefPtr<Action> act;
-       
-       monitor_actions = Actions.create_action_group (X_("Monitor"));
 
-       Actions.register_toggle_action (monitor_actions, "monitor-mono", _("Switch monitor to mono"),
+       monitor_actions = myactions.create_action_group (X_("Monitor"));
+
+       myactions.register_toggle_action (monitor_actions, "monitor-mono", _("Switch monitor to mono"),
                        sigc::mem_fun (*this, &MonitorSection::mono));
 
-       Actions.register_toggle_action (monitor_actions, "monitor-cut-all", _("Cut monitor"),
+       myactions.register_toggle_action (monitor_actions, "monitor-cut-all", _("Cut monitor"),
                        sigc::mem_fun (*this, &MonitorSection::cut_all));
 
-       Actions.register_toggle_action (monitor_actions, "monitor-dim-all", _("Dim monitor"),
+       myactions.register_toggle_action (monitor_actions, "monitor-dim-all", _("Dim monitor"),
                        sigc::mem_fun (*this, &MonitorSection::dim_all));
 
-       act = Actions.register_toggle_action (monitor_actions, "toggle-exclusive-solo", _("Toggle exclusive solo mode"),
+       act = myactions.register_toggle_action (monitor_actions, "toggle-exclusive-solo", _("Toggle exclusive solo mode"),
                        sigc::mem_fun (*this, &MonitorSection::toggle_exclusive_solo));
 
        Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
        tact->set_active (Config->get_exclusive_solo());
 
-       act = Actions.register_toggle_action (monitor_actions, "toggle-mute-overrides-solo", _("Toggle mute overrides solo mode"),
+       act = myactions.register_toggle_action (monitor_actions, "toggle-mute-overrides-solo", _("Toggle mute overrides solo mode"),
                        sigc::mem_fun (*this, &MonitorSection::toggle_mute_overrides_solo));
 
        tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
@@ -879,36 +919,39 @@ MonitorSection::register_actions ()
 
                action_name = string_compose (X_("monitor-cut-%1"), chn);
                action_descr = string_compose (_("Cut monitor channel %1"), chn);
-               Actions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
+               myactions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
                                sigc::bind (sigc::mem_fun (*this, &MonitorSection::cut_channel), chn));
 
                action_name = string_compose (X_("monitor-dim-%1"), chn);
                action_descr = string_compose (_("Dim monitor channel %1"), chn);
-               Actions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
+               myactions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
                                sigc::bind (sigc::mem_fun (*this, &MonitorSection::dim_channel), chn));
 
                action_name = string_compose (X_("monitor-solo-%1"), chn);
                action_descr = string_compose (_("Solo monitor channel %1"), chn);
-               Actions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
+               myactions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
                                sigc::bind (sigc::mem_fun (*this, &MonitorSection::solo_channel), chn));
 
                action_name = string_compose (X_("monitor-invert-%1"), chn);
                action_descr = string_compose (_("Invert monitor channel %1"), chn);
-               Actions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
+               myactions.register_toggle_action (monitor_actions, action_name.c_str(), action_descr.c_str(),
                                sigc::bind (sigc::mem_fun (*this, &MonitorSection::invert_channel), chn));
 
        }
 
 
-       Glib::RefPtr<ActionGroup> solo_actions = Actions.create_action_group (X_("Solo"));
+       Glib::RefPtr<ActionGroup> solo_actions = myactions.create_action_group (X_("Solo"));
        RadioAction::Group solo_group;
 
-       Actions.register_radio_action (solo_actions, solo_group, "solo-use-in-place", _("In-place solo"),
+       myactions.register_radio_action (solo_actions, solo_group, "solo-use-in-place", _("In-place solo"),
                        sigc::mem_fun (*this, &MonitorSection::solo_use_in_place));
-       Actions.register_radio_action (solo_actions, solo_group, "solo-use-afl", _("After Fade Listen (AFL) solo"),
+       myactions.register_radio_action (solo_actions, solo_group, "solo-use-afl", _("After Fade Listen (AFL) solo"),
                        sigc::mem_fun (*this, &MonitorSection::solo_use_afl));
-       Actions.register_radio_action (solo_actions, solo_group, "solo-use-pfl", _("Pre Fade Listen (PFL) solo"),
+       myactions.register_radio_action (solo_actions, solo_group, "solo-use-pfl", _("Pre Fade Listen (PFL) solo"),
                        sigc::mem_fun (*this, &MonitorSection::solo_use_pfl));
+
+       myactions.register_toggle_action (monitor_actions, "toggle-monitor-processor-box", _("Toggle Monitor Section Processor Box"),
+                       sigc::mem_fun(*this, &MonitorSection::update_processor_box));
 }
 
 void
@@ -1204,7 +1247,7 @@ MonitorSection::cancel_isolate (GdkEventButton*)
 {
        if (_session) {
                boost::shared_ptr<RouteList> rl (_session->get_routes ());
-               _session->set_solo_isolated (rl, false, Session::rt_cleanup, Controllable::NoGroup);
+               _session->set_controls (route_list_to_control_list (rl, &Stripable::solo_isolate_control), 0.0, Controllable::NoGroup);
        }
 
        return true;
@@ -1624,6 +1667,12 @@ MonitorSection::port_connected_or_disconnected (boost::weak_ptr<Port> wa, boost:
        }
 }
 
+void
+MonitorSection::load_bindings ()
+{
+       bindings = Bindings::get_bindings (X_("Monitor Section"), myactions);
+}
+
 void
 MonitorSection::help_count_processors (boost::weak_ptr<Processor> p, uint32_t* cnt) const
 {
@@ -1652,3 +1701,4 @@ MonitorSection::processors_changed (ARDOUR::RouteProcessorChange)
 {
        update_processor_box ();
 }
+