NOOP, remove trailing tabs/whitespace.
[ardour.git] / libs / surfaces / mackie / gui.cc
index 6753f0a97c965b7dff6d8e25ce8172f81afb7f28..156070dbc89d6072e4258a05fe877585f9221876 100644 (file)
@@ -33,6 +33,7 @@
 #include "gtkmm2ext/utils.h"
 #include "gtkmm2ext/actions.h"
 
+#include "ardour/audioengine.h"
 #include "ardour/rc_configuration.h"
 
 #include "mackie_control_protocol.h"
@@ -42,8 +43,9 @@
 #include "i18n.h"
 
 using namespace std;
-using namespace Mackie;
 using namespace Gtk;
+using namespace ArdourSurface;
+using namespace Mackie;
 
 void*
 MackieControlProtocol::get_gui () const
@@ -86,20 +88,23 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
 {
        Gtk::Label* l;
        Gtk::Alignment* align;
+       int row = 0;
 
        set_border_width (12);
 
-       Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 9));
+       Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 12));
        table->set_row_spacings (4);
        table->set_col_spacings (6);
        table->set_border_width (12);
+
        l = manage (new Gtk::Label (_("Device Type:")));
        l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
-       table->attach (_surface_combo, 1, 2, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 20);
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (_surface_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       row++;
 
        vector<string> surfaces;
-       
+
        for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
                surfaces.push_back (i->first);
        }
@@ -107,59 +112,111 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
        _surface_combo.set_active_text (p.device_info().name());
        _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
 
+       vector<string> midi_ports;
+
+       ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsPhysical), midi_ports);
+       Gtkmm2ext::set_popdown_strings (_input_port_combo, midi_ports);
+
+       string send_string;
+       string receive_string;
+
+       if (_cp.device_info().extenders() > 0) {
+               send_string = _("Main surface sends via:");
+               receive_string = _("Main surface receives via:");
+       } else {
+               send_string = _("Surface sends via:");
+               receive_string = _("Surface receives via:");
+       }
+
+       l = manage (new Gtk::Label (send_string));
+       l->set_alignment (1.0, 0.5);
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (_input_port_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       row++;
+
+       midi_ports.clear ();
+       ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsPhysical), midi_ports);
+       Gtkmm2ext::set_popdown_strings (_output_port_combo, midi_ports);
+
+       l = manage (new Gtk::Label (receive_string));
+       l->set_alignment (1.0, 0.5);
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (_output_port_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       row++;
+
+       l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
+       l->set_alignment (1.0, 0.5);
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (ipmidi_base_port_spinner, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       row++;
+
+       ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
+       ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
+
+       /* leave an extra blank row */
+       row++;
+
        RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
        touch_move_mode_button.set_group (rb_group);
 
+       recalibrate_fader_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::recalibrate_faders));
+       backlight_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::toggle_backlight));
+
+       touch_sensitivity_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::touch_sensitive_change));
+       touch_sensitivity_scale.set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
+
        l = manage (new Gtk::Label (_("Button click")));
        l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
        align->add (relay_click_button);
-       table->attach (*align, 1, 2, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       row++;
+
        l = manage (new Gtk::Label (_("Backlight")));
        l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
        align->add (backlight_button);
-       table->attach (*align, 1, 2, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       row++;
+
        l = manage (new Gtk::Label (_("Send Fader Position Only When Touched")));
        l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
        align->add (absolute_touch_mode_button);
-       table->attach (*align, 1, 2, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       row++;
+
        l = manage (new Gtk::Label (_("Send Fader Position When Moved")));
        l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
        align->add (touch_move_mode_button);
-       table->attach (*align, 1, 2, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       row++;
+
        l = manage (new Gtk::Label (_("Fader Touch Sense Sensitivity")));
        l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        touch_sensitivity_scale.property_digits() = 0;
        touch_sensitivity_scale.property_draw_value() = false;
        table->attach (touch_sensitivity_scale, 1, 2, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
-       table->attach (recalibrate_fader_button, 1, 2, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
-
-       l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
-       l->set_alignment (1.0, 0.5);
-       table->attach (*l, 0, 1, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
-       table->attach (ipmidi_base_port_spinner, 1, 2, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (recalibrate_fader_button, row, row+1, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       row++;
 
-       ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
-       ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
 
-       
-       table->attach (discover_button, 1, 2, 8, 9, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table->attach (discover_button, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        discover_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::discover_clicked));
+       row++;
 
        vector<string> profiles;
-       
+
        profiles.push_back ("default");
 
        for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
@@ -177,13 +234,13 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
        VBox* fkey_packer = manage (new VBox);
        HBox* profile_packer = manage (new HBox);
        HBox* observation_packer = manage (new HBox);
-       
+
        l = manage (new Gtk::Label (_("Profile/Settings:")));
        profile_packer->pack_start (*l, false, false);
        profile_packer->pack_start (_profile_combo, true, true);
        profile_packer->set_spacing (12);
        profile_packer->set_border_width (12);
-       
+
        l = manage (new Gtk::Label (_("* Button available at the original Mackie MCU PRO or current device if enabled (NOT implemented yet). Device specific name presented.")));
        observation_packer->pack_start (*l, false, false);
 
@@ -218,7 +275,7 @@ void
 MackieControlProtocolGUI::build_available_action_menu ()
 {
        /* build a model of all available actions (needs to be tree structured
-        * more) 
+        * more)
         */
 
        available_action_model = TreeStore::create (available_action_columns);
@@ -241,6 +298,31 @@ MackieControlProtocolGUI::build_available_action_menu ()
 
        available_action_model->clear ();
 
+       /* Because there are button bindings built in that are not
+       in the key binding map, there needs to be a way to undo
+       a profile edit. */
+       TreeIter rowp;
+       TreeModel::Row parent;
+       rowp = available_action_model->append();
+       parent = *(rowp);
+       parent[available_action_columns.name] = _("Remove Binding");
+
+       /* Key aliasing */
+
+       rowp = available_action_model->append();
+       parent = *(rowp);
+       parent[available_action_columns.name] = _("Shift");
+       rowp = available_action_model->append();
+       parent = *(rowp);
+       parent[available_action_columns.name] = _("Control");
+       rowp = available_action_model->append();
+       parent = *(rowp);
+       parent[available_action_columns.name] = _("Option");
+       rowp = available_action_model->append();
+       parent = *(rowp);
+       parent[available_action_columns.name] = _("CmdAlt");
+
+
        for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
 
                TreeModel::Row row;
@@ -313,7 +395,7 @@ MackieControlProtocolGUI::build_function_key_editor ()
        col = manage (new TreeViewColumn (_("Plain"), *renderer));
        col->add_attribute (renderer->property_text(), function_key_columns.plain);
        function_key_editor.append_column (*col);
-       
+
        renderer = make_action_renderer (available_action_model, function_key_columns.shift);
        col = manage (new TreeViewColumn (_("Shift"), *renderer));
        col->add_attribute (renderer->property_text(), function_key_columns.shift);
@@ -375,11 +457,17 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
                if (action.empty()) {
                        row[function_key_columns.plain] = defstring;
                } else {
-                       act = ActionManager::get_action (action.c_str());
-                       if (act) {
-                               row[function_key_columns.plain] = act->get_label();
+                       if (action.find ('/') == string::npos) {
+                               /* Probably a key alias */
+                               row[function_key_columns.plain] = action;
                        } else {
-                               row[function_key_columns.plain] = defstring;
+
+                               act = ActionManager::get_action (action.c_str());
+                               if (act) {
+                                       row[function_key_columns.plain] = act->get_label();
+                               } else {
+                                       row[function_key_columns.plain] = defstring;
+                               }
                        }
                }
 
@@ -387,11 +475,16 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
                if (action.empty()) {
                        row[function_key_columns.control] = defstring;
                } else {
-                       act = ActionManager::get_action (action.c_str());
-                       if (act) {
-                               row[function_key_columns.control] = act->get_label();
+                       if (action.find ('/') == string::npos) {
+                               /* Probably a key alias */
+                               row[function_key_columns.control] = action;
                        } else {
-                               row[function_key_columns.control] = defstring;
+                               act = ActionManager::get_action (action.c_str());
+                               if (act) {
+                                       row[function_key_columns.control] = act->get_label();
+                               } else {
+                                       row[function_key_columns.control] = defstring;
+                               }
                        }
                }
 
@@ -399,11 +492,16 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
                if (action.empty()) {
                        row[function_key_columns.shift] = defstring;
                } else {
-                       act = ActionManager::get_action (action.c_str());
-                       if (act) {
-                               row[function_key_columns.shift] = act->get_label();
+                       if (action.find ('/') == string::npos) {
+                               /* Probably a key alias */
+                               row[function_key_columns.shift] = action;
                        } else {
-                               row[function_key_columns.shift] = defstring;
+                               act = ActionManager::get_action (action.c_str());
+                               if (act) {
+                                       row[function_key_columns.shift] = act->get_label();
+                               } else {
+                                       row[function_key_columns.shift] = defstring;
+                               }
                        }
                }
 
@@ -411,11 +509,16 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
                if (action.empty()) {
                        row[function_key_columns.option] = defstring;
                } else {
-                       act = ActionManager::get_action (action.c_str());
-                       if (act) {
-                               row[function_key_columns.option] = act->get_label();
+                       if (action.find ('/') == string::npos) {
+                               /* Probably a key alias */
+                               row[function_key_columns.option] = action;
                        } else {
-                               row[function_key_columns.option] = defstring;
+                               act = ActionManager::get_action (action.c_str());
+                               if (act) {
+                                       row[function_key_columns.option] = act->get_label();
+                               } else {
+                                       row[function_key_columns.option] = defstring;
+                               }
                        }
                }
 
@@ -423,11 +526,16 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
                if (action.empty()) {
                        row[function_key_columns.cmdalt] = defstring;
                } else {
-                       act = ActionManager::get_action (action.c_str());
-                       if (act) {
-                               row[function_key_columns.cmdalt] = act->get_label();
+                       if (action.find ('/') == string::npos) {
+                               /* Probably a key alias */
+                               row[function_key_columns.cmdalt] = action;
                        } else {
-                               row[function_key_columns.cmdalt] = defstring;
+                               act = ActionManager::get_action (action.c_str());
+                               if (act) {
+                                       row[function_key_columns.cmdalt] = act->get_label();
+                               } else {
+                                       row[function_key_columns.cmdalt] = defstring;
+                               }
                        }
                }
 
@@ -447,28 +555,39 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
        function_key_editor.set_model (function_key_model);
 }
 
-void 
+void
 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
 {
+       // Remove Binding is not in the action map but still valid
+       bool remove (false);
+       if ( text == "Remove Binding") {
+               remove = true;
+       }
        Gtk::TreePath path(sPath);
        Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
 
        if (row) {
 
                std::map<std::string,std::string>::iterator i = action_map.find (text);
-               
+
                if (i == action_map.end()) {
-                       return;
+                       if (!remove) {
+                               return;
+                       }
                }
-
                Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
 
-               if (act) {
+               if (act || remove) {
                        /* update visible text, using string supplied by
                           available action model so that it matches and is found
                           within the model.
                        */
-                       (*row).set_value (col.index(), text);
+                       if (remove) {
+                               Glib::ustring dot = "\u2022";
+                               (*row).set_value (col.index(), dot);
+                       } else {
+                               (*row).set_value (col.index(), text);
+                       }
 
                        /* update the current DeviceProfile, using the full
                         * path
@@ -496,7 +615,12 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib
                                modifier = 0;
                        }
 
-                       _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
+                       if (remove) {
+                               _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
+                       } else {
+                               _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
+                       }
+
                } else {
                        std::cerr << "no such action\n";
                }
@@ -506,11 +630,18 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib
 void
 MackieControlProtocolGUI::surface_combo_changed ()
 {
+       _cp.not_session_load();
        _cp.set_device (_surface_combo.get_active_text());
 
-       /* update ipMIDI field */
-
-       ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
+       if (_cp.device_info().uses_ipmidi()) {
+               ipmidi_base_port_spinner.set_sensitive (true);
+               _input_port_combo.set_sensitive (false);
+               _output_port_combo.set_sensitive (false);
+       } else {
+               ipmidi_base_port_spinner.set_sensitive (false);
+               _input_port_combo.set_sensitive (true);
+               _output_port_combo.set_sensitive (true);
+       }
 }
 
 void
@@ -535,3 +666,22 @@ MackieControlProtocolGUI::discover_clicked ()
        /* this should help to get things started */
        _cp.midi_connectivity_established ();
 }
+
+void
+MackieControlProtocolGUI::recalibrate_faders ()
+{
+       _cp.recalibrate_faders ();
+}
+
+void
+MackieControlProtocolGUI::toggle_backlight ()
+{
+       _cp.toggle_backlight ();
+}
+
+void
+MackieControlProtocolGUI::touch_sensitive_change ()
+{
+       int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
+       _cp.set_touch_sensitivity (sensitivity);
+}