Plugin selector keyboard focus should now stay in the plugin list. More
[ardour.git] / gtk2_ardour / ardour_ui_ed.cc
index e658aa23e93d76c17390a84c575e488aff19f343..238f81dd4f414973c0a2595c11f37872f5196e85 100644 (file)
 #include "actions.h"
 
 #include <ardour/session.h>
+#include <ardour/control_protocol_manager.h>
+
+#include <control_protocol/control_protocol.h>
 
 #include "i18n.h"
 
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Gtk;
 using namespace Gtkmm2ext;
 
@@ -76,6 +80,7 @@ ARDOUR_UI::install_actions ()
        ActionManager::register_action (main_actions, X_("AudioFileFormat"), _("Audio File Format"));
        ActionManager::register_action (main_actions, X_("AudioFileFormatHeader"), _("Header"));
        ActionManager::register_action (main_actions, X_("AudioFileFormatData"), _("Data"));
+       ActionManager::register_action (main_actions, X_("ControlSurfaces"), _("Control Surfaces"));
 
        /* the real actions */
 
@@ -259,31 +264,26 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
 
-       /* XXX the newline in the displayed names of these action is really wrong, but its because we want the button
-          that proxies for these action to be more compact. It would be nice to find a way to override the action
-          name appearance on the buttons.
-       */
-
-       act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch\nin"), mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
+       act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), mem_fun(*this, &ARDOUR_UI::toggle_punch_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\nout"), mem_fun(*this, &ARDOUR_UI::toggle_punch_out));
+       act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchOut"), _("Punch Out"), mem_fun(*this, &ARDOUR_UI::toggle_punch_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"), mem_fun(*this, &ARDOUR_UI::toggle_click));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
-       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoInput"), _("Auto\ninput"), mem_fun(*this, &ARDOUR_UI::toggle_auto_input));
+       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoInput"), _("Auto Input"), mem_fun(*this, &ARDOUR_UI::toggle_auto_input));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
-       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoPlay"), _("Auto\nplay"), mem_fun(*this, &ARDOUR_UI::toggle_auto_play));
+       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoPlay"), _("Auto Play"), mem_fun(*this, &ARDOUR_UI::toggle_auto_play));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
-       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoReturn"), _("Auto\nreturn"), mem_fun(*this, &ARDOUR_UI::toggle_auto_return));
+       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoReturn"), _("Auto Return"), mem_fun(*this, &ARDOUR_UI::toggle_auto_return));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleTimeMaster"), _("Time\nmaster"), mem_fun(*this, &ARDOUR_UI::toggle_time_master));
+       act = ActionManager::register_toggle_action (transport_actions, X_("ToggleTimeMaster"), _("Master"), mem_fun(*this, &ARDOUR_UI::toggle_time_master));
        ActionManager::session_sensitive_actions.push_back (act);
 
        act = ActionManager::register_action (common_actions, X_("ToggleRecordEnableTrack1"), _("Toggle Record Enable Track1"), bind (mem_fun(*this, &ARDOUR_UI::toggle_record_enable),  0U));
@@ -360,7 +360,7 @@ ARDOUR_UI::install_actions ()
 
        act = ActionManager::register_toggle_action (option_actions, X_("SendMTC"), _("Send MTC"), mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = ActionManager::register_toggle_action (option_actions, X_("SendMMC"), _("Send MMC"), mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
+       act = ActionManager::register_toggle_action (option_actions, X_("SendMMC"), _("Send MMC"), mem_fun (*this, &ARDOUR_UI::toggle_send_mmc));
        ActionManager::session_sensitive_actions.push_back (act);
        act = ActionManager::register_toggle_action (option_actions, X_("UseMMC"), _("Use MMC"), mem_fun (*this, &ARDOUR_UI::toggle_use_mmc));
        ActionManager::session_sensitive_actions.push_back (act);
@@ -369,7 +369,7 @@ ARDOUR_UI::install_actions ()
        act = ActionManager::register_toggle_action (option_actions, X_("UseMIDIcontrol"), _("Use MIDI control"), mem_fun (*this, &ARDOUR_UI::toggle_use_midi_control));
        ActionManager::session_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_toggle_action (option_actions, X_("AutoConnectNewTrackInputsToHardware"), _("Connect newtrack inputs to hardware"), mem_fun (*this, &ARDOUR_UI::toggle_AutoConnectNewTrackInputsToHardware));
+       act = ActionManager::register_toggle_action (option_actions, X_("AutoConnectNewTrackInputsToHardware"), _("Connect new track inputs to hardware"), mem_fun (*this, &ARDOUR_UI::toggle_AutoConnectNewTrackInputsToHardware));
        ActionManager::session_sensitive_actions.push_back (act);
 
        RadioAction::Group file_header_group;
@@ -377,8 +377,9 @@ ARDOUR_UI::install_actions ()
        act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatBWF"), X_("Broadcast WAVE"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::BWF));
        act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatWAVE"), X_("WAVE"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::WAVE));
        act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatWAVE64"), X_("WAVE-64"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::WAVE64));
-       act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatiXML"), X_("iXML"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::iXML));
-       act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatRF64"), X_("RF64"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::RF64));
+       // act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatiXML"), X_("iXML"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::iXML));
+       // act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatRF64"), X_("RF64"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::RF64));
+       act = ActionManager::register_radio_action (option_actions, file_header_group, X_("FileHeaderFormatCAF"), X_("CAF"), bind (mem_fun (*this, &ARDOUR_UI::set_native_file_header_format), ARDOUR::CAF));
 
        RadioAction::Group file_data_group;
 
@@ -441,9 +442,68 @@ ARDOUR_UI::install_actions ()
        setup_config_options ();
 }
 
+void
+ARDOUR_UI::toggle_control_protocol (ControlProtocolInfo* cpi)
+{
+       if (!session) {
+               /* this happens when we build the menu bar when control protocol support
+                  has been used in the past for some given protocol - the item needs
+                  to be made active, but there is no session yet.
+               */
+               return;
+       }
+
+       if (cpi->protocol == 0) {
+               ControlProtocolManager::instance().instantiate (*cpi);
+       } else {
+               ControlProtocolManager::instance().teardown (*cpi);
+       }
+}
+
+void
+ARDOUR_UI::build_control_surface_menu ()
+{
+       list<ControlProtocolInfo*>::iterator i;
+
+       /* !!! this has to match the top level entry from ardour.menus */
+
+       string ui = "<menubar name='Main' action='MainMenu'>\n<menu name='Options' action='Options'>\n<menu action='ControlSurfaces'><separator/>\n";
+
+       for (i = ControlProtocolManager::instance().control_protocol_info.begin(); i != ControlProtocolManager::instance().control_protocol_info.end(); ++i) {
+
+               if (!(*i)->mandatory) {
+
+                       string action_name = "Toggle";
+                       action_name += legalize_for_path ((*i)->name);
+                       action_name += "Surface";
+                       
+                       string action_label = (*i)->name;
+                       
+                       Glib::RefPtr<Action> act = ActionManager::register_toggle_action (editor->editor_actions, action_name.c_str(), action_label.c_str(),
+                                                                                         (bind (mem_fun (*this, &ARDOUR_UI::toggle_control_protocol), *i)));
+                       
+                       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+                       
+                       if ((*i)->protocol || (*i)->requested) {
+                               tact->set_active ();
+                       }
+                       
+                       ui += "<menuitem action='";
+                       ui += action_name;
+                       ui += "'/>\n";
+               }
+       }
+
+       ui += "</menu>\n</menu>\n</menubar>\n";
+
+       ActionManager::ui_manager->add_ui_from_string (ui);
+}
+
 void
 ARDOUR_UI::build_menu_bar ()
 {
+       build_control_surface_menu ();
+
        menu_bar = dynamic_cast<MenuBar*> (ActionManager::get_widget (X_("/Main")));
        menu_bar->set_name ("MainMenuBar");
 
@@ -470,10 +530,6 @@ ARDOUR_UI::build_menu_bar ()
        buffer_load_box.set_name ("BufferLoad");
        buffer_load_label.set_name ("BufferLoad");
 
-//     disk_rate_box.add (disk_rate_label);
-//     disk_rate_box.set_name ("DiskRate");
-//     disk_rate_label.set_name ("DiskRate");
-
        sample_rate_box.add (sample_rate_label);
        sample_rate_box.set_name ("SampleRate");
        sample_rate_label.set_name ("SampleRate");
@@ -482,7 +538,6 @@ ARDOUR_UI::build_menu_bar ()
        menu_hbox.pack_end (wall_clock_box, false, false, 10);
        menu_hbox.pack_end (disk_space_box, false, false, 10);
        menu_hbox.pack_end (cpu_load_box, false, false, 10);
-//     menu_hbox.pack_end (disk_rate_box, false, false, 10);
        menu_hbox.pack_end (buffer_load_box, false, false, 10);
        menu_hbox.pack_end (sample_rate_box, false, false, 10);