use ActionManager namespace, rather than ActionMap objects
[ardour.git] / libs / surfaces / mackie / gui.cc
index ddbb9278082fbdf8dc705409f5d21e3e7b8f30d2..b2dc987c133cb23f7705fcfaac92114d2ceb35d3 100644 (file)
@@ -34,6 +34,7 @@
 #include "pbd/stacktrace.h"
 
 #include "gtkmm2ext/actions.h"
+#include "gtkmm2ext/bindings.h"
 #include "gtkmm2ext/gui_thread.h"
 #include "gtkmm2ext/utils.h"
 
@@ -47,7 +48,7 @@
 #include "surface.h"
 #include "surface_port.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Gtk;
@@ -93,6 +94,7 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
        , ipmidi_base_port_adjustment (_cp.ipmidi_base(), 0, 32767, 1, 1000)
        , discover_button (_("Discover Mackie Devices"))
        , _device_dependent_widget (0)
+       , _ignore_profile_changed (false)
        , ignore_active_change (false)
 {
        Gtk::Label* l;
@@ -190,9 +192,9 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
        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 (touch_sensitivity_scale, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        row++;
-       table.attach (recalibrate_fader_button, row, row+1, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       table.attach (recalibrate_fader_button, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        row++;
 
 
@@ -202,12 +204,12 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
 
        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) {
+               cerr << "add discovered profile " << i->first << endl;
                profiles.push_back (i->first);
        }
        Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
+       cerr << "set active profile from " << p.device_profile().name() << endl;
        _profile_combo.set_active_text (p.device_profile().name());
        _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
 
@@ -332,6 +334,7 @@ MackieControlProtocolGUI::device_dependent_widget ()
        int row = 0;
 
        uint32_t n_surfaces = 1 + _cp.device_info().extenders();
+       uint32_t main_pos = _cp.device_info().master_position();
 
        if (!_cp.device_info().uses_ipmidi()) {
                dd_table = Gtk::manage (new Gtk::Table (n_surfaces, 2));
@@ -386,12 +389,12 @@ MackieControlProtocolGUI::device_dependent_widget ()
                        string receive_string;
 
                        if (n_surfaces > 1) {
-                               if (n == 0) {
-                                       send_string = _("Main surface sends via:");
-                                       receive_string = _("Main surface receives via:");
+                               if (n == main_pos) {
+                                       send_string = string_compose(_("Main surface at position %1 sends via:"), n + 1);
+                                       receive_string = string_compose(_("Main surface at position %1 receives via:"), n + 1);
                                } else {
-                                       send_string = string_compose (_("Extender %1 sends via:"), n);
-                                       receive_string = string_compose (_("Extender %1 receives via:"), n);
+                                       send_string = string_compose (_("Extender at position %1 sends via:"), n + 1);
+                                       receive_string = string_compose (_("Extender at position %1 receives via:"), n + 1);
                                }
                        } else {
                                send_string = _("Surface sends via:");
@@ -451,12 +454,13 @@ MackieControlProtocolGUI::build_available_action_menu ()
        vector<string> labels;
        vector<string> tooltips;
        vector<string> keys;
-       vector<AccelKey> bindings;
+       vector<Glib::RefPtr<Gtk::Action> > actions;
+
        typedef std::map<string,TreeIter> NodeMap;
        NodeMap nodes;
        NodeMap::iterator r;
 
-       ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
+       ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
 
        vector<string>::iterator k;
        vector<string>::iterator p;
@@ -466,8 +470,9 @@ 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. */
+          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();
@@ -489,7 +494,6 @@ MackieControlProtocolGUI::build_available_action_menu ()
        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;
@@ -620,54 +624,68 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
                string action;
                const string defstring = "\u2022";
 
-               action = dp.get_button_action (bid, 0);
-               if (action.empty()) {
-                       row[function_key_columns.plain] = defstring;
-               } else {
-                       if (action.find ('/') == string::npos) {
-                               /* Probably a key alias */
-                               row[function_key_columns.plain] = action;
-                       } else {
+               /* We only allow plain bindings for Fn keys. All others are
+                * reserved for hard-coded actions.
+                */
 
-                               act = ActionManager::get_action (action.c_str());
-                               if (act) {
-                                       row[function_key_columns.plain] = act->get_label();
+               if (bid >= Mackie::Button::F1 && bid <= Mackie::Button::F8) {
+
+                       action = dp.get_button_action (bid, 0);
+                       if (action.empty()) {
+                               row[function_key_columns.plain] = defstring;
+                       } else {
+                               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;
+                                       }
                                }
                        }
                }
 
-               action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
-               if (action.empty()) {
-                       row[function_key_columns.control] = defstring;
-               } else {
-                       if (action.find ('/') == string::npos) {
-                               /* Probably a key alias */
-                               row[function_key_columns.control] = action;
+               /* We only allow plain bindings for Fn keys. All others are
+                * reserved for hard-coded actions.
+                */
+
+               if (bid >= Mackie::Button::F1 && bid <= Mackie::Button::F8) {
+
+                       action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
+                       if (action.empty()) {
+                               row[function_key_columns.shift] = 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.shift] = action;
                                } else {
-                                       row[function_key_columns.control] = 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;
+                                       }
                                }
                        }
                }
 
-               action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
+               action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
                if (action.empty()) {
-                       row[function_key_columns.shift] = defstring;
+                       row[function_key_columns.control] = defstring;
                } else {
                        if (action.find ('/') == string::npos) {
                                /* Probably a key alias */
-                               row[function_key_columns.shift] = action;
+                               row[function_key_columns.control] = action;
                        } else {
                                act = ActionManager::get_action (action.c_str());
                                if (act) {
-                                       row[function_key_columns.shift] = act->get_label();
+                                       row[function_key_columns.control] = act->get_label();
                                } else {
-                                       row[function_key_columns.shift] = defstring;
+                                       row[function_key_columns.control] = defstring;
                                }
                        }
                }
@@ -788,6 +806,10 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib
                                _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
                        }
 
+                       _ignore_profile_changed = true;
+                       _profile_combo.set_active_text ( _cp.device_profile().name() );
+                       _ignore_profile_changed = false;
+
                } else {
                        std::cerr << "no such action\n";
                }
@@ -797,7 +819,6 @@ 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(), false);
 }
 
@@ -818,11 +839,13 @@ MackieControlProtocolGUI::device_changed ()
 void
 MackieControlProtocolGUI::profile_combo_changed ()
 {
-       string profile = _profile_combo.get_active_text();
+       if (!_ignore_profile_changed) {
+               string profile = _profile_combo.get_active_text();
 
-       _cp.set_profile (profile);
+               _cp.set_profile (profile);
 
-       refresh_function_key_editor ();
+               refresh_function_key_editor ();
+       }
 }
 
 void
@@ -870,7 +893,11 @@ MackieControlProtocolGUI::build_midi_port_list (vector<string> const & ports, bo
        for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
                row = *store->append ();
                row[midi_port_columns.full_name] = *p;
-               row[midi_port_columns.short_name] = (*p).substr ((*p).find (':') + 1);
+               std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
+               if (pn.empty ()) {
+                       pn = (*p).substr ((*p).find (':') + 1);
+               }
+               row[midi_port_columns.short_name] = pn;
        }
 
        return store;