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");
259 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
262 vector<string> parts;
266 split (*p, parts, '/');
272 //kinda kludgy way to avoid displaying menu items as mappable
273 if ( parts[1] == _("Main_menu") )
275 if ( parts[1] == _("JACK") )
277 if ( parts[1] == _("redirectmenu") )
279 if ( parts[1] == _("Editor_menus") )
281 if ( parts[1] == _("RegionList") )
283 if ( parts[1] == _("ProcessorMenu") )
286 if ((r = nodes.find (parts[1])) == nodes.end()) {
288 /* top level is missing */
291 TreeModel::Row parent;
292 rowp = available_action_model->append();
293 nodes[parts[1]] = rowp;
295 parent[available_action_columns.name] = parts[1];
297 row = *(available_action_model->append (parent.children()));
301 row = *(available_action_model->append ((*r->second)->children()));
305 /* add this action */
308 row[available_action_columns.name] = *t;
311 row[available_action_columns.name] = *l;
315 row[available_action_columns.path] = (*p);
320 MackieControlProtocolGUI::build_function_key_editor ()
322 function_key_editor.append_column (_("Key"), function_key_columns.name);
325 CellRendererCombo* renderer;
327 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
328 col = manage (new TreeViewColumn (_("Plain"), *renderer));
329 col->add_attribute (renderer->property_text(), function_key_columns.plain);
330 function_key_editor.append_column (*col);
332 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
333 col = manage (new TreeViewColumn (_("Shift"), *renderer));
334 col->add_attribute (renderer->property_text(), function_key_columns.shift);
335 function_key_editor.append_column (*col);
337 renderer = make_action_renderer (available_action_model, function_key_columns.control);
338 col = manage (new TreeViewColumn (_("Control"), *renderer));
339 col->add_attribute (renderer->property_text(), function_key_columns.control);
340 function_key_editor.append_column (*col);
342 renderer = make_action_renderer (available_action_model, function_key_columns.option);
343 col = manage (new TreeViewColumn (_("Option"), *renderer));
344 col->add_attribute (renderer->property_text(), function_key_columns.option);
345 function_key_editor.append_column (*col);
347 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
348 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
349 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
350 function_key_editor.append_column (*col);
352 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
353 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
354 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
355 function_key_editor.append_column (*col);
357 function_key_model = ListStore::create (function_key_columns);
358 function_key_editor.set_model (function_key_model);
362 MackieControlProtocolGUI::refresh_function_key_editor ()
364 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
365 function_key_model->clear ();
367 /* now fill with data */
370 DeviceProfile dp (_cp.device_profile());
373 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
375 Mackie::Button::ID bid = (Mackie::Button::ID) n;
377 row = *(function_key_model->append());
378 if (di.global_buttons().find (bid) == di.global_buttons().end()) {
379 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
381 row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
383 row[function_key_columns.id] = bid;
385 Glib::RefPtr<Gtk::Action> act;
387 const string defstring = "\u2022";
389 action = dp.get_button_action (bid, 0);
390 if (action.empty()) {
391 row[function_key_columns.plain] = defstring;
393 act = ActionManager::get_action (action.c_str());
395 row[function_key_columns.plain] = act->get_label();
397 row[function_key_columns.plain] = defstring;
401 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
402 if (action.empty()) {
403 row[function_key_columns.control] = defstring;
405 act = ActionManager::get_action (action.c_str());
407 row[function_key_columns.control] = act->get_label();
409 row[function_key_columns.control] = defstring;
413 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
414 if (action.empty()) {
415 row[function_key_columns.shift] = defstring;
417 act = ActionManager::get_action (action.c_str());
419 row[function_key_columns.shift] = act->get_label();
421 row[function_key_columns.shift] = defstring;
425 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
426 if (action.empty()) {
427 row[function_key_columns.option] = defstring;
429 act = ActionManager::get_action (action.c_str());
431 row[function_key_columns.option] = act->get_label();
433 row[function_key_columns.option] = defstring;
437 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
438 if (action.empty()) {
439 row[function_key_columns.cmdalt] = defstring;
441 act = ActionManager::get_action (action.c_str());
443 row[function_key_columns.cmdalt] = act->get_label();
445 row[function_key_columns.cmdalt] = defstring;
449 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
450 if (action.empty()) {
451 row[function_key_columns.shiftcontrol] = defstring;
453 act = ActionManager::get_action (action.c_str());
455 row[function_key_columns.shiftcontrol] = act->get_label();
457 row[function_key_columns.shiftcontrol] = defstring;
462 function_key_editor.set_model (function_key_model);
466 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
468 // Remove Binding is not in the action map but still valid
470 if ( text == "Remove Binding") {
473 Gtk::TreePath path(sPath);
474 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
478 std::map<std::string,std::string>::iterator i = action_map.find (text);
480 if (i == action_map.end()) {
485 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
488 /* update visible text, using string supplied by
489 available action model so that it matches and is found
493 Glib::ustring dot = "\u2022";
494 (*row).set_value (col.index(), dot);
496 (*row).set_value (col.index(), text);
499 /* update the current DeviceProfile, using the full
505 switch (col.index()) {
507 modifier = MackieControlProtocol::MODIFIER_SHIFT;
510 modifier = MackieControlProtocol::MODIFIER_CONTROL;
513 modifier = MackieControlProtocol::MODIFIER_OPTION;
516 modifier = MackieControlProtocol::MODIFIER_CMDALT;
519 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
526 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
528 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
532 std::cerr << "no such action\n";
538 MackieControlProtocolGUI::surface_combo_changed ()
540 _cp.not_session_load();
541 _cp.set_device (_surface_combo.get_active_text());
543 /* update ipMIDI field */
545 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
549 MackieControlProtocolGUI::profile_combo_changed ()
551 string profile = _profile_combo.get_active_text();
553 _cp.set_profile (profile);
555 refresh_function_key_editor ();
559 MackieControlProtocolGUI::ipmidi_spinner_changed ()
561 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));
565 MackieControlProtocolGUI::discover_clicked ()
567 /* this should help to get things started */
568 _cp.midi_connectivity_established ();
572 MackieControlProtocolGUI::recalibrate_faders ()
574 _cp.recalibrate_faders ();
578 MackieControlProtocolGUI::toggle_backlight ()
580 _cp.toggle_backlight ();
584 MackieControlProtocolGUI::touch_sensitive_change ()
586 int sensitivity = (int) touch_sensitivity_adjustment.get_value ();
587 _cp.set_touch_sensitivity (sensitivity);