globally remove all trailing whitespace from ardour code base.
[ardour.git] / libs / surfaces / mackie / gui.cc
1 /*
2         Copyright (C) 2010 Paul Davis
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <gtkmm/comboboxtext.h>
20 #include <gtkmm/box.h>
21 #include <gtkmm/spinbutton.h>
22 #include <gtkmm/table.h>
23 #include <gtkmm/treeview.h>
24 #include <gtkmm/liststore.h>
25 #include <gtkmm/treestore.h>
26 #include <gtkmm/notebook.h>
27 #include <gtkmm/cellrenderercombo.h>
28 #include <gtkmm/scale.h>
29 #include <gtkmm/alignment.h>
30
31 #include "pbd/strsplit.h"
32
33 #include "gtkmm2ext/utils.h"
34 #include "gtkmm2ext/actions.h"
35
36 #include "ardour/audioengine.h"
37 #include "ardour/rc_configuration.h"
38
39 #include "mackie_control_protocol.h"
40 #include "device_info.h"
41 #include "gui.h"
42
43 #include "i18n.h"
44
45 using namespace std;
46 using namespace Gtk;
47 using namespace ArdourSurface;
48 using namespace Mackie;
49
50 void*
51 MackieControlProtocol::get_gui () const
52 {
53         if (!_gui) {
54                 const_cast<MackieControlProtocol*>(this)->build_gui ();
55         }
56         static_cast<Gtk::Notebook*>(_gui)->show_all();
57         return _gui;
58 }
59
60 void
61 MackieControlProtocol::tear_down_gui ()
62 {
63         if (_gui) {
64                 Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
65                 if (w) {
66                         w->hide();
67                         delete w;
68                 }
69         }
70         delete (MackieControlProtocolGUI*) _gui;
71         _gui = 0;
72 }
73
74 void
75 MackieControlProtocol::build_gui ()
76 {
77         _gui = (void *) new MackieControlProtocolGUI (*this);
78 }
79
80 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
81         : _cp (p)
82         , touch_sensitivity_adjustment (0, 0, 9, 1, 4)
83         , touch_sensitivity_scale (touch_sensitivity_adjustment)
84         , recalibrate_fader_button (_("Recalibrate Faders"))
85         , ipmidi_base_port_adjustment (_cp.ipmidi_base(), 0, 32767, 1, 1000)
86         , ipmidi_base_port_spinner (ipmidi_base_port_adjustment)
87         , discover_button (_("Discover Mackie Devices"))
88 {
89         Gtk::Label* l;
90         Gtk::Alignment* align;
91         int row = 0;
92         
93         set_border_width (12);
94
95         Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 12));
96         table->set_row_spacings (4);
97         table->set_col_spacings (6);
98         table->set_border_width (12);
99
100         l = manage (new Gtk::Label (_("Device Type:")));
101         l->set_alignment (1.0, 0.5);
102         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
103         table->attach (_surface_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
104         row++;
105                 
106         vector<string> surfaces;
107         
108         for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
109                 surfaces.push_back (i->first);
110         }
111         Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
112         _surface_combo.set_active_text (p.device_info().name());
113         _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
114
115         vector<string> midi_ports;
116
117         ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsPhysical), midi_ports);
118         Gtkmm2ext::set_popdown_strings (_input_port_combo, midi_ports);
119
120         string send_string;
121         string receive_string;
122
123         if (_cp.device_info().extenders() > 0) {
124                 send_string = _("Main surface sends via:");
125                 receive_string = _("Main surface receives via:");
126         } else {
127                 send_string = _("Surface sends via:");
128                 receive_string = _("Surface receives via:");
129         }
130         
131         l = manage (new Gtk::Label (send_string));
132         l->set_alignment (1.0, 0.5);
133         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
134         table->attach (_input_port_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
135         row++;
136
137         midi_ports.clear ();
138         ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsPhysical), midi_ports);
139         Gtkmm2ext::set_popdown_strings (_output_port_combo, midi_ports);
140
141         l = manage (new Gtk::Label (receive_string));
142         l->set_alignment (1.0, 0.5);
143         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
144         table->attach (_output_port_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
145         row++;
146
147         l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
148         l->set_alignment (1.0, 0.5);
149         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
150         table->attach (ipmidi_base_port_spinner, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
151         row++;
152         
153         ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
154         ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
155         
156         /* leave an extra blank row */
157         row++;
158
159         RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
160         touch_move_mode_button.set_group (rb_group);
161
162         recalibrate_fader_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::recalibrate_faders));
163         backlight_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::toggle_backlight));
164
165         touch_sensitivity_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::touch_sensitive_change));
166         touch_sensitivity_scale.set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
167         
168         l = manage (new Gtk::Label (_("Button click")));
169         l->set_alignment (1.0, 0.5);
170         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
171         align = manage (new Alignment);
172         align->set (0.0, 0.5);
173         align->add (relay_click_button);
174         table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
175         row++;
176         
177         l = manage (new Gtk::Label (_("Backlight")));
178         l->set_alignment (1.0, 0.5);
179         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
180         align = manage (new Alignment);
181         align->set (0.0, 0.5);
182         align->add (backlight_button);
183         table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
184         row++;
185                 
186         l = manage (new Gtk::Label (_("Send Fader Position Only When Touched")));
187         l->set_alignment (1.0, 0.5);
188         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
189         align = manage (new Alignment);
190         align->set (0.0, 0.5);
191         align->add (absolute_touch_mode_button);
192         table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
193         row++;
194         
195         l = manage (new Gtk::Label (_("Send Fader Position When Moved")));
196         l->set_alignment (1.0, 0.5);
197         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
198         align = manage (new Alignment);
199         align->set (0.0, 0.5);
200         align->add (touch_move_mode_button);
201         table->attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
202         row++;
203         
204         l = manage (new Gtk::Label (_("Fader Touch Sense Sensitivity")));
205         l->set_alignment (1.0, 0.5);
206         table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
207         touch_sensitivity_scale.property_digits() = 0;
208         touch_sensitivity_scale.property_draw_value() = false;
209         table->attach (touch_sensitivity_scale, 1, 2, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
210         table->attach (recalibrate_fader_button, row, row+1, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
211         row++;
212         
213
214         table->attach (discover_button, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
215         discover_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::discover_clicked));
216         row++;
217         
218         vector<string> profiles;
219         
220         profiles.push_back ("default");
221
222         for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
223                 profiles.push_back (i->first);
224         }
225         Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
226         _profile_combo.set_active_text (p.device_profile().name());
227         _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
228
229         append_page (*table, _("Device Setup"));
230         table->show_all();
231
232         /* function key editor */
233
234         VBox* fkey_packer = manage (new VBox);
235         HBox* profile_packer = manage (new HBox);
236         HBox* observation_packer = manage (new HBox);
237         
238         l = manage (new Gtk::Label (_("Profile/Settings:")));
239         profile_packer->pack_start (*l, false, false);
240         profile_packer->pack_start (_profile_combo, true, true);
241         profile_packer->set_spacing (12);
242         profile_packer->set_border_width (12);
243         
244         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.")));
245         observation_packer->pack_start (*l, false, false);
246
247         fkey_packer->pack_start (*profile_packer, false, false);
248         fkey_packer->pack_start (function_key_scroller, true, true);
249         fkey_packer->pack_start (*observation_packer, false, false);
250         fkey_packer->set_spacing (12);
251         function_key_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
252         function_key_scroller.add (function_key_editor);
253         append_page (*fkey_packer, _("Function Keys"));
254
255         build_available_action_menu ();
256         build_function_key_editor ();
257         refresh_function_key_editor ();
258         fkey_packer->show_all();
259 }
260
261 CellRendererCombo*
262 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
263 {
264         CellRendererCombo* renderer = manage (new CellRendererCombo);
265         renderer->property_model() = model;
266         renderer->property_editable() = true;
267         renderer->property_text_column() = 0;
268         renderer->property_has_entry() = false;
269         renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
270
271         return renderer;
272 }
273
274 void
275 MackieControlProtocolGUI::build_available_action_menu ()
276 {
277         /* build a model of all available actions (needs to be tree structured
278          * more)
279          */
280
281         available_action_model = TreeStore::create (available_action_columns);
282
283         vector<string> paths;
284         vector<string> labels;
285         vector<string> tooltips;
286         vector<string> keys;
287         vector<AccelKey> bindings;
288         typedef std::map<string,TreeIter> NodeMap;
289         NodeMap nodes;
290         NodeMap::iterator r;
291
292         ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
293
294         vector<string>::iterator k;
295         vector<string>::iterator p;
296         vector<string>::iterator t;
297         vector<string>::iterator l;
298
299         available_action_model->clear ();
300
301         /* Because there are button bindings built in that are not
302         in the key binding map, there needs to be a way to undo
303         a profile edit. */
304         TreeIter rowp;
305         TreeModel::Row parent;
306         rowp = available_action_model->append();
307         parent = *(rowp);
308         parent[available_action_columns.name] = _("Remove Binding");
309
310         /* Key aliasing */
311
312         rowp = available_action_model->append();
313         parent = *(rowp);
314         parent[available_action_columns.name] = _("Shift");
315         rowp = available_action_model->append();
316         parent = *(rowp);
317         parent[available_action_columns.name] = _("Control");
318         rowp = available_action_model->append();
319         parent = *(rowp);
320         parent[available_action_columns.name] = _("Option");
321         rowp = available_action_model->append();
322         parent = *(rowp);
323         parent[available_action_columns.name] = _("CmdAlt");
324
325         
326         for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
327
328                 TreeModel::Row row;
329                 vector<string> parts;
330
331                 parts.clear ();
332
333                 split (*p, parts, '/');
334
335                 if (parts.empty()) {
336                         continue;
337                 }
338
339                 //kinda kludgy way to avoid displaying menu items as mappable
340                 if ( parts[1] == _("Main_menu") )
341                         continue;
342                 if ( parts[1] == _("JACK") )
343                         continue;
344                 if ( parts[1] == _("redirectmenu") )
345                         continue;
346                 if ( parts[1] == _("Editor_menus") )
347                         continue;
348                 if ( parts[1] == _("RegionList") )
349                         continue;
350                 if ( parts[1] == _("ProcessorMenu") )
351                         continue;
352
353                 if ((r = nodes.find (parts[1])) == nodes.end()) {
354
355                         /* top level is missing */
356
357                         TreeIter rowp;
358                         TreeModel::Row parent;
359                         rowp = available_action_model->append();
360                         nodes[parts[1]] = rowp;
361                         parent = *(rowp);
362                         parent[available_action_columns.name] = parts[1];
363
364                         row = *(available_action_model->append (parent.children()));
365
366                 } else {
367
368                         row = *(available_action_model->append ((*r->second)->children()));
369
370                 }
371
372                 /* add this action */
373
374                 if (l->empty ()) {
375                         row[available_action_columns.name] = *t;
376                         action_map[*t] = *p;
377                 } else {
378                         row[available_action_columns.name] = *l;
379                         action_map[*l] = *p;
380                 }
381
382                 row[available_action_columns.path] = (*p);
383         }
384 }
385
386 void
387 MackieControlProtocolGUI::build_function_key_editor ()
388 {
389         function_key_editor.append_column (_("Key"), function_key_columns.name);
390
391         TreeViewColumn* col;
392         CellRendererCombo* renderer;
393
394         renderer = make_action_renderer (available_action_model, function_key_columns.plain);
395         col = manage (new TreeViewColumn (_("Plain"), *renderer));
396         col->add_attribute (renderer->property_text(), function_key_columns.plain);
397         function_key_editor.append_column (*col);
398         
399         renderer = make_action_renderer (available_action_model, function_key_columns.shift);
400         col = manage (new TreeViewColumn (_("Shift"), *renderer));
401         col->add_attribute (renderer->property_text(), function_key_columns.shift);
402         function_key_editor.append_column (*col);
403
404         renderer = make_action_renderer (available_action_model, function_key_columns.control);
405         col = manage (new TreeViewColumn (_("Control"), *renderer));
406         col->add_attribute (renderer->property_text(), function_key_columns.control);
407         function_key_editor.append_column (*col);
408
409         renderer = make_action_renderer (available_action_model, function_key_columns.option);
410         col = manage (new TreeViewColumn (_("Option"), *renderer));
411         col->add_attribute (renderer->property_text(), function_key_columns.option);
412         function_key_editor.append_column (*col);
413
414         renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
415         col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
416         col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
417         function_key_editor.append_column (*col);
418
419         renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
420         col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
421         col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
422         function_key_editor.append_column (*col);
423
424         function_key_model = ListStore::create (function_key_columns);
425         function_key_editor.set_model (function_key_model);
426 }
427
428 void
429 MackieControlProtocolGUI::refresh_function_key_editor ()
430 {
431         function_key_editor.set_model (Glib::RefPtr<TreeModel>());
432         function_key_model->clear ();
433
434         /* now fill with data */
435
436         TreeModel::Row row;
437         DeviceProfile dp (_cp.device_profile());
438         DeviceInfo di;
439
440         for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
441
442                 Mackie::Button::ID bid = (Mackie::Button::ID) n;
443
444                 row = *(function_key_model->append());
445                 if (di.global_buttons().find (bid) == di.global_buttons().end()) {
446                         row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
447                 } else {
448                         row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
449                 }
450                 row[function_key_columns.id] = bid;
451
452                 Glib::RefPtr<Gtk::Action> act;
453                 string action;
454                 const string defstring = "\u2022";
455
456                 action = dp.get_button_action (bid, 0);
457                 if (action.empty()) {
458                         row[function_key_columns.plain] = defstring;
459                 } else {
460                         if (action.find ('/') == string::npos) {
461                                 /* Probably a key alias */
462                                 row[function_key_columns.plain] = action;
463                         } else {
464                                 
465                                 act = ActionManager::get_action (action.c_str());
466                                 if (act) {
467                                         row[function_key_columns.plain] = act->get_label();
468                                 } else {
469                                         row[function_key_columns.plain] = defstring;
470                                 }
471                         }
472                 }
473
474                 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
475                 if (action.empty()) {
476                         row[function_key_columns.control] = defstring;
477                 } else {
478                         if (action.find ('/') == string::npos) {
479                                 /* Probably a key alias */
480                                 row[function_key_columns.control] = action;
481                         } else {
482                                 act = ActionManager::get_action (action.c_str());
483                                 if (act) {
484                                         row[function_key_columns.control] = act->get_label();
485                                 } else {
486                                         row[function_key_columns.control] = defstring;
487                                 }
488                         }
489                 }
490
491                 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
492                 if (action.empty()) {
493                         row[function_key_columns.shift] = defstring;
494                 } else {
495                         if (action.find ('/') == string::npos) {
496                                 /* Probably a key alias */
497                                 row[function_key_columns.shift] = action;
498                         } else {
499                                 act = ActionManager::get_action (action.c_str());
500                                 if (act) {
501                                         row[function_key_columns.shift] = act->get_label();
502                                 } else {
503                                         row[function_key_columns.shift] = defstring;
504                                 }
505                         }
506                 }
507
508                 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
509                 if (action.empty()) {
510                         row[function_key_columns.option] = defstring;
511                 } else {
512                         if (action.find ('/') == string::npos) {
513                                 /* Probably a key alias */
514                                 row[function_key_columns.option] = action;
515                         } else {
516                                 act = ActionManager::get_action (action.c_str());
517                                 if (act) {
518                                         row[function_key_columns.option] = act->get_label();
519                                 } else {
520                                         row[function_key_columns.option] = defstring;
521                                 }
522                         }
523                 }
524
525                 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
526                 if (action.empty()) {
527                         row[function_key_columns.cmdalt] = defstring;
528                 } else {
529                         if (action.find ('/') == string::npos) {
530                                 /* Probably a key alias */
531                                 row[function_key_columns.cmdalt] = action;
532                         } else {
533                                 act = ActionManager::get_action (action.c_str());
534                                 if (act) {
535                                         row[function_key_columns.cmdalt] = act->get_label();
536                                 } else {
537                                         row[function_key_columns.cmdalt] = defstring;
538                                 }
539                         }
540                 }
541
542                 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
543                 if (action.empty()) {
544                         row[function_key_columns.shiftcontrol] = defstring;
545                 } else {
546                         act = ActionManager::get_action (action.c_str());
547                         if (act) {
548                                 row[function_key_columns.shiftcontrol] = act->get_label();
549                         } else {
550                                 row[function_key_columns.shiftcontrol] = defstring;
551                         }
552                 }
553         }
554
555         function_key_editor.set_model (function_key_model);
556 }
557
558 void
559 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
560 {
561         // Remove Binding is not in the action map but still valid
562         bool remove (false);
563         if ( text == "Remove Binding") {
564                 remove = true;
565         }
566         Gtk::TreePath path(sPath);
567         Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
568
569         if (row) {
570
571                 std::map<std::string,std::string>::iterator i = action_map.find (text);
572                 
573                 if (i == action_map.end()) {
574                         if (!remove) {
575                                 return;
576                         }
577                 }
578                 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
579
580                 if (act || remove) {
581                         /* update visible text, using string supplied by
582                            available action model so that it matches and is found
583                            within the model.
584                         */
585                         if (remove) {
586                                 Glib::ustring dot = "\u2022";
587                                 (*row).set_value (col.index(), dot);
588                         } else {
589                                 (*row).set_value (col.index(), text);
590                         }
591
592                         /* update the current DeviceProfile, using the full
593                          * path
594                          */
595
596                         int modifier;
597
598                         switch (col.index()) {
599                         case 3:
600                                 modifier = MackieControlProtocol::MODIFIER_SHIFT;
601                                 break;
602                         case 4:
603                                 modifier = MackieControlProtocol::MODIFIER_CONTROL;
604                                 break;
605                         case 5:
606                                 modifier = MackieControlProtocol::MODIFIER_OPTION;
607                                 break;
608                         case 6:
609                                 modifier = MackieControlProtocol::MODIFIER_CMDALT;
610                                 break;
611                         case 7:
612                                 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
613                                 break;
614                         default:
615                                 modifier = 0;
616                         }
617
618                         if (remove) {
619                                 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
620                         } else {
621                                 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
622                         }
623
624                 } else {
625                         std::cerr << "no such action\n";
626                 }
627         }
628 }
629
630 void
631 MackieControlProtocolGUI::surface_combo_changed ()
632 {
633         _cp.not_session_load();
634         _cp.set_device (_surface_combo.get_active_text());
635
636         if (_cp.device_info().uses_ipmidi()) {
637                 ipmidi_base_port_spinner.set_sensitive (true);
638                 _input_port_combo.set_sensitive (false);
639                 _output_port_combo.set_sensitive (false);
640         } else {
641                 ipmidi_base_port_spinner.set_sensitive (false);
642                 _input_port_combo.set_sensitive (true);
643                 _output_port_combo.set_sensitive (true);
644         }
645 }
646
647 void
648 MackieControlProtocolGUI::profile_combo_changed ()
649 {
650         string profile = _profile_combo.get_active_text();
651
652         _cp.set_profile (profile);
653
654         refresh_function_key_editor ();
655 }
656
657 void
658 MackieControlProtocolGUI::ipmidi_spinner_changed ()
659 {
660         _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));
661 }
662
663 void
664 MackieControlProtocolGUI::discover_clicked ()
665 {
666         /* this should help to get things started */
667         _cp.midi_connectivity_established ();
668 }
669
670 void
671 MackieControlProtocolGUI::recalibrate_faders ()
672 {
673         _cp.recalibrate_faders ();
674 }
675
676 void
677 MackieControlProtocolGUI::toggle_backlight ()
678 {
679         _cp.toggle_backlight ();
680 }
681
682 void
683 MackieControlProtocolGUI::touch_sensitive_change ()
684 {
685         int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
686         _cp.set_touch_sensitivity (sensitivity);
687 }