implement backlight, fader touch sensitivity and recalibrate fader functions for...
[ardour.git] / libs / surfaces / mackie / gui.cc
index 7425b388266c5369de132e370bbc8228c801bafa..99aeec14d8bf443c53b576a2f29b5b36e1f3c740 100644 (file)
@@ -42,8 +42,9 @@
 #include "i18n.h"
 
 using namespace std;
-using namespace Mackie;
 using namespace Gtk;
+using namespace ArdourSurface;
+using namespace Mackie;
 
 void*
 MackieControlProtocol::get_gui () const
@@ -51,14 +52,22 @@ MackieControlProtocol::get_gui () const
        if (!_gui) {
                const_cast<MackieControlProtocol*>(this)->build_gui ();
        }
-
+       static_cast<Gtk::Notebook*>(_gui)->show_all();
        return _gui;
 }
 
 void
 MackieControlProtocol::tear_down_gui ()
 {
+       if (_gui) {
+               Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
+               if (w) {
+                       w->hide();
+                       delete w;
+               }
+       }
        delete (MackieControlProtocolGUI*) _gui;
+       _gui = 0;
 }
 
 void
@@ -102,6 +111,12 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
        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));
@@ -145,7 +160,6 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
 
        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));
        discover_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::discover_clicked));
@@ -233,6 +247,15 @@ 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");
+
        for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
 
                TreeModel::Row row;
@@ -442,6 +465,11 @@ MackieControlProtocolGUI::refresh_function_key_editor ()
 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);
 
@@ -450,17 +478,23 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib
                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
@@ -488,7 +522,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";
                }
@@ -498,6 +537,7 @@ 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 */
@@ -527,3 +567,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);
+}