Fix some bugs I introduced with the last commit.
[ardour.git] / gtk2_ardour / ardour_ui_ed.cc
index 5892695085702046858e1485256dc2b5152d6431..b46c50cfb3c5a8e7f54083c69f301a1464a66619 100644 (file)
@@ -35,6 +35,7 @@
 #include "gtkmm2ext/utils.h"
 #include "gtkmm2ext/window_title.h"
 #include "gtkmm2ext/tearoff.h"
+#include "gtkmm2ext/cairo_packer.h"
 
 #include "pbd/file_utils.h"
 #include "pbd/fpu.h"
@@ -53,6 +54,7 @@
 #include "utils.h"
 #include "window_proxy.h"
 #include "global_port_matrix.h"
+#include "location_ui.h"
 
 #include <gtkmm2ext/application.h>
 
@@ -147,6 +149,10 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
 
+       act = ActionManager::register_action (main_actions, X_("Rename"), _("Rename..."), sigc::mem_fun(*this, &ARDOUR_UI::rename_session));
+       ActionManager::session_sensitive_actions.push_back (act);
+       ActionManager::write_sensitive_actions.push_back (act);
+
        act = ActionManager::register_action (main_actions, X_("SaveTemplate"), _("Save Template..."),  sigc::mem_fun(*this, &ARDOUR_UI::save_template));
        ActionManager::session_sensitive_actions.push_back (act);
 
@@ -221,7 +227,7 @@ ARDOUR_UI::install_actions ()
        act = ActionManager::register_toggle_action (common_actions, X_("KeepTearoffs"), _("Toolbars when Maximised"), mem_fun (*this, &ARDOUR_UI::toggle_keep_tearoffs));
        ActionManager::session_sensitive_actions.push_back (act);
 
-       ActionManager::register_toggle_action (common_actions, X_("toggle-mixer"), _("Mixer"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_window));
+       ActionManager::register_toggle_action (common_actions, X_("toggle-mixer"), S_("Window|Mixer"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_window));
        ActionManager::register_toggle_action (common_actions, X_("toggle-mixer-on-top"), _("Mixer on Top"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_on_top));
        ActionManager::register_toggle_action (common_actions, X_("ToggleRCOptionsEditor"), _("Preferences"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_rc_options_window));
        ActionManager::register_toggle_action (common_actions, X_("ToggleSessionOptionsEditor"), _("Properties"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_options_window));
@@ -242,7 +248,8 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::register_action (common_actions, X_("About"), _("About"),  sigc::mem_fun(*this, &ARDOUR_UI::show_about));
        ActionManager::register_action (common_actions, X_("Chat"), _("Chat"),  sigc::mem_fun(*this, &ARDOUR_UI::launch_chat));
-       ActionManager::register_action (common_actions, X_("Manual"), _("Manual"),  mem_fun(*this, &ARDOUR_UI::launch_manual));
+       /** TRANSLATORS: This is `Manual' in the sense of an instruction book that tells a user how to use Ardour */
+       ActionManager::register_action (common_actions, X_("Manual"), S_("Help|Manual"),  mem_fun(*this, &ARDOUR_UI::launch_manual));
        ActionManager::register_action (common_actions, X_("Reference"), _("Reference"),  mem_fun(*this, &ARDOUR_UI::launch_reference));
        ActionManager::register_toggle_action (common_actions, X_("ToggleThemeManager"), _("Theme Manager"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_theme_manager));
        ActionManager::register_toggle_action (common_actions, X_("ToggleKeyEditor"), _("Key Bindings"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_key_editor));
@@ -350,7 +357,7 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_action (transport_actions, X_("focus-on-clock"), _("Focus On Clock"), sigc::mem_fun(primary_clock, &AudioClock::focus));
+       act = ActionManager::register_action (transport_actions, X_("focus-on-clock"), _("Focus On Clock"), sigc::mem_fun(*this, &ARDOUR_UI::focus_on_clock));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
 
@@ -362,8 +369,6 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        act = ActionManager::register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Frames));
        ActionManager::session_sensitive_actions.push_back (act);
-       //act = ActionManager::register_action (transport_actions, X_("primary-clock-off"), _("Off"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Off));
-       ActionManager::session_sensitive_actions.push_back (act);
 
        act = ActionManager::register_action (transport_actions, X_("secondary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Timecode));
        ActionManager::session_sensitive_actions.push_back (act);
@@ -373,16 +378,17 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        act = ActionManager::register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Frames));
        ActionManager::session_sensitive_actions.push_back (act);
-       //act = ActionManager::register_action (transport_actions, X_("secondary-clock-off"), _("Off"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Off));
-       //ActionManager::session_sensitive_actions.push_back (act);
 
        act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
+       act->set_short_label (_("In"));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
        act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchOut"), _("Punch Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_out));
+       act->set_short_label (_("Out"));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
        act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunch"), _("Punch In/Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch));
+       act->set_short_label (_("In/Out"));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
        act = ActionManager::register_toggle_action (transport_actions, X_("ToggleClick"), _("Click"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_click));
@@ -441,12 +447,18 @@ ARDOUR_UI::install_actions ()
                }
        }
 
+       /* MIDI */
+
+       Glib::RefPtr<ActionGroup> midi_actions = ActionGroup::create (X_("MIDI"));
+       ActionManager::register_action (midi_actions, X_("panic"), _("Panic"), sigc::mem_fun(*this, &ARDOUR_UI::midi_panic));
+
        ActionManager::add_action_group (shuttle_actions);
        ActionManager::add_action_group (option_actions);
        ActionManager::add_action_group (jack_actions);
        ActionManager::add_action_group (transport_actions);
        ActionManager::add_action_group (main_actions);
        ActionManager::add_action_group (common_actions);
+       ActionManager::add_action_group (midi_actions);
 }
 
 void
@@ -519,25 +531,25 @@ ARDOUR_UI::build_menu_bar ()
        // so use this instead ...
        gtk_settings_set_long_property (gtk_settings_get_default(), "gtk-can-change-accels", 1, "Ardour:designers");
 
-       wall_clock_box.add (wall_clock_label);
-       wall_clock_box.set_name ("WallClock");
-       wall_clock_label.set_name ("WallClock");
+       EventBox* ev = manage (new EventBox);
+       ev->show ();
+       CairoHPacker* hbox = manage (new CairoHPacker);
+       hbox->show ();
+       
+       ev->add (*hbox);
 
-       disk_space_box.add (disk_space_label);
-       disk_space_box.set_name ("WallClock");
+       wall_clock_label.set_name ("WallClock");
+       wall_clock_label.set_use_markup ();
        disk_space_label.set_name ("WallClock");
-
-       cpu_load_box.add (cpu_load_label);
-       cpu_load_box.set_name ("CPULoad");
+       disk_space_label.set_use_markup ();
        cpu_load_label.set_name ("CPULoad");
-
-       buffer_load_box.add (buffer_load_label);
-       buffer_load_box.set_name ("BufferLoad");
+       cpu_load_label.set_use_markup ();
        buffer_load_label.set_name ("BufferLoad");
-
-       sample_rate_box.add (sample_rate_label);
-       sample_rate_box.set_name ("SampleRate");
+       buffer_load_label.set_use_markup ();
        sample_rate_label.set_name ("SampleRate");
+       sample_rate_label.set_use_markup ();
+       format_label.set_name ("Format");
+       format_label.set_use_markup ();
 
 #ifndef TOP_MENUBAR
        menu_hbox.pack_start (*menu_bar, false, false);
@@ -545,20 +557,37 @@ ARDOUR_UI::build_menu_bar ()
        use_menubar_as_top_menubar ();
 #endif
 
+       bool wall_clock = false;
+       bool disk_space = false;
+
        if (!Profile->get_small_screen()) {
 #ifndef GTKOSX
                // OSX provides its own wallclock, thank you very much
-               menu_hbox.pack_end (wall_clock_box, false, false, 2);
+               wall_clock = true;
 #endif
-               menu_hbox.pack_end (disk_space_box, false, false, 4);
+               disk_space = true;
        }
+       
+       hbox->pack_end (wall_clock_label, false, false, 2);
+       hbox->pack_end (disk_space_label, false, false, 4);
+       hbox->pack_end (cpu_load_label, false, false, 4);
+       hbox->pack_end (buffer_load_label, false, false, 4);
+       hbox->pack_end (sample_rate_label, false, false, 4);
+       hbox->pack_end (format_label, false, false, 4);
 
-       menu_hbox.pack_end (cpu_load_box, false, false, 4);
-       menu_hbox.pack_end (buffer_load_box, false, false, 4);
-       menu_hbox.pack_end (sample_rate_box, false, false, 4);
+       menu_hbox.pack_end (*ev, false, false);
 
        menu_bar_base.set_name ("MainMenuBar");
        menu_bar_base.add (menu_hbox);
+
+       _status_bar_visibility.add (&wall_clock_label,  X_("WallClock"), _("Wall Clock"), wall_clock);
+       _status_bar_visibility.add (&disk_space_label,  X_("Disk"),      _("Disk Space"), disk_space);
+       _status_bar_visibility.add (&cpu_load_label,    X_("DSP"),       _("DSP"), true);
+       _status_bar_visibility.add (&buffer_load_label, X_("Buffers"),   _("Buffers"), true);
+       _status_bar_visibility.add (&sample_rate_label, X_("JACK"),      _("JACK Sampling Rate and Latency"), true);
+       _status_bar_visibility.add (&format_label,      X_("Format"),    _("File Format"), true);
+
+       ev->signal_button_press_event().connect (sigc::mem_fun (_status_bar_visibility, &VisibilityGroup::button_press_event));
 }
 
 void
@@ -575,21 +604,31 @@ ARDOUR_UI::use_menubar_as_top_menubar ()
 
        GtkApplicationMenuGroup* group = app->add_app_menu_group ();
 
-       if ((widget = ActionManager::get_widget ("/ui/Main/Help/About"))) {
+       if ((widget = ActionManager::get_widget ("/ui/Main/Session/About"))) {
                app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
        }
 
-       if ((widget = ActionManager::get_widget ("/ui/Main/WindowMenu/ToggleOptionsEditor"))) {
+       if ((widget = ActionManager::get_widget ("/ui/Main/Session/ToggleRCOptionsEditor"))) {
                app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
        }
 
        app->set_menu_bar (*menu_bar);
 }
 
+void
+ARDOUR_UI::big_clock_catch_focus ()
+{
+       PublicEditor::instance().reset_focus ();
+}
+
 void
 ARDOUR_UI::setup_clock ()
 {
-       ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (big_clock, &AudioClock::set), false));
+       ARDOUR_UI::Clock.connect (sigc::mem_fun (big_clock, &AudioClock::set));
+
+       big_clock->set_corner_radius (0.0);
+       big_clock->set_fixed_width (false);
+       big_clock->mode_changed.connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_reset_aspect_ratio));
 
        big_clock_window->set (new Window (WINDOW_TOPLEVEL), false);
 
@@ -598,15 +637,30 @@ ARDOUR_UI::setup_clock ()
        big_clock_window->get()->add (*big_clock);
 
        big_clock_window->get()->set_title (_("Big Clock"));
-       big_clock_window->get()->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
        big_clock_window->get()->signal_realize().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_realized));
-       big_clock_window->get()->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBigClock")));
        big_clock_window->get()->signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), big_clock_window->get()), false);
        big_clock_window->get()->signal_size_allocate().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_size_allocate));
 
+       big_clock_window->get()->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBigClock")));
+       big_clock_window->get()->signal_unmap().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_catch_focus));
+
        manage_window (*big_clock_window->get());
 }
 
+void
+ARDOUR_UI::big_clock_reset_aspect_ratio ()
+{
+       Gtk::Requisition req;
+       big_clock->size_request (req);
+       float aspect = req.width/(float)req.height;
+       Gdk::Geometry geom;
+
+       geom.min_aspect = aspect;
+       geom.max_aspect = aspect;
+
+       big_clock_window->get()->set_geometry_hints (*big_clock, geom, Gdk::HINT_ASPECT);
+}
+
 void
 ARDOUR_UI::big_clock_realized ()
 {
@@ -615,6 +669,8 @@ ARDOUR_UI::big_clock_realized ()
        set_decoration (big_clock_window->get(), (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
        big_clock_window->get()->get_window()->get_geometry (x, y, w, big_clock_height, d);
 
+       big_clock_reset_aspect_ratio ();
+
        original_big_clock_height = big_clock_height;
        original_big_clock_width = w;
 
@@ -641,7 +697,7 @@ ARDOUR_UI::float_big_clock (Gtk::Window* parent)
 }
 
 void
-ARDOUR_UI::big_clock_size_allocate (Gtk::Allocation&)
+ARDOUR_UI::big_clock_size_allocate (Gtk::Allocation& alloc)
 {
        if (!big_clock_resize_in_progress) {
                Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::idle_big_clock_text_resizer), 0, 0));
@@ -707,6 +763,7 @@ ARDOUR_UI::save_ardour_state ()
        Config->add_extra_xml (get_transport_controllable_state());
 
        XMLNode* window_node = new XMLNode (X_("UI"));
+       window_node->add_property (_status_bar_visibility.get_state_name().c_str(), _status_bar_visibility.get_state_value ());
 
        for (list<WindowProxyBase*>::iterator i = _window_proxies.begin(); i != _window_proxies.end(); ++i) {
                if ((*i)->rc_configured()) {
@@ -744,17 +801,25 @@ ARDOUR_UI::save_ardour_state ()
                Config->add_extra_xml (_startup->engine_control()->get_state());
        }
        Config->save_state();
-       ui_config->save_state ();
+       if (ui_config->dirty()) {
+               ui_config->save_state ();
+       }
 
-       XMLNode enode(static_cast<Stateful*>(editor)->get_state());
-       XMLNode mnode(mixer->get_state());
+       XMLNode& enode (static_cast<Stateful*>(editor)->get_state());
+       XMLNode& mnode (mixer->get_state());
 
        if (_session) {
                _session->add_instant_xml (enode);
                _session->add_instant_xml (mnode);
+               if (location_ui->get ()) {
+                       _session->add_instant_xml (location_ui->get()->ui().get_state ());
+               }
        } else {
                Config->add_instant_xml (enode);
                Config->add_instant_xml (mnode);
+               if (location_ui->get ()) {
+                       Config->add_instant_xml (location_ui->get()->ui().get_state ());
+               }
        }
 
        Keyboard::save_keybindings ();
@@ -781,3 +846,19 @@ ARDOUR_UI::toggle_global_port_matrix (ARDOUR::DataType t)
                }
        }
 }
+
+void
+ARDOUR_UI::resize_text_widgets ()
+{
+       set_size_request_to_display_given_text (cpu_load_label, "DSP: 100.0%", 2, 2);
+       set_size_request_to_display_given_text (buffer_load_label, "Buffers: p:100% c:100%", 2, 2);
+}
+
+void
+ARDOUR_UI::focus_on_clock ()
+{
+       if (editor && primary_clock) {
+               editor->present ();
+               primary_clock->focus ();
+       }
+}