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[1] == _("Main_menu") )
513 if ( parts[1] == _("JACK") )
515 if ( parts[1] == _("redirectmenu") )
517 if ( parts[1] == _("Editor_menus") )
519 if ( parts[1] == _("RegionList") )
521 if ( parts[1] == _("ProcessorMenu") )
524 if ((r = nodes.find (parts[1])) == nodes.end()) {
526 /* top level is missing */
529 TreeModel::Row parent;
530 rowp = available_action_model->append();
531 nodes[parts[1]] = rowp;
533 parent[available_action_columns.name] = parts[1];
535 row = *(available_action_model->append (parent.children()));
539 row = *(available_action_model->append ((*r->second)->children()));
543 /* add this action */
546 row[available_action_columns.name] = *t;
549 row[available_action_columns.name] = *l;
553 row[available_action_columns.path] = (*p);
558 MackieControlProtocolGUI::build_function_key_editor ()
560 function_key_editor.append_column (_("Key"), function_key_columns.name);
563 CellRendererCombo* renderer;
565 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
566 col = manage (new TreeViewColumn (_("Plain"), *renderer));
567 col->add_attribute (renderer->property_text(), function_key_columns.plain);
568 function_key_editor.append_column (*col);
570 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
571 col = manage (new TreeViewColumn (_("Shift"), *renderer));
572 col->add_attribute (renderer->property_text(), function_key_columns.shift);
573 function_key_editor.append_column (*col);
575 renderer = make_action_renderer (available_action_model, function_key_columns.control);
576 col = manage (new TreeViewColumn (_("Control"), *renderer));
577 col->add_attribute (renderer->property_text(), function_key_columns.control);
578 function_key_editor.append_column (*col);
580 renderer = make_action_renderer (available_action_model, function_key_columns.option);
581 col = manage (new TreeViewColumn (_("Option"), *renderer));
582 col->add_attribute (renderer->property_text(), function_key_columns.option);
583 function_key_editor.append_column (*col);
585 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
586 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
587 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
588 function_key_editor.append_column (*col);
590 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
591 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
592 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
593 function_key_editor.append_column (*col);
595 function_key_model = ListStore::create (function_key_columns);
596 function_key_editor.set_model (function_key_model);
600 MackieControlProtocolGUI::refresh_function_key_editor ()
602 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
603 function_key_model->clear ();
605 /* now fill with data */
608 DeviceProfile dp (_cp.device_profile());
611 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
613 Mackie::Button::ID bid = (Mackie::Button::ID) n;
615 row = *(function_key_model->append());
616 if (di.global_buttons().find (bid) == di.global_buttons().end()) {
617 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
619 row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
621 row[function_key_columns.id] = bid;
623 Glib::RefPtr<Gtk::Action> act;
625 const string defstring = "\u2022";
627 /* We only allow plain bindings for Fn keys. All others are
628 * reserved for hard-coded actions.
631 if (bid >= Mackie::Button::F1 && bid <= Mackie::Button::F8) {
633 action = dp.get_button_action (bid, 0);
634 if (action.empty()) {
635 row[function_key_columns.plain] = defstring;
637 if (action.find ('/') == string::npos) {
638 /* Probably a key alias */
639 row[function_key_columns.plain] = action;
642 act = ActionManager::get_action (action.c_str());
644 row[function_key_columns.plain] = act->get_label();
646 row[function_key_columns.plain] = defstring;
652 /* We only allow plain bindings for Fn keys. All others are
653 * reserved for hard-coded actions.
656 if (bid >= Mackie::Button::F1 && bid <= Mackie::Button::F8) {
658 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
659 if (action.empty()) {
660 row[function_key_columns.shift] = defstring;
662 if (action.find ('/') == string::npos) {
663 /* Probably a key alias */
664 row[function_key_columns.shift] = action;
666 act = ActionManager::get_action (action.c_str());
668 row[function_key_columns.shift] = act->get_label();
670 row[function_key_columns.shift] = defstring;
676 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
677 if (action.empty()) {
678 row[function_key_columns.control] = defstring;
680 if (action.find ('/') == string::npos) {
681 /* Probably a key alias */
682 row[function_key_columns.control] = action;
684 act = ActionManager::get_action (action.c_str());
686 row[function_key_columns.control] = act->get_label();
688 row[function_key_columns.control] = defstring;
693 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
694 if (action.empty()) {
695 row[function_key_columns.option] = defstring;
697 if (action.find ('/') == string::npos) {
698 /* Probably a key alias */
699 row[function_key_columns.option] = action;
701 act = ActionManager::get_action (action.c_str());
703 row[function_key_columns.option] = act->get_label();
705 row[function_key_columns.option] = defstring;
710 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
711 if (action.empty()) {
712 row[function_key_columns.cmdalt] = defstring;
714 if (action.find ('/') == string::npos) {
715 /* Probably a key alias */
716 row[function_key_columns.cmdalt] = action;
718 act = ActionManager::get_action (action.c_str());
720 row[function_key_columns.cmdalt] = act->get_label();
722 row[function_key_columns.cmdalt] = defstring;
727 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
728 if (action.empty()) {
729 row[function_key_columns.shiftcontrol] = defstring;
731 act = ActionManager::get_action (action.c_str());
733 row[function_key_columns.shiftcontrol] = act->get_label();
735 row[function_key_columns.shiftcontrol] = defstring;
740 function_key_editor.set_model (function_key_model);
744 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
746 // Remove Binding is not in the action map but still valid
748 if ( text == "Remove Binding") {
751 Gtk::TreePath path(sPath);
752 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
756 std::map<std::string,std::string>::iterator i = action_map.find (text);
758 if (i == action_map.end()) {
763 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
766 /* update visible text, using string supplied by
767 available action model so that it matches and is found
771 Glib::ustring dot = "\u2022";
772 (*row).set_value (col.index(), dot);
774 (*row).set_value (col.index(), text);
777 /* update the current DeviceProfile, using the full
783 switch (col.index()) {
785 modifier = MackieControlProtocol::MODIFIER_SHIFT;
788 modifier = MackieControlProtocol::MODIFIER_CONTROL;
791 modifier = MackieControlProtocol::MODIFIER_OPTION;
794 modifier = MackieControlProtocol::MODIFIER_CMDALT;
797 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
804 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
806 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
809 _ignore_profile_changed = true;
810 _profile_combo.set_active_text ( _cp.device_profile().name() );
811 _ignore_profile_changed = false;
814 std::cerr << "no such action\n";
820 MackieControlProtocolGUI::surface_combo_changed ()
822 _cp.set_device (_surface_combo.get_active_text(), false);
826 MackieControlProtocolGUI::device_changed ()
828 if (_device_dependent_widget) {
829 table.remove (*_device_dependent_widget);
830 _device_dependent_widget = 0;
833 _device_dependent_widget = device_dependent_widget ();
834 _device_dependent_widget->show_all ();
836 table.attach (*_device_dependent_widget, 0, 12, device_dependent_row, device_dependent_row+1, AttachOptions(0), AttachOptions(0), 0, 0);
840 MackieControlProtocolGUI::profile_combo_changed ()
842 if (!_ignore_profile_changed) {
843 string profile = _profile_combo.get_active_text();
845 _cp.set_profile (profile);
847 refresh_function_key_editor ();
852 MackieControlProtocolGUI::ipmidi_spinner_changed ()
854 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_adjustment.get_value()));
858 MackieControlProtocolGUI::discover_clicked ()
860 /* this should help to get things started */
865 MackieControlProtocolGUI::recalibrate_faders ()
867 _cp.recalibrate_faders ();
871 MackieControlProtocolGUI::toggle_backlight ()
873 _cp.toggle_backlight ();
877 MackieControlProtocolGUI::touch_sensitive_change ()
879 int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
880 _cp.set_touch_sensitivity (sensitivity);
883 Glib::RefPtr<Gtk::ListStore>
884 MackieControlProtocolGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
886 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
889 row = *store->append ();
890 row[midi_port_columns.full_name] = string();
891 row[midi_port_columns.short_name] = _("Disconnected");
893 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
894 row = *store->append ();
895 row[midi_port_columns.full_name] = *p;
896 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
898 pn = (*p).substr ((*p).find (':') + 1);
900 row[midi_port_columns.short_name] = pn;
907 MackieControlProtocolGUI::active_port_changed (Gtk::ComboBox* combo, boost::weak_ptr<Surface> ws, bool for_input)
909 if (ignore_active_change) {
913 boost::shared_ptr<Surface> surface = ws.lock();
919 TreeModel::iterator active = combo->get_active ();
920 string new_port = (*active)[midi_port_columns.full_name];
922 if (new_port.empty()) {
924 surface->port().input().disconnect_all ();
926 surface->port().output().disconnect_all ();
933 if (!surface->port().input().connected_to (new_port)) {
934 surface->port().input().disconnect_all ();
935 surface->port().input().connect (new_port);
938 if (!surface->port().output().connected_to (new_port)) {
939 surface->port().output().disconnect_all ();
940 surface->port().output().connect (new_port);