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"
45 using namespace Mackie;
49 MackieControlProtocol::get_gui () const
52 const_cast<MackieControlProtocol*>(this)->build_gui ();
59 MackieControlProtocol::tear_down_gui ()
61 delete (MackieControlProtocolGUI*) _gui;
65 MackieControlProtocol::build_gui ()
67 _gui = (void *) new MackieControlProtocolGUI (*this);
70 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
72 , touch_sensitivity_adjustment (0, 0, 9, 1, 4)
73 , touch_sensitivity_scale (touch_sensitivity_adjustment)
74 , recalibrate_fader_button (_("Recalibrate Faders"))
75 , ipmidi_base_port_adjustment (_cp.ipmidi_base(), 0, 32767, 1, 1000)
76 , ipmidi_base_port_spinner (ipmidi_base_port_adjustment)
79 Gtk::Alignment* align;
81 set_border_width (12);
83 Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 8));
84 table->set_row_spacings (4);
85 table->set_col_spacings (6);
86 l = manage (new Gtk::Label (_("Device Type:")));
87 table->attach (*l, 0, 1, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
88 table->attach (_surface_combo, 1, 2, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 20);
90 vector<string> surfaces;
92 for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
93 surfaces.push_back (i->first);
95 Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
96 _surface_combo.set_active_text (p.device_info().name());
97 _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
99 RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
100 touch_move_mode_button.set_group (rb_group);
102 l = manage (new Gtk::Label (_("Button click")));
103 l->set_alignment (1.0, 0.5);
104 table->attach (*l, 0, 1, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
105 align = manage (new Alignment);
106 align->set (0.0, 0.5);
107 align->add (relay_click_button);
108 table->attach (*align, 1, 2, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
109 l = manage (new Gtk::Label (_("Backlight")));
110 l->set_alignment (1.0, 0.5);
111 table->attach (*l, 0, 1, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
112 align = manage (new Alignment);
113 align->set (0.0, 0.5);
114 align->add (backlight_button);
115 table->attach (*align, 1, 2, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
116 l = manage (new Gtk::Label (_("Send Fader Position Only When Touched")));
117 l->set_alignment (1.0, 0.5);
118 table->attach (*l, 0, 1, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
119 align = manage (new Alignment);
120 align->set (0.0, 0.5);
121 align->add (absolute_touch_mode_button);
122 table->attach (*align, 1, 2, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
123 l = manage (new Gtk::Label (_("Send Fader Position When Moved")));
124 l->set_alignment (1.0, 0.5);
125 table->attach (*l, 0, 1, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
126 align = manage (new Alignment);
127 align->set (0.0, 0.5);
128 align->add (touch_move_mode_button);
129 table->attach (*align, 1, 2, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
130 l = manage (new Gtk::Label (_("Fader Touch Sense Sensitivity")));
131 l->set_alignment (1.0, 0.5);
132 table->attach (*l, 0, 1, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
133 touch_sensitivity_scale.property_digits() = 0;
134 touch_sensitivity_scale.property_draw_value() = false;
135 table->attach (touch_sensitivity_scale, 1, 2, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
136 table->attach (recalibrate_fader_button, 1, 2, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
138 l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
139 l->set_alignment (1.0, 0.5);
140 table->attach (*l, 0, 1, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
141 table->attach (ipmidi_base_port_spinner, 1, 2, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
143 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
144 ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
146 vector<string> profiles;
148 profiles.push_back ("default");
150 for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
151 profiles.push_back (i->first);
153 Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
154 _profile_combo.set_active_text (p.device_profile().name());
155 _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
157 append_page (*table, _("Device Setup"));
160 /* function key editor */
162 VBox* fkey_packer = manage (new VBox);
163 HBox* profile_packer = manage (new HBox);
165 l = manage (new Gtk::Label (_("Profile/Settings:")));
166 profile_packer->pack_start (*l, false, false);
167 profile_packer->pack_start (_profile_combo, true, true);
168 profile_packer->set_spacing (12);
169 profile_packer->set_border_width (12);
171 fkey_packer->pack_start (*profile_packer, false, false);
172 fkey_packer->pack_start (function_key_scroller, true, true);
173 fkey_packer->set_spacing (12);
174 function_key_scroller.set_size_request (700,700);
175 function_key_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
176 function_key_scroller.add (function_key_editor);
177 append_page (*fkey_packer, _("Function Keys"));
179 build_available_action_menu ();
180 build_function_key_editor ();
181 refresh_function_key_editor ();
182 fkey_packer->show_all();
186 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
188 CellRendererCombo* renderer = manage (new CellRendererCombo);
189 renderer->property_model() = model;
190 renderer->property_editable() = true;
191 renderer->property_text_column() = 0;
192 renderer->property_has_entry() = false;
193 renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
199 MackieControlProtocolGUI::build_available_action_menu ()
201 /* build a model of all available actions (needs to be tree structured
205 available_action_model = TreeStore::create (available_action_columns);
207 vector<string> paths;
208 vector<string> labels;
209 vector<string> tooltips;
211 vector<AccelKey> bindings;
212 typedef std::map<string,TreeIter> NodeMap;
216 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
218 vector<string>::iterator k;
219 vector<string>::iterator p;
220 vector<string>::iterator t;
221 vector<string>::iterator l;
223 available_action_model->clear ();
225 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
228 vector<string> parts;
232 split (*p, parts, '/');
238 //kinda kludgy way to avoid displaying menu items as mappable
239 if ( parts[1] == _("Main_menu") )
241 if ( parts[1] == _("JACK") )
243 if ( parts[1] == _("redirectmenu") )
245 if ( parts[1] == _("Editor_menus") )
247 if ( parts[1] == _("RegionList") )
249 if ( parts[1] == _("ProcessorMenu") )
252 if ((r = nodes.find (parts[1])) == nodes.end()) {
254 /* top level is missing */
257 TreeModel::Row parent;
258 rowp = available_action_model->append();
259 nodes[parts[1]] = rowp;
261 parent[available_action_columns.name] = parts[1];
263 row = *(available_action_model->append (parent.children()));
267 row = *(available_action_model->append ((*r->second)->children()));
271 /* add this action */
274 row[available_action_columns.name] = *t;
277 row[available_action_columns.name] = *l;
281 row[available_action_columns.path] = (*p);
286 MackieControlProtocolGUI::build_function_key_editor ()
288 function_key_editor.append_column (_("Key"), function_key_columns.name);
291 CellRendererCombo* renderer;
293 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
294 col = manage (new TreeViewColumn (_("Plain"), *renderer));
295 col->add_attribute (renderer->property_text(), function_key_columns.plain);
296 function_key_editor.append_column (*col);
298 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
299 col = manage (new TreeViewColumn (_("Shift"), *renderer));
300 col->add_attribute (renderer->property_text(), function_key_columns.shift);
301 function_key_editor.append_column (*col);
303 renderer = make_action_renderer (available_action_model, function_key_columns.control);
304 col = manage (new TreeViewColumn (_("Control"), *renderer));
305 col->add_attribute (renderer->property_text(), function_key_columns.control);
306 function_key_editor.append_column (*col);
308 renderer = make_action_renderer (available_action_model, function_key_columns.option);
309 col = manage (new TreeViewColumn (_("Option"), *renderer));
310 col->add_attribute (renderer->property_text(), function_key_columns.option);
311 function_key_editor.append_column (*col);
313 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
314 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
315 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
316 function_key_editor.append_column (*col);
318 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
319 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
320 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
321 function_key_editor.append_column (*col);
323 function_key_model = ListStore::create (function_key_columns);
324 function_key_editor.set_model (function_key_model);
328 MackieControlProtocolGUI::refresh_function_key_editor ()
330 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
331 function_key_model->clear ();
333 /* now fill with data */
336 DeviceProfile dp (_cp.device_profile());
338 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
340 Mackie::Button::ID bid = (Mackie::Button::ID) n;
342 row = *(function_key_model->append());
343 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
344 row[function_key_columns.id] = bid;
346 Glib::RefPtr<Gtk::Action> act;
348 const string defstring = "\u2022";
350 action = dp.get_button_action (bid, 0);
351 if (action.empty()) {
352 row[function_key_columns.plain] = defstring;
354 act = ActionManager::get_action (action.c_str());
356 row[function_key_columns.plain] = act->get_label();
358 row[function_key_columns.plain] = defstring;
362 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
363 if (action.empty()) {
364 row[function_key_columns.control] = defstring;
366 act = ActionManager::get_action (action.c_str());
368 row[function_key_columns.control] = act->get_label();
370 row[function_key_columns.control] = defstring;
374 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
375 if (action.empty()) {
376 row[function_key_columns.shift] = defstring;
378 act = ActionManager::get_action (action.c_str());
380 row[function_key_columns.shift] = act->get_label();
382 row[function_key_columns.shift] = defstring;
386 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
387 if (action.empty()) {
388 row[function_key_columns.option] = defstring;
390 act = ActionManager::get_action (action.c_str());
392 row[function_key_columns.option] = act->get_label();
394 row[function_key_columns.option] = defstring;
398 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
399 if (action.empty()) {
400 row[function_key_columns.cmdalt] = defstring;
402 act = ActionManager::get_action (action.c_str());
404 row[function_key_columns.cmdalt] = act->get_label();
406 row[function_key_columns.cmdalt] = defstring;
410 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
411 if (action.empty()) {
412 row[function_key_columns.shiftcontrol] = defstring;
414 act = ActionManager::get_action (action.c_str());
416 row[function_key_columns.shiftcontrol] = act->get_label();
418 row[function_key_columns.shiftcontrol] = defstring;
423 function_key_editor.set_model (function_key_model);
427 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
429 Gtk::TreePath path(sPath);
430 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
434 std::map<std::string,std::string>::iterator i = action_map.find (text);
436 if (i == action_map.end()) {
440 cerr << "Changed to " << i->first << " aka " << i->second << endl;
442 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
445 /* update visible text, using string supplied by
446 available action model so that it matches and is found
449 (*row).set_value (col.index(), text);
451 /* update the current DeviceProfile, using the full
457 switch (col.index()) {
459 modifier = MackieControlProtocol::MODIFIER_SHIFT;
462 modifier = MackieControlProtocol::MODIFIER_CONTROL;
465 modifier = MackieControlProtocol::MODIFIER_OPTION;
468 modifier = MackieControlProtocol::MODIFIER_CMDALT;
471 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
477 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
479 std::cerr << "no such action\n";
485 MackieControlProtocolGUI::surface_combo_changed ()
487 _cp.set_device (_surface_combo.get_active_text());
489 /* update ipMIDI field */
491 cerr << "New device called " << _cp.device_info().name() << " with ipMIDI ? " << _cp.device_info().uses_ipmidi() << endl;
493 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
497 MackieControlProtocolGUI::profile_combo_changed ()
499 string profile = _profile_combo.get_active_text();
501 _cp.set_profile (profile);
503 refresh_function_key_editor ();
507 MackieControlProtocolGUI::ipmidi_spinner_changed ()
509 cerr << "Set IP MIDI base to " << ipmidi_base_port_spinner.get_value() << endl;
510 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));