2 Copyright (C) 2010 Paul Davis
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.
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.
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.
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>
31 #include "pbd/error.h"
32 #include "pbd/unwind.h"
33 #include "pbd/strsplit.h"
34 #include "pbd/stacktrace.h"
36 #include "gtkmm2ext/actions.h"
37 #include "gtkmm2ext/bindings.h"
38 #include "gtkmm2ext/gui_thread.h"
39 #include "gtkmm2ext/utils.h"
41 #include "ardour/audioengine.h"
42 #include "ardour/port.h"
43 #include "ardour/rc_configuration.h"
45 #include "mackie_control_protocol.h"
46 #include "device_info.h"
49 #include "surface_port.h"
55 using namespace ArdourSurface;
56 using namespace Mackie;
59 MackieControlProtocol::get_gui () const
62 const_cast<MackieControlProtocol*>(this)->build_gui ();
64 static_cast<Gtk::Notebook*>(_gui)->show_all();
69 MackieControlProtocol::tear_down_gui ()
72 Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
78 delete (MackieControlProtocolGUI*) _gui;
83 MackieControlProtocol::build_gui ()
85 _gui = (void *) new MackieControlProtocolGUI (*this);
88 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
91 , touch_sensitivity_adjustment (0, 0, 9, 1, 4)
92 , touch_sensitivity_scale (touch_sensitivity_adjustment)
93 , recalibrate_fader_button (_("Recalibrate Faders"))
94 , ipmidi_base_port_adjustment (_cp.ipmidi_base(), 0, 32767, 1, 1000)
95 , discover_button (_("Discover Mackie Devices"))
96 , _device_dependent_widget (0)
97 , _ignore_profile_changed (false)
98 , ignore_active_change (false)
101 Gtk::Alignment* align;
104 set_border_width (12);
106 table.set_row_spacings (4);
107 table.set_col_spacings (6);
108 table.set_border_width (12);
109 table.set_homogeneous (false);
111 l = manage (new Gtk::Label (_("Device Type:")));
112 l->set_alignment (1.0, 0.5);
113 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
114 table.attach (_surface_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
117 vector<string> surfaces;
119 for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
120 surfaces.push_back (i->first);
122 Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
123 _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
125 _cp.DeviceChanged.connect (device_change_connection, invalidator (*this), boost::bind (&MackieControlProtocolGUI::device_changed, this), gui_context());
126 _cp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&MackieControlProtocolGUI::connection_handler, this), gui_context());
128 ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
130 /* device-dependent part */
132 device_dependent_row = row;
134 if (_device_dependent_widget) {
135 table.remove (*_device_dependent_widget);
136 _device_dependent_widget = 0;
139 _device_dependent_widget = device_dependent_widget ();
140 table.attach (*_device_dependent_widget, 0, 12, row, row+1, AttachOptions(0), AttachOptions(0), 0, 0);
143 /* back to the boilerplate */
145 RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
146 touch_move_mode_button.set_group (rb_group);
148 recalibrate_fader_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::recalibrate_faders));
149 backlight_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::toggle_backlight));
151 touch_sensitivity_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::touch_sensitive_change));
152 touch_sensitivity_scale.set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
154 l = manage (new Gtk::Label (_("Button click")));
155 l->set_alignment (1.0, 0.5);
156 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
157 align = manage (new Alignment);
158 align->set (0.0, 0.5);
159 align->add (relay_click_button);
160 table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
163 l = manage (new Gtk::Label (_("Backlight")));
164 l->set_alignment (1.0, 0.5);
165 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
166 align = manage (new Alignment);
167 align->set (0.0, 0.5);
168 align->add (backlight_button);
169 table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
172 l = manage (new Gtk::Label (_("Send Fader Position Only When Touched")));
173 l->set_alignment (1.0, 0.5);
174 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
175 align = manage (new Alignment);
176 align->set (0.0, 0.5);
177 align->add (absolute_touch_mode_button);
178 table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
181 l = manage (new Gtk::Label (_("Send Fader Position When Moved")));
182 l->set_alignment (1.0, 0.5);
183 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
184 align = manage (new Alignment);
185 align->set (0.0, 0.5);
186 align->add (touch_move_mode_button);
187 table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
190 l = manage (new Gtk::Label (_("Fader Touch Sense Sensitivity")));
191 l->set_alignment (1.0, 0.5);
192 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
193 touch_sensitivity_scale.property_digits() = 0;
194 touch_sensitivity_scale.property_draw_value() = false;
195 table.attach (touch_sensitivity_scale, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
197 table.attach (recalibrate_fader_button, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
201 table.attach (discover_button, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
202 discover_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::discover_clicked));
205 vector<string> profiles;
207 for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
208 cerr << "add discovered profile " << i->first << endl;
209 profiles.push_back (i->first);
211 Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
212 cerr << "set active profile from " << p.device_profile().name() << endl;
213 _profile_combo.set_active_text (p.device_profile().name());
214 _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
216 append_page (table, _("Device Setup"));
219 /* function key editor */
221 VBox* fkey_packer = manage (new VBox);
222 HBox* profile_packer = manage (new HBox);
223 HBox* observation_packer = manage (new HBox);
225 l = manage (new Gtk::Label (_("Profile/Settings:")));
226 profile_packer->pack_start (*l, false, false);
227 profile_packer->pack_start (_profile_combo, true, true);
228 profile_packer->set_spacing (12);
229 profile_packer->set_border_width (12);
231 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.")));
232 observation_packer->pack_start (*l, false, false);
234 fkey_packer->pack_start (*profile_packer, false, false);
235 fkey_packer->pack_start (function_key_scroller, true, true);
236 fkey_packer->pack_start (*observation_packer, false, false);
237 fkey_packer->set_spacing (12);
238 function_key_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
239 function_key_scroller.add (function_key_editor);
240 append_page (*fkey_packer, _("Function Keys"));
242 build_available_action_menu ();
243 build_function_key_editor ();
244 refresh_function_key_editor ();
245 fkey_packer->show_all();
249 MackieControlProtocolGUI::connection_handler ()
251 /* ignore all changes to combobox active strings here, because we're
252 updating them to match a new ("external") reality - we were called
253 because port connections have changed.
256 PBD::Unwinder<bool> ici (ignore_active_change, true);
258 vector<Gtk::ComboBox*>::iterator ic;
259 vector<Gtk::ComboBox*>::iterator oc;
261 vector<string> midi_inputs;
262 vector<string> midi_outputs;
264 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
265 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
267 for (ic = input_combos.begin(), oc = output_combos.begin(); ic != input_combos.end() && oc != output_combos.end(); ++ic, ++oc) {
269 boost::shared_ptr<Surface> surface = _cp.get_surface_by_raw_pointer ((*ic)->get_data ("surface"));
272 update_port_combos (midi_inputs, midi_outputs, *ic, *oc, surface);
278 MackieControlProtocolGUI::update_port_combos (vector<string> const& midi_inputs, vector<string> const& midi_outputs,
279 Gtk::ComboBox* input_combo,
280 Gtk::ComboBox* output_combo,
281 boost::shared_ptr<Surface> surface)
283 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
284 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
285 bool input_found = false;
286 bool output_found = false;
289 input_combo->set_model (input);
290 output_combo->set_model (output);
292 Gtk::TreeModel::Children children = input->children();
293 Gtk::TreeModel::Children::iterator i;
294 i = children.begin();
295 ++i; /* skip "Disconnected" */
298 for (n = 1; i != children.end(); ++i, ++n) {
299 string port_name = (*i)[midi_port_columns.full_name];
300 if (surface->port().input().connected_to (port_name)) {
301 input_combo->set_active (n);
308 input_combo->set_active (0); /* disconnected */
311 children = output->children();
312 i = children.begin();
313 ++i; /* skip "Disconnected" */
315 for (n = 1; i != children.end(); ++i, ++n) {
316 string port_name = (*i)[midi_port_columns.full_name];
317 if (surface->port().output().connected_to (port_name)) {
318 output_combo->set_active (n);
325 output_combo->set_active (0); /* disconnected */
330 MackieControlProtocolGUI::device_dependent_widget ()
332 Gtk::Table* dd_table;
336 uint32_t n_surfaces = 1 + _cp.device_info().extenders();
337 uint32_t main_pos = _cp.device_info().master_position();
339 if (!_cp.device_info().uses_ipmidi()) {
340 dd_table = Gtk::manage (new Gtk::Table (n_surfaces, 2));
342 dd_table = Gtk::manage (new Gtk::Table (1, 2));
345 dd_table = Gtk::manage (new Gtk::Table (2, n_surfaces));
346 dd_table->set_row_spacings (4);
347 dd_table->set_col_spacings (6);
348 dd_table->set_border_width (12);
350 _surface_combo.set_active_text (_cp.device_info().name());
352 vector<string> midi_inputs;
353 vector<string> midi_outputs;
355 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsPhysical), midi_inputs);
356 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsPhysical), midi_outputs);
358 input_combos.clear ();
359 output_combos.clear ();
361 if (!_cp.device_info().uses_ipmidi()) {
363 for (uint32_t n = 0; n < n_surfaces; ++n) {
365 boost::shared_ptr<Surface> surface = _cp.nth_surface (n);
368 PBD::fatal << string_compose (_("programming error: %1\n"), string_compose ("n=%1 surface not found!", n)) << endmsg;
372 Gtk::ComboBox* input_combo = manage (new Gtk::ComboBox);
373 Gtk::ComboBox* output_combo = manage (new Gtk::ComboBox);
375 update_port_combos (midi_inputs, midi_outputs, input_combo, output_combo, surface);
377 input_combo->pack_start (midi_port_columns.short_name);
378 input_combo->set_data ("surface", surface.get());
379 input_combos.push_back (input_combo);
380 output_combo->pack_start (midi_port_columns.short_name);
381 output_combo->set_data ("surface", surface.get());
382 output_combos.push_back (output_combo);
384 boost::weak_ptr<Surface> ws (surface);
385 input_combo->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &MackieControlProtocolGUI::active_port_changed), input_combo, ws, true));
386 output_combo->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &MackieControlProtocolGUI::active_port_changed), output_combo, ws, false));
389 string receive_string;
391 if (n_surfaces > 1) {
393 send_string = string_compose(_("Main surface at position %1 sends via:"), n + 1);
394 receive_string = string_compose(_("Main surface at position %1 receives via:"), n + 1);
396 send_string = string_compose (_("Extender at position %1 sends via:"), n + 1);
397 receive_string = string_compose (_("Extender at position %1 receives via:"), n + 1);
400 send_string = _("Surface sends via:");
401 receive_string = _("Surface receives via:");
404 l = manage (new Gtk::Label (send_string));
405 l->set_alignment (1.0, 0.5);
406 dd_table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
407 dd_table->attach (*input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
410 l = manage (new Gtk::Label (receive_string));
411 l->set_alignment (1.0, 0.5);
412 dd_table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
413 dd_table->attach (*output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
419 l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
420 l->set_alignment (1.0, 0.5);
422 Gtk::SpinButton* ipmidi_base_port_spinner = manage (new Gtk::SpinButton (ipmidi_base_port_adjustment));
423 dd_table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
424 dd_table->attach (*ipmidi_base_port_spinner, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
432 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
434 CellRendererCombo* renderer = manage (new CellRendererCombo);
435 renderer->property_model() = model;
436 renderer->property_editable() = true;
437 renderer->property_text_column() = 0;
438 renderer->property_has_entry() = false;
439 renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
445 MackieControlProtocolGUI::build_available_action_menu ()
447 /* build a model of all available actions (needs to be tree structured
451 available_action_model = TreeStore::create (available_action_columns);
453 vector<string> paths;
454 vector<string> labels;
455 vector<string> tooltips;
457 vector<Glib::RefPtr<Gtk::Action> > actions;
459 typedef std::map<string,TreeIter> NodeMap;
463 ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
465 vector<string>::iterator k;
466 vector<string>::iterator p;
467 vector<string>::iterator t;
468 vector<string>::iterator l;
470 available_action_model->clear ();
472 /* Because there are button bindings built in that are not
473 in the key binding map, there needs to be a way to undo
477 TreeModel::Row parent;
478 rowp = available_action_model->append();
480 parent[available_action_columns.name] = _("Remove Binding");
484 rowp = available_action_model->append();
486 parent[available_action_columns.name] = _("Shift");
487 rowp = available_action_model->append();
489 parent[available_action_columns.name] = _("Control");
490 rowp = available_action_model->append();
492 parent[available_action_columns.name] = _("Option");
493 rowp = available_action_model->append();
495 parent[available_action_columns.name] = _("CmdAlt");
497 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
500 vector<string> parts;
504 split (*p, parts, '/');
510 //kinda kludgy way to avoid displaying menu items as mappable
511 if (parts[0] == _("Main Menu") )
513 if (parts[0] == _("JACK") )
515 if (parts[0] == _("redirectmenu") )
517 if (parts[0] == _("RegionList") )
519 if (parts[0] == _("ProcessorMenu") )
522 if ((r = nodes.find (parts[0])) == nodes.end()) {
524 /* top level is missing */
527 TreeModel::Row parent;
528 rowp = available_action_model->append();
529 nodes[parts[0]] = rowp;
531 parent[available_action_columns.name] = parts[0];
533 row = *(available_action_model->append (parent.children()));
537 row = *(available_action_model->append ((*r->second)->children()));
541 /* add this action */
544 row[available_action_columns.name] = *t;
547 row[available_action_columns.name] = *l;
551 row[available_action_columns.path] = *p;
556 MackieControlProtocolGUI::build_function_key_editor ()
558 function_key_editor.append_column (_("Key"), function_key_columns.name);
561 CellRendererCombo* renderer;
563 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
564 col = manage (new TreeViewColumn (_("Plain"), *renderer));
565 col->add_attribute (renderer->property_text(), function_key_columns.plain);
566 function_key_editor.append_column (*col);
568 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
569 col = manage (new TreeViewColumn (_("Shift"), *renderer));
570 col->add_attribute (renderer->property_text(), function_key_columns.shift);
571 function_key_editor.append_column (*col);
573 renderer = make_action_renderer (available_action_model, function_key_columns.control);
574 col = manage (new TreeViewColumn (_("Control"), *renderer));
575 col->add_attribute (renderer->property_text(), function_key_columns.control);
576 function_key_editor.append_column (*col);
578 renderer = make_action_renderer (available_action_model, function_key_columns.option);
579 col = manage (new TreeViewColumn (_("Option"), *renderer));
580 col->add_attribute (renderer->property_text(), function_key_columns.option);
581 function_key_editor.append_column (*col);
583 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
584 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
585 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
586 function_key_editor.append_column (*col);
588 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
589 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
590 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
591 function_key_editor.append_column (*col);
593 function_key_model = ListStore::create (function_key_columns);
594 function_key_editor.set_model (function_key_model);
598 MackieControlProtocolGUI::refresh_function_key_editor ()
600 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
601 function_key_model->clear ();
603 /* now fill with data */
606 DeviceProfile dp (_cp.device_profile());
609 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
611 Mackie::Button::ID bid = (Mackie::Button::ID) n;
613 row = *(function_key_model->append());
614 if (di.global_buttons().find (bid) == di.global_buttons().end()) {
615 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
617 row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
619 row[function_key_columns.id] = bid;
621 Glib::RefPtr<Gtk::Action> act;
623 const string defstring = "\u2022";
625 /* We only allow plain bindings for Fn keys. All others are
626 * reserved for hard-coded actions.
629 if (bid >= Mackie::Button::F1 && bid <= Mackie::Button::F8) {
631 action = dp.get_button_action (bid, 0);
632 if (action.empty()) {
633 row[function_key_columns.plain] = defstring;
635 if (action.find ('/') == string::npos) {
636 /* Probably a key alias */
637 row[function_key_columns.plain] = action;
640 act = ActionManager::get_action (action, false);
642 row[function_key_columns.plain] = act->get_label();
644 row[function_key_columns.plain] = defstring;
650 /* We only allow plain bindings for Fn keys. All others are
651 * reserved for hard-coded actions.
654 if (bid >= Mackie::Button::F1 && bid <= Mackie::Button::F8) {
656 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
657 if (action.empty()) {
658 row[function_key_columns.shift] = defstring;
660 if (action.find ('/') == string::npos) {
661 /* Probably a key alias */
662 row[function_key_columns.shift] = action;
664 act = ActionManager::get_action (action, false);
666 row[function_key_columns.shift] = act->get_label();
668 row[function_key_columns.shift] = defstring;
674 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
675 if (action.empty()) {
676 row[function_key_columns.control] = defstring;
678 if (action.find ('/') == string::npos) {
679 /* Probably a key alias */
680 row[function_key_columns.control] = action;
682 act = ActionManager::get_action (action, false);
684 row[function_key_columns.control] = act->get_label();
686 row[function_key_columns.control] = defstring;
691 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
692 if (action.empty()) {
693 row[function_key_columns.option] = defstring;
695 if (action.find ('/') == string::npos) {
696 /* Probably a key alias */
697 row[function_key_columns.option] = action;
699 act = ActionManager::get_action (action, false);
701 row[function_key_columns.option] = act->get_label();
703 row[function_key_columns.option] = defstring;
708 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
709 if (action.empty()) {
710 row[function_key_columns.cmdalt] = defstring;
712 if (action.find ('/') == string::npos) {
713 /* Probably a key alias */
714 row[function_key_columns.cmdalt] = action;
716 act = ActionManager::get_action (action, false);
718 row[function_key_columns.cmdalt] = act->get_label();
720 row[function_key_columns.cmdalt] = defstring;
725 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
726 if (action.empty()) {
727 row[function_key_columns.shiftcontrol] = defstring;
729 act = ActionManager::get_action (action, false);
731 row[function_key_columns.shiftcontrol] = act->get_label();
733 row[function_key_columns.shiftcontrol] = defstring;
738 function_key_editor.set_model (function_key_model);
742 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
744 // Remove Binding is not in the action map but still valid
746 if ( text == "Remove Binding") {
749 Gtk::TreePath path(sPath);
750 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
754 std::map<std::string,std::string>::iterator i = action_map.find (text);
756 if (i == action_map.end()) {
761 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second, false);
764 /* update visible text, using string supplied by
765 available action model so that it matches and is found
769 Glib::ustring dot = "\u2022";
770 (*row).set_value (col.index(), dot);
772 (*row).set_value (col.index(), text);
775 /* update the current DeviceProfile, using the full
781 switch (col.index()) {
783 modifier = MackieControlProtocol::MODIFIER_SHIFT;
786 modifier = MackieControlProtocol::MODIFIER_CONTROL;
789 modifier = MackieControlProtocol::MODIFIER_OPTION;
792 modifier = MackieControlProtocol::MODIFIER_CMDALT;
795 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
802 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
804 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
807 _ignore_profile_changed = true;
808 _profile_combo.set_active_text ( _cp.device_profile().name() );
809 _ignore_profile_changed = false;
812 std::cerr << "no such action\n";
818 MackieControlProtocolGUI::surface_combo_changed ()
820 _cp.set_device (_surface_combo.get_active_text(), false);
824 MackieControlProtocolGUI::device_changed ()
826 if (_device_dependent_widget) {
827 table.remove (*_device_dependent_widget);
828 _device_dependent_widget = 0;
831 _device_dependent_widget = device_dependent_widget ();
832 _device_dependent_widget->show_all ();
834 table.attach (*_device_dependent_widget, 0, 12, device_dependent_row, device_dependent_row+1, AttachOptions(0), AttachOptions(0), 0, 0);
838 MackieControlProtocolGUI::profile_combo_changed ()
840 if (!_ignore_profile_changed) {
841 string profile = _profile_combo.get_active_text();
843 _cp.set_profile (profile);
845 refresh_function_key_editor ();
850 MackieControlProtocolGUI::ipmidi_spinner_changed ()
852 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_adjustment.get_value()));
856 MackieControlProtocolGUI::discover_clicked ()
858 /* this should help to get things started */
863 MackieControlProtocolGUI::recalibrate_faders ()
865 _cp.recalibrate_faders ();
869 MackieControlProtocolGUI::toggle_backlight ()
871 _cp.toggle_backlight ();
875 MackieControlProtocolGUI::touch_sensitive_change ()
877 int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
878 _cp.set_touch_sensitivity (sensitivity);
881 Glib::RefPtr<Gtk::ListStore>
882 MackieControlProtocolGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
884 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
887 row = *store->append ();
888 row[midi_port_columns.full_name] = string();
889 row[midi_port_columns.short_name] = _("Disconnected");
891 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
892 row = *store->append ();
893 row[midi_port_columns.full_name] = *p;
894 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
896 pn = (*p).substr ((*p).find (':') + 1);
898 row[midi_port_columns.short_name] = pn;
905 MackieControlProtocolGUI::active_port_changed (Gtk::ComboBox* combo, boost::weak_ptr<Surface> ws, bool for_input)
907 if (ignore_active_change) {
911 boost::shared_ptr<Surface> surface = ws.lock();
917 TreeModel::iterator active = combo->get_active ();
918 string new_port = (*active)[midi_port_columns.full_name];
920 if (new_port.empty()) {
922 surface->port().input().disconnect_all ();
924 surface->port().output().disconnect_all ();
931 if (!surface->port().input().connected_to (new_port)) {
932 surface->port().input().disconnect_all ();
933 surface->port().input().connect (new_port);
936 if (!surface->port().output().connected_to (new_port)) {
937 surface->port().output().disconnect_all ();
938 surface->port().output().connect (new_port);