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/audioengine.h"
37 #include "ardour/rc_configuration.h"
39 #include "mackie_control_protocol.h"
40 #include "device_info.h"
47 using namespace ArdourSurface;
48 using namespace Mackie;
51 MackieControlProtocol::get_gui () const
54 const_cast<MackieControlProtocol*>(this)->build_gui ();
56 static_cast<Gtk::Notebook*>(_gui)->show_all();
61 MackieControlProtocol::tear_down_gui ()
64 Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
70 delete (MackieControlProtocolGUI*) _gui;
75 MackieControlProtocol::build_gui ()
77 _gui = (void *) new MackieControlProtocolGUI (*this);
80 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& 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"))
90 Gtk::Alignment* align;
93 set_border_width (12);
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);
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);
106 vector<string> surfaces;
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);
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));
115 vector<string> midi_ports;
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);
121 string receive_string;
123 if (_cp.device_info().extenders() > 0) {
124 send_string = _("Main surface sends via:");
125 receive_string = _("Main surface receives via:");
127 send_string = _("Surface sends via:");
128 receive_string = _("Surface receives via:");
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);
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);
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);
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));
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));
156 /* leave an extra blank row */
159 RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
160 touch_move_mode_button.set_group (rb_group);
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));
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);
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));
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));
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));
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));
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));
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));
218 vector<string> profiles;
220 profiles.push_back ("default");
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);
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));
229 append_page (*table, _("Device Setup"));
232 /* function key editor */
234 VBox* fkey_packer = manage (new VBox);
235 HBox* profile_packer = manage (new HBox);
236 HBox* observation_packer = manage (new HBox);
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);
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);
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"));
255 build_available_action_menu ();
256 build_function_key_editor ();
257 refresh_function_key_editor ();
258 fkey_packer->show_all();
262 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
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));
275 MackieControlProtocolGUI::build_available_action_menu ()
277 /* build a model of all available actions (needs to be tree structured
281 available_action_model = TreeStore::create (available_action_columns);
283 vector<string> paths;
284 vector<string> labels;
285 vector<string> tooltips;
287 vector<AccelKey> bindings;
288 typedef std::map<string,TreeIter> NodeMap;
292 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
294 vector<string>::iterator k;
295 vector<string>::iterator p;
296 vector<string>::iterator t;
297 vector<string>::iterator l;
299 available_action_model->clear ();
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
305 TreeModel::Row parent;
306 rowp = available_action_model->append();
308 parent[available_action_columns.name] = _("Remove Binding");
312 rowp = available_action_model->append();
314 parent[available_action_columns.name] = _("Shift");
315 rowp = available_action_model->append();
317 parent[available_action_columns.name] = _("Control");
318 rowp = available_action_model->append();
320 parent[available_action_columns.name] = _("Option");
321 rowp = available_action_model->append();
323 parent[available_action_columns.name] = _("CmdAlt");
326 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
329 vector<string> parts;
333 split (*p, parts, '/');
339 //kinda kludgy way to avoid displaying menu items as mappable
340 if ( parts[1] == _("Main_menu") )
342 if ( parts[1] == _("JACK") )
344 if ( parts[1] == _("redirectmenu") )
346 if ( parts[1] == _("Editor_menus") )
348 if ( parts[1] == _("RegionList") )
350 if ( parts[1] == _("ProcessorMenu") )
353 if ((r = nodes.find (parts[1])) == nodes.end()) {
355 /* top level is missing */
358 TreeModel::Row parent;
359 rowp = available_action_model->append();
360 nodes[parts[1]] = rowp;
362 parent[available_action_columns.name] = parts[1];
364 row = *(available_action_model->append (parent.children()));
368 row = *(available_action_model->append ((*r->second)->children()));
372 /* add this action */
375 row[available_action_columns.name] = *t;
378 row[available_action_columns.name] = *l;
382 row[available_action_columns.path] = (*p);
387 MackieControlProtocolGUI::build_function_key_editor ()
389 function_key_editor.append_column (_("Key"), function_key_columns.name);
392 CellRendererCombo* renderer;
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);
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);
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);
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);
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);
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);
424 function_key_model = ListStore::create (function_key_columns);
425 function_key_editor.set_model (function_key_model);
429 MackieControlProtocolGUI::refresh_function_key_editor ()
431 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
432 function_key_model->clear ();
434 /* now fill with data */
437 DeviceProfile dp (_cp.device_profile());
440 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
442 Mackie::Button::ID bid = (Mackie::Button::ID) n;
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);
448 row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
450 row[function_key_columns.id] = bid;
452 Glib::RefPtr<Gtk::Action> act;
454 const string defstring = "\u2022";
456 action = dp.get_button_action (bid, 0);
457 if (action.empty()) {
458 row[function_key_columns.plain] = defstring;
460 if (action.find ('/') == string::npos) {
461 /* Probably a key alias */
462 row[function_key_columns.plain] = action;
465 act = ActionManager::get_action (action.c_str());
467 row[function_key_columns.plain] = act->get_label();
469 row[function_key_columns.plain] = defstring;
474 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
475 if (action.empty()) {
476 row[function_key_columns.control] = defstring;
478 if (action.find ('/') == string::npos) {
479 /* Probably a key alias */
480 row[function_key_columns.control] = action;
482 act = ActionManager::get_action (action.c_str());
484 row[function_key_columns.control] = act->get_label();
486 row[function_key_columns.control] = defstring;
491 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
492 if (action.empty()) {
493 row[function_key_columns.shift] = defstring;
495 if (action.find ('/') == string::npos) {
496 /* Probably a key alias */
497 row[function_key_columns.shift] = action;
499 act = ActionManager::get_action (action.c_str());
501 row[function_key_columns.shift] = act->get_label();
503 row[function_key_columns.shift] = defstring;
508 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
509 if (action.empty()) {
510 row[function_key_columns.option] = defstring;
512 if (action.find ('/') == string::npos) {
513 /* Probably a key alias */
514 row[function_key_columns.option] = action;
516 act = ActionManager::get_action (action.c_str());
518 row[function_key_columns.option] = act->get_label();
520 row[function_key_columns.option] = defstring;
525 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
526 if (action.empty()) {
527 row[function_key_columns.cmdalt] = defstring;
529 if (action.find ('/') == string::npos) {
530 /* Probably a key alias */
531 row[function_key_columns.cmdalt] = action;
533 act = ActionManager::get_action (action.c_str());
535 row[function_key_columns.cmdalt] = act->get_label();
537 row[function_key_columns.cmdalt] = defstring;
542 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
543 if (action.empty()) {
544 row[function_key_columns.shiftcontrol] = defstring;
546 act = ActionManager::get_action (action.c_str());
548 row[function_key_columns.shiftcontrol] = act->get_label();
550 row[function_key_columns.shiftcontrol] = defstring;
555 function_key_editor.set_model (function_key_model);
559 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
561 // Remove Binding is not in the action map but still valid
563 if ( text == "Remove Binding") {
566 Gtk::TreePath path(sPath);
567 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
571 std::map<std::string,std::string>::iterator i = action_map.find (text);
573 if (i == action_map.end()) {
578 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
581 /* update visible text, using string supplied by
582 available action model so that it matches and is found
586 Glib::ustring dot = "\u2022";
587 (*row).set_value (col.index(), dot);
589 (*row).set_value (col.index(), text);
592 /* update the current DeviceProfile, using the full
598 switch (col.index()) {
600 modifier = MackieControlProtocol::MODIFIER_SHIFT;
603 modifier = MackieControlProtocol::MODIFIER_CONTROL;
606 modifier = MackieControlProtocol::MODIFIER_OPTION;
609 modifier = MackieControlProtocol::MODIFIER_CMDALT;
612 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
619 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
621 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
625 std::cerr << "no such action\n";
631 MackieControlProtocolGUI::surface_combo_changed ()
633 _cp.not_session_load();
634 _cp.set_device (_surface_combo.get_active_text());
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);
641 ipmidi_base_port_spinner.set_sensitive (false);
642 _input_port_combo.set_sensitive (true);
643 _output_port_combo.set_sensitive (true);
648 MackieControlProtocolGUI::profile_combo_changed ()
650 string profile = _profile_combo.get_active_text();
652 _cp.set_profile (profile);
654 refresh_function_key_editor ();
658 MackieControlProtocolGUI::ipmidi_spinner_changed ()
660 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));
664 MackieControlProtocolGUI::discover_clicked ()
666 /* this should help to get things started */
667 _cp.midi_connectivity_established ();
671 MackieControlProtocolGUI::recalibrate_faders ()
673 _cp.recalibrate_faders ();
677 MackieControlProtocolGUI::toggle_backlight ()
679 _cp.toggle_backlight ();
683 MackieControlProtocolGUI::touch_sensitive_change ()
685 int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
686 _cp.set_touch_sensitivity (sensitivity);