first compiling, mostly working version of group controls changes
[ardour.git] / gtk2_ardour / ardour_ui_dialogs.cc
index 2cfa27cbb241b7c919d019e3150bc17df4576e7e..859a1678327ee0797fad09fe06529b476e0f7bd7 100644 (file)
    This is to cut down on the compile times.  It also helps with my sanity.
 */
 
-#include "ardour/session.h"
 #include "ardour/audioengine.h"
 #include "ardour/automation_watch.h"
-
-#ifdef interface
-#undef interface
-#endif
+#include "ardour/control_protocol_manager.h"
+#include "ardour/profile.h"
+#include "ardour/session.h"
+#include "control_protocol/control_protocol.h"
 
 #include "actions.h"
 #include "add_route_dialog.h"
@@ -43,6 +42,7 @@
 #include "keyeditor.h"
 #include "location_ui.h"
 #include "main_clock.h"
+#include "meterbridge.h"
 #include "meter_patterns.h"
 #include "midi_tracer.h"
 #include "mixer_ui.h"
@@ -56,6 +56,7 @@
 #include "sfdb_ui.h"
 #include "theme_manager.h"
 #include "time_info_box.h"
+#include "timers.h"
 
 #include <gtkmm2ext/keyboard.h>
 
@@ -146,12 +147,9 @@ ARDOUR_UI::set_session (Session *s)
 
        setup_session_options ();
 
-       Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
-       Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::solo_blink));
-       Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::sync_blink));
-       Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::audition_blink));
-       Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::feedback_blink));
+       blink_connection = Timers::blink_connect (sigc::mem_fun(*this, &ARDOUR_UI::blink_handler));
 
+       _session->SaveSessionRequested.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::save_session_at_its_request, this, _1), gui_context());
        _session->RecordStateChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::record_state_changed, this), gui_context());
        _session->StepEditStatusChange.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::step_edit_status_change, this, _1), gui_context());
        _session->TransportStateChange.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::map_transport_state, this), gui_context());
@@ -179,13 +177,13 @@ ARDOUR_UI::set_session (Session *s)
        Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::first_idle));
 
        start_clocking ();
-       start_blinking ();
 
        map_transport_state ();
 
-       second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_second), 1000);
-       point_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
-       point_zero_something_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_zero_something_seconds), 40);
+       second_connection = Timers::second_connect (sigc::mem_fun(*this, &ARDOUR_UI::every_second));
+       point_one_second_connection = Timers::rapid_connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_one_seconds));
+       point_zero_something_second_connection = Timers::super_rapid_connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_zero_something_seconds));
+       set_fps_timeout_connection();
 
        update_format ();
 
@@ -206,32 +204,33 @@ ARDOUR_UI::set_session (Session *s)
                transport_tearoff_hbox.remove (editor_meter_peak_display);
        }
 
-       if (_session && 
-           _session->master_out() && 
+       if (_session &&
+           _session->master_out() &&
            _session->master_out()->n_outputs().n(DataType::AUDIO) > 0) {
 
-               editor_meter = new LevelMeterHBox(_session);
-               editor_meter->set_meter (_session->master_out()->shared_peak_meter().get());
-               editor_meter->clear_meters();
-               editor_meter->set_type (_session->master_out()->meter_type());
-               editor_meter->setup_meters (30, 12, 6);
-               editor_meter->show();
-               meter_box.pack_start(*editor_meter);
+               if (!ARDOUR::Profile->get_trx()) {
+                       editor_meter = new LevelMeterHBox(_session);
+                       editor_meter->set_meter (_session->master_out()->shared_peak_meter().get());
+                       editor_meter->clear_meters();
+                       editor_meter->set_type (_session->master_out()->meter_type());
+                       editor_meter->setup_meters (30, 12, 6);
+                       editor_meter->show();
+                       meter_box.pack_start(*editor_meter);
+               }
 
                ArdourMeter::ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &ARDOUR_UI::reset_peak_display));
                ArdourMeter::ResetRoutePeakDisplays.connect (sigc::mem_fun(*this, &ARDOUR_UI::reset_route_peak_display));
                ArdourMeter::ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &ARDOUR_UI::reset_group_peak_display));
 
                editor_meter_peak_display.set_name ("meterbridge peakindicator");
-               editor_meter_peak_display.set_elements((ArdourButton::Element) (ArdourButton::Edge|ArdourButton::Body));
                editor_meter_peak_display.unset_flags (Gtk::CAN_FOCUS);
-               editor_meter_peak_display.set_size_request(6, -1);
-               editor_meter_peak_display.set_corner_radius(2);
+               editor_meter_peak_display.set_size_request (std::max(9.f, rintf(8.f * UIConfiguration::instance().get_ui_scale())), -1);
+               editor_meter_peak_display.set_corner_radius (3.0);
 
                editor_meter_max_peak = -INFINITY;
                editor_meter_peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::editor_meter_peak_button_release), false);
 
-               if (Config->get_show_editor_meter()) {
+               if (UIConfiguration::instance().get_show_editor_meter() && !ARDOUR::Profile->get_trx()) {
                        transport_tearoff_hbox.pack_start (meter_box, false, false);
                        transport_tearoff_hbox.pack_start (editor_meter_peak_display, false, false);
                        meter_box.show();
@@ -263,11 +262,20 @@ ARDOUR_UI::unload_session (bool hide_stuff)
                }
        }
 
+       {
+               // tear down session specific CPI (owned by rc_config_editor which can remain)
+               ControlProtocolManager& m = ControlProtocolManager::instance ();
+               for (std::list<ControlProtocolInfo*>::iterator i = m.control_protocol_info.begin(); i != m.control_protocol_info.end(); ++i) {
+                       if (*i && (*i)->protocol && (*i)->protocol->has_editor ()) {
+                               (*i)->protocol->tear_down_gui ();
+                       }
+               }
+       }
+
        if (hide_stuff) {
                editor->hide ();
                mixer->hide ();
                meterbridge->hide ();
-               theme_manager->hide ();
                audio_port_matrix->hide();
                midi_port_matrix->hide();
                route_params->hide();
@@ -276,6 +284,7 @@ ARDOUR_UI::unload_session (bool hide_stuff)
        second_connection.disconnect ();
        point_one_second_connection.disconnect ();
        point_zero_something_second_connection.disconnect();
+       fps_connection.disconnect();
 
        if (editor_meter) {
                meter_box.remove(*editor_meter);
@@ -294,12 +303,11 @@ ARDOUR_UI::unload_session (bool hide_stuff)
                ARDOUR_UI::instance()->video_timeline->close_session();
        }
 
-       stop_blinking ();
        stop_clocking ();
 
        /* drop everything attached to the blink signal */
 
-       Blink.clear ();
+       blink_connection.disconnect ();
 
        delete _session;
        _session = 0;
@@ -329,7 +337,9 @@ ARDOUR_UI::goto_editor_window ()
        editor->show_window ();
        editor->present ();
        /* mixer should now be on top */
-       WM::Manager::instance().set_transient_for (editor);
+       if (UIConfiguration::instance().get_transients_follow_front()) {
+               WM::Manager::instance().set_transient_for (editor);
+       }
        _mixer_on_top = false;
 }
 
@@ -338,7 +348,7 @@ ARDOUR_UI::goto_mixer_window ()
 {
        Glib::RefPtr<Gdk::Window> win;
        Glib::RefPtr<Gdk::Screen> screen;
-       
+
        if (editor) {
                win = editor->get_window ();
        }
@@ -348,7 +358,7 @@ ARDOUR_UI::goto_mixer_window ()
        } else {
                screen = Gdk::Screen::get_default();
        }
-       
+
        if (g_getenv ("ARDOUR_LOVES_STUPID_TINY_SCREENS") == 0 && screen && screen->get_height() < 700) {
                Gtk::MessageDialog msg (_("This screen is not tall enough to display the mixer window"));
                msg.run ();
@@ -358,21 +368,37 @@ ARDOUR_UI::goto_mixer_window ()
        mixer->show_window ();
        mixer->present ();
        /* mixer should now be on top */
-       WM::Manager::instance().set_transient_for (mixer);
+       if (UIConfiguration::instance().get_transients_follow_front()) {
+               WM::Manager::instance().set_transient_for (mixer);
+       }
        _mixer_on_top = true;
 }
 
 void
 ARDOUR_UI::toggle_mixer_window ()
 {
-       Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-mixer"));
-       if (!act) {
-               return;
+       /* thse windows are created in ARDOUR_UI::setup_windows()
+        * it should be impossible to get here with any of them being NULL
+        */
+       assert (editor && mixer && meterbridge);
+
+       bool show = false;
+       bool obscuring = false;
+
+       if (mixer->not_visible ()) {
+               show = true;
+       }
+       else if (   (!editor->not_visible () && ARDOUR_UI_UTILS::windows_overlap (editor, mixer))
+                || (!meterbridge->not_visible () && ARDOUR_UI_UTILS::windows_overlap (meterbridge, mixer))
+                       ) {
+               obscuring = true;
        }
 
-       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+       if (obscuring && (editor->property_has_toplevel_focus() || meterbridge->property_has_toplevel_focus())) {
+               show = true;
+       }
 
-       if (tact->get_active()) {
+       if (show) {
                goto_mixer_window ();
        } else {
                mixer->hide ();
@@ -382,15 +408,28 @@ ARDOUR_UI::toggle_mixer_window ()
 void
 ARDOUR_UI::toggle_meterbridge ()
 {
-       Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-meterbridge"));
-       if (!act) {
-               return;
+       assert (editor && mixer && meterbridge);
+
+       bool show = false;
+       bool obscuring = false;
+
+       if (meterbridge->not_visible ()) {
+               show = true;
+       }
+       else if (   (!editor->not_visible() && ARDOUR_UI_UTILS::windows_overlap (editor, meterbridge))
+                || (!mixer->not_visible () && ARDOUR_UI_UTILS::windows_overlap (meterbridge, mixer))
+                       ) {
+               obscuring = true;
        }
 
-       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+       if (obscuring && (editor->property_has_toplevel_focus() || mixer->property_has_toplevel_focus())) {
+               show = true;
+       }
 
-       if (tact->get_active()) {
+       if (show) {
                meterbridge->show_window ();
+               meterbridge->present ();
+               meterbridge->raise ();
        } else {
                meterbridge->hide_window (NULL);
        }
@@ -400,79 +439,37 @@ void
 ARDOUR_UI::toggle_editor_mixer ()
 {
        bool obscuring = false;
-       /* currently, if windows are on different
-          screens then we do nothing; but in the
-          future we may want to bring the window 
-          to the front or something, so I'm leaving this 
-          variable for future use
-       */
-        bool same_screen = true; 
-       
-        if (editor && mixer) {
-
-               /* remeber: Screen != Monitor (Screen is a separately rendered
-                * continuous geometry that make include 1 or more monitors.
-                */
-               
-                if (editor->get_screen() != mixer->get_screen() && (mixer->get_screen() != 0) && (editor->get_screen() != 0)) {
-                        // different screens, so don't do anything
-                        same_screen = false;
-                } else {
-                        // they are on the same screen, see if they are obscuring each other
-
-                        gint ex, ey, ew, eh;
-                        gint mx, my, mw, mh;
-
-                        editor->get_position (ex, ey);
-                        editor->get_size (ew, eh);
-
-                        mixer->get_position (mx, my);
-                        mixer->get_size (mw, mh);
-
-                        GdkRectangle e;
-                        GdkRectangle m;
-                        GdkRectangle r;
-
-                        e.x = ex;
-                        e.y = ey;
-                        e.width = ew;
-                        e.height = eh;
-
-                        m.x = mx;
-                        m.y = my;
-                        m.width = mw;
-                        m.height = mh;
-
-                       if (gdk_rectangle_intersect (&e, &m, &r)) {
-                                obscuring = true;
-                        }
-                }
-        }
-
-        if (mixer && !mixer->not_visible() && mixer->property_has_toplevel_focus()) {
-                if (obscuring && same_screen) {
-                        goto_editor_window();
-                }
-        } else if (editor && !editor->not_visible() && editor->property_has_toplevel_focus()) {
-                if (obscuring && same_screen) {
-                        goto_mixer_window();
-                }
-        } else if (mixer && mixer->not_visible()) {
-                if (obscuring && same_screen) {
-                        goto_mixer_window ();
-                }
-        } else if (editor && editor->not_visible()) {
-                if (obscuring && same_screen) {
-                        goto_editor_window ();
-                }
-        } else if (obscuring && same_screen) {
-                //it's unclear what to do here, so just do the opposite of what we did last time  (old behavior)
-                if (_mixer_on_top) {
+
+       if (editor && mixer) {
+               if (ARDOUR_UI_UTILS::windows_overlap (editor, mixer)) {
+                       obscuring = true;
+               }
+       }
+
+       if (mixer && !mixer->not_visible() && mixer->property_has_toplevel_focus()) {
+               if (obscuring) {
+                       goto_editor_window();
+               }
+       } else if (editor && !editor->not_visible() && editor->property_has_toplevel_focus()) {
+               if (obscuring) {
+                       goto_mixer_window();
+               }
+       } else if (mixer && mixer->not_visible()) {
+               if (obscuring) {
+                       goto_mixer_window ();
+               }
+       } else if (editor && editor->not_visible()) {
+               if (obscuring) {
+                       goto_editor_window ();
+               }
+       } else if (obscuring) {
+               //it's unclear what to do here, so just do the opposite of what we did last time  (old behavior)
+               if (_mixer_on_top) {
                        goto_editor_window ();
                } else {
                        goto_mixer_window ();
                }
-        }
+       }
 }
 
 void
@@ -572,5 +569,42 @@ ARDOUR_UI::editor_meter_peak_button_release (GdkEventButton* ev)
        } else if (_session->master_out()) {
                ArdourMeter::ResetRoutePeakDisplays (_session->master_out().get());
        }
-       return true;
+       return false;
+}
+
+void
+ARDOUR_UI::toggle_mixer_space()
+{
+       Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalMixer");
+
+       if (act) {
+               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+               if (tact->get_active()) {
+                       mixer->maximise_mixer_space ();
+               } else {
+                       mixer->restore_mixer_space ();
+               }
+       }
+}
+
+void
+ARDOUR_UI::toggle_mixer_list()
+{
+       Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMixerList");
+
+       if (act) {
+               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+                       mixer->show_mixer_list (tact->get_active());
+       }
+}
+
+void
+ARDOUR_UI::toggle_monitor_section_visibility ()
+{
+       Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
+
+       if (act) {
+               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+                       mixer->show_monitor_section (tact->get_active());
+       }
 }