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/strsplit.h"
33 #include "gtkmm2ext/utils.h"
34 #include "gtkmm2ext/actions.h"
36 #include "ardour/rc_configuration.h"
38 #include "mackie_control_protocol.h"
39 #include "device_info.h"
46 using namespace ArdourSurface;
47 using namespace Mackie;
50 MackieControlProtocol::get_gui () const
53 const_cast<MackieControlProtocol*>(this)->build_gui ();
55 static_cast<Gtk::Notebook*>(_gui)->show_all();
60 MackieControlProtocol::tear_down_gui ()
63 Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
69 delete (MackieControlProtocolGUI*) _gui;
74 MackieControlProtocol::build_gui ()
76 _gui = (void *) new MackieControlProtocolGUI (*this);
79 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
81 , touch_sensitivity_adjustment (0, 0, 9, 1, 4)
82 , touch_sensitivity_scale (touch_sensitivity_adjustment)
83 , recalibrate_fader_button (_("Recalibrate Faders"))
84 , ipmidi_base_port_adjustment (_cp.ipmidi_base(), 0, 32767, 1, 1000)
85 , ipmidi_base_port_spinner (ipmidi_base_port_adjustment)
86 , discover_button (_("Discover Mackie Devices"))
89 Gtk::Alignment* align;
91 set_border_width (12);
93 Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 9));
94 table->set_row_spacings (4);
95 table->set_col_spacings (6);
96 table->set_border_width (12);
97 l = manage (new Gtk::Label (_("Device Type:")));
98 l->set_alignment (1.0, 0.5);
99 table->attach (*l, 0, 1, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
100 table->attach (_surface_combo, 1, 2, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 20);
102 vector<string> surfaces;
104 for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
105 surfaces.push_back (i->first);
107 Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
108 _surface_combo.set_active_text (p.device_info().name());
109 _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
111 RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
112 touch_move_mode_button.set_group (rb_group);
114 recalibrate_fader_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::recalibrate_faders));
115 backlight_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::toggle_backlight));
117 touch_sensitivity_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::touch_sensitive_change));
118 touch_sensitivity_scale.set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
120 l = manage (new Gtk::Label (_("Button click")));
121 l->set_alignment (1.0, 0.5);
122 table->attach (*l, 0, 1, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
123 align = manage (new Alignment);
124 align->set (0.0, 0.5);
125 align->add (relay_click_button);
126 table->attach (*align, 1, 2, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
127 l = manage (new Gtk::Label (_("Backlight")));
128 l->set_alignment (1.0, 0.5);
129 table->attach (*l, 0, 1, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
130 align = manage (new Alignment);
131 align->set (0.0, 0.5);
132 align->add (backlight_button);
133 table->attach (*align, 1, 2, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
134 l = manage (new Gtk::Label (_("Send Fader Position Only When Touched")));
135 l->set_alignment (1.0, 0.5);
136 table->attach (*l, 0, 1, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
137 align = manage (new Alignment);
138 align->set (0.0, 0.5);
139 align->add (absolute_touch_mode_button);
140 table->attach (*align, 1, 2, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
141 l = manage (new Gtk::Label (_("Send Fader Position When Moved")));
142 l->set_alignment (1.0, 0.5);
143 table->attach (*l, 0, 1, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
144 align = manage (new Alignment);
145 align->set (0.0, 0.5);
146 align->add (touch_move_mode_button);
147 table->attach (*align, 1, 2, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
148 l = manage (new Gtk::Label (_("Fader Touch Sense Sensitivity")));
149 l->set_alignment (1.0, 0.5);
150 table->attach (*l, 0, 1, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
151 touch_sensitivity_scale.property_digits() = 0;
152 touch_sensitivity_scale.property_draw_value() = false;
153 table->attach (touch_sensitivity_scale, 1, 2, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
154 table->attach (recalibrate_fader_button, 1, 2, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
156 l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
157 l->set_alignment (1.0, 0.5);
158 table->attach (*l, 0, 1, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
159 table->attach (ipmidi_base_port_spinner, 1, 2, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
161 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
162 ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
164 table->attach (discover_button, 1, 2, 8, 9, AttachOptions(FILL|EXPAND), AttachOptions (0));
165 discover_button.signal_clicked().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::discover_clicked));
167 vector<string> profiles;
169 profiles.push_back ("default");
171 for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
172 profiles.push_back (i->first);
174 Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
175 _profile_combo.set_active_text (p.device_profile().name());
176 _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
178 append_page (*table, _("Device Setup"));
181 /* function key editor */
183 VBox* fkey_packer = manage (new VBox);
184 HBox* profile_packer = manage (new HBox);
185 HBox* observation_packer = manage (new HBox);
187 l = manage (new Gtk::Label (_("Profile/Settings:")));
188 profile_packer->pack_start (*l, false, false);
189 profile_packer->pack_start (_profile_combo, true, true);
190 profile_packer->set_spacing (12);
191 profile_packer->set_border_width (12);
193 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.")));
194 observation_packer->pack_start (*l, false, false);
196 fkey_packer->pack_start (*profile_packer, false, false);
197 fkey_packer->pack_start (function_key_scroller, true, true);
198 fkey_packer->pack_start (*observation_packer, false, false);
199 fkey_packer->set_spacing (12);
200 function_key_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
201 function_key_scroller.add (function_key_editor);
202 append_page (*fkey_packer, _("Function Keys"));
204 build_available_action_menu ();
205 build_function_key_editor ();
206 refresh_function_key_editor ();
207 fkey_packer->show_all();
211 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
213 CellRendererCombo* renderer = manage (new CellRendererCombo);
214 renderer->property_model() = model;
215 renderer->property_editable() = true;
216 renderer->property_text_column() = 0;
217 renderer->property_has_entry() = false;
218 renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
224 MackieControlProtocolGUI::build_available_action_menu ()
226 /* build a model of all available actions (needs to be tree structured
230 available_action_model = TreeStore::create (available_action_columns);
232 vector<string> paths;
233 vector<string> labels;
234 vector<string> tooltips;
236 vector<AccelKey> bindings;
237 typedef std::map<string,TreeIter> NodeMap;
241 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
243 vector<string>::iterator k;
244 vector<string>::iterator p;
245 vector<string>::iterator t;
246 vector<string>::iterator l;
248 available_action_model->clear ();
250 /* Because there are button bindings built in that are not
251 in the key binding map, there needs to be a way to undo
254 TreeModel::Row parent;
255 rowp = available_action_model->append();
257 parent[available_action_columns.name] = _("Remove Binding");
261 rowp = available_action_model->append();
263 parent[available_action_columns.name] = _("Shift");
264 rowp = available_action_model->append();
266 parent[available_action_columns.name] = _("Control");
267 rowp = available_action_model->append();
269 parent[available_action_columns.name] = _("Option");
270 rowp = available_action_model->append();
272 parent[available_action_columns.name] = _("CmdAlt");
275 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
278 vector<string> parts;
282 split (*p, parts, '/');
288 //kinda kludgy way to avoid displaying menu items as mappable
289 if ( parts[1] == _("Main_menu") )
291 if ( parts[1] == _("JACK") )
293 if ( parts[1] == _("redirectmenu") )
295 if ( parts[1] == _("Editor_menus") )
297 if ( parts[1] == _("RegionList") )
299 if ( parts[1] == _("ProcessorMenu") )
302 if ((r = nodes.find (parts[1])) == nodes.end()) {
304 /* top level is missing */
307 TreeModel::Row parent;
308 rowp = available_action_model->append();
309 nodes[parts[1]] = rowp;
311 parent[available_action_columns.name] = parts[1];
313 row = *(available_action_model->append (parent.children()));
317 row = *(available_action_model->append ((*r->second)->children()));
321 /* add this action */
324 row[available_action_columns.name] = *t;
327 row[available_action_columns.name] = *l;
331 row[available_action_columns.path] = (*p);
336 MackieControlProtocolGUI::build_function_key_editor ()
338 function_key_editor.append_column (_("Key"), function_key_columns.name);
341 CellRendererCombo* renderer;
343 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
344 col = manage (new TreeViewColumn (_("Plain"), *renderer));
345 col->add_attribute (renderer->property_text(), function_key_columns.plain);
346 function_key_editor.append_column (*col);
348 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
349 col = manage (new TreeViewColumn (_("Shift"), *renderer));
350 col->add_attribute (renderer->property_text(), function_key_columns.shift);
351 function_key_editor.append_column (*col);
353 renderer = make_action_renderer (available_action_model, function_key_columns.control);
354 col = manage (new TreeViewColumn (_("Control"), *renderer));
355 col->add_attribute (renderer->property_text(), function_key_columns.control);
356 function_key_editor.append_column (*col);
358 renderer = make_action_renderer (available_action_model, function_key_columns.option);
359 col = manage (new TreeViewColumn (_("Option"), *renderer));
360 col->add_attribute (renderer->property_text(), function_key_columns.option);
361 function_key_editor.append_column (*col);
363 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
364 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
365 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
366 function_key_editor.append_column (*col);
368 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
369 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
370 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
371 function_key_editor.append_column (*col);
373 function_key_model = ListStore::create (function_key_columns);
374 function_key_editor.set_model (function_key_model);
378 MackieControlProtocolGUI::refresh_function_key_editor ()
380 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
381 function_key_model->clear ();
383 /* now fill with data */
386 DeviceProfile dp (_cp.device_profile());
389 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
391 Mackie::Button::ID bid = (Mackie::Button::ID) n;
393 row = *(function_key_model->append());
394 if (di.global_buttons().find (bid) == di.global_buttons().end()) {
395 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
397 row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
399 row[function_key_columns.id] = bid;
401 Glib::RefPtr<Gtk::Action> act;
403 const string defstring = "\u2022";
405 action = dp.get_button_action (bid, 0);
406 if (action.empty()) {
407 row[function_key_columns.plain] = defstring;
409 if (action.find ('/') == string::npos) {
410 /* Probably a key alias */
411 row[function_key_columns.plain] = action;
414 act = ActionManager::get_action (action.c_str());
416 row[function_key_columns.plain] = act->get_label();
418 row[function_key_columns.plain] = defstring;
423 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
424 if (action.empty()) {
425 row[function_key_columns.control] = defstring;
427 if (action.find ('/') == string::npos) {
428 /* Probably a key alias */
429 row[function_key_columns.control] = action;
431 act = ActionManager::get_action (action.c_str());
433 row[function_key_columns.control] = act->get_label();
435 row[function_key_columns.control] = defstring;
440 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
441 if (action.empty()) {
442 row[function_key_columns.shift] = defstring;
444 if (action.find ('/') == string::npos) {
445 /* Probably a key alias */
446 row[function_key_columns.shift] = action;
448 act = ActionManager::get_action (action.c_str());
450 row[function_key_columns.shift] = act->get_label();
452 row[function_key_columns.shift] = defstring;
457 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
458 if (action.empty()) {
459 row[function_key_columns.option] = defstring;
461 if (action.find ('/') == string::npos) {
462 /* Probably a key alias */
463 row[function_key_columns.option] = action;
465 act = ActionManager::get_action (action.c_str());
467 row[function_key_columns.option] = act->get_label();
469 row[function_key_columns.option] = defstring;
474 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
475 if (action.empty()) {
476 row[function_key_columns.cmdalt] = defstring;
478 if (action.find ('/') == string::npos) {
479 /* Probably a key alias */
480 row[function_key_columns.cmdalt] = action;
482 act = ActionManager::get_action (action.c_str());
484 row[function_key_columns.cmdalt] = act->get_label();
486 row[function_key_columns.cmdalt] = defstring;
491 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
492 if (action.empty()) {
493 row[function_key_columns.shiftcontrol] = defstring;
495 act = ActionManager::get_action (action.c_str());
497 row[function_key_columns.shiftcontrol] = act->get_label();
499 row[function_key_columns.shiftcontrol] = defstring;
504 function_key_editor.set_model (function_key_model);
508 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
510 // Remove Binding is not in the action map but still valid
512 if ( text == "Remove Binding") {
515 Gtk::TreePath path(sPath);
516 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
520 std::map<std::string,std::string>::iterator i = action_map.find (text);
522 if (i == action_map.end()) {
527 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
530 /* update visible text, using string supplied by
531 available action model so that it matches and is found
535 Glib::ustring dot = "\u2022";
536 (*row).set_value (col.index(), dot);
538 (*row).set_value (col.index(), text);
541 /* update the current DeviceProfile, using the full
547 switch (col.index()) {
549 modifier = MackieControlProtocol::MODIFIER_SHIFT;
552 modifier = MackieControlProtocol::MODIFIER_CONTROL;
555 modifier = MackieControlProtocol::MODIFIER_OPTION;
558 modifier = MackieControlProtocol::MODIFIER_CMDALT;
561 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
568 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
570 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
574 std::cerr << "no such action\n";
580 MackieControlProtocolGUI::surface_combo_changed ()
582 _cp.not_session_load();
583 _cp.set_device (_surface_combo.get_active_text());
585 /* update ipMIDI field */
587 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
591 MackieControlProtocolGUI::profile_combo_changed ()
593 string profile = _profile_combo.get_active_text();
595 _cp.set_profile (profile);
597 refresh_function_key_editor ();
601 MackieControlProtocolGUI::ipmidi_spinner_changed ()
603 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));
607 MackieControlProtocolGUI::discover_clicked ()
609 /* this should help to get things started */
610 _cp.midi_connectivity_established ();
614 MackieControlProtocolGUI::recalibrate_faders ()
616 _cp.recalibrate_faders ();
620 MackieControlProtocolGUI::toggle_backlight ()
622 _cp.toggle_backlight ();
626 MackieControlProtocolGUI::touch_sensitive_change ()
628 int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
629 _cp.set_touch_sensitivity (sensitivity);