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 l->set_alignment (1.0, 0.5);
88 table->attach (*l, 0, 1, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
89 table->attach (_surface_combo, 1, 2, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 20);
91 vector<string> surfaces;
93 for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
94 surfaces.push_back (i->first);
96 Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
97 _surface_combo.set_active_text (p.device_info().name());
98 _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
100 RadioButtonGroup rb_group = absolute_touch_mode_button.get_group();
101 touch_move_mode_button.set_group (rb_group);
103 l = manage (new Gtk::Label (_("Button click")));
104 l->set_alignment (1.0, 0.5);
105 table->attach (*l, 0, 1, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
106 align = manage (new Alignment);
107 align->set (0.0, 0.5);
108 align->add (relay_click_button);
109 table->attach (*align, 1, 2, 1, 2, AttachOptions(FILL|EXPAND), AttachOptions (0));
110 l = manage (new Gtk::Label (_("Backlight")));
111 l->set_alignment (1.0, 0.5);
112 table->attach (*l, 0, 1, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
113 align = manage (new Alignment);
114 align->set (0.0, 0.5);
115 align->add (backlight_button);
116 table->attach (*align, 1, 2, 2, 3, AttachOptions(FILL|EXPAND), AttachOptions (0));
117 l = manage (new Gtk::Label (_("Send Fader Position Only When Touched")));
118 l->set_alignment (1.0, 0.5);
119 table->attach (*l, 0, 1, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
120 align = manage (new Alignment);
121 align->set (0.0, 0.5);
122 align->add (absolute_touch_mode_button);
123 table->attach (*align, 1, 2, 3, 4, AttachOptions(FILL|EXPAND), AttachOptions (0));
124 l = manage (new Gtk::Label (_("Send Fader Position When Moved")));
125 l->set_alignment (1.0, 0.5);
126 table->attach (*l, 0, 1, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
127 align = manage (new Alignment);
128 align->set (0.0, 0.5);
129 align->add (touch_move_mode_button);
130 table->attach (*align, 1, 2, 4, 5, AttachOptions(FILL|EXPAND), AttachOptions (0));
131 l = manage (new Gtk::Label (_("Fader Touch Sense Sensitivity")));
132 l->set_alignment (1.0, 0.5);
133 table->attach (*l, 0, 1, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
134 touch_sensitivity_scale.property_digits() = 0;
135 touch_sensitivity_scale.property_draw_value() = false;
136 table->attach (touch_sensitivity_scale, 1, 2, 5, 6, AttachOptions(FILL|EXPAND), AttachOptions (0));
137 table->attach (recalibrate_fader_button, 1, 2, 6, 7, AttachOptions(FILL|EXPAND), AttachOptions (0));
139 l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
140 l->set_alignment (1.0, 0.5);
141 table->attach (*l, 0, 1, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
142 table->attach (ipmidi_base_port_spinner, 1, 2, 7, 8, AttachOptions(FILL|EXPAND), AttachOptions (0));
144 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
145 ipmidi_base_port_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::ipmidi_spinner_changed));
147 vector<string> profiles;
149 profiles.push_back ("default");
151 for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
152 profiles.push_back (i->first);
154 Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
155 _profile_combo.set_active_text (p.device_profile().name());
156 _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
158 append_page (*table, _("Device Setup"));
161 /* function key editor */
163 VBox* fkey_packer = manage (new VBox);
164 HBox* profile_packer = manage (new HBox);
166 l = manage (new Gtk::Label (_("Profile/Settings:")));
167 profile_packer->pack_start (*l, false, false);
168 profile_packer->pack_start (_profile_combo, true, true);
169 profile_packer->set_spacing (12);
170 profile_packer->set_border_width (12);
172 fkey_packer->pack_start (*profile_packer, false, false);
173 fkey_packer->pack_start (function_key_scroller, true, true);
174 fkey_packer->set_spacing (12);
175 function_key_scroller.set_size_request (700,700);
176 function_key_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
177 function_key_scroller.add (function_key_editor);
178 append_page (*fkey_packer, _("Function Keys"));
180 build_available_action_menu ();
181 build_function_key_editor ();
182 refresh_function_key_editor ();
183 fkey_packer->show_all();
187 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
189 CellRendererCombo* renderer = manage (new CellRendererCombo);
190 renderer->property_model() = model;
191 renderer->property_editable() = true;
192 renderer->property_text_column() = 0;
193 renderer->property_has_entry() = false;
194 renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
200 MackieControlProtocolGUI::build_available_action_menu ()
202 /* build a model of all available actions (needs to be tree structured
206 available_action_model = TreeStore::create (available_action_columns);
208 vector<string> paths;
209 vector<string> labels;
210 vector<string> tooltips;
212 vector<AccelKey> bindings;
213 typedef std::map<string,TreeIter> NodeMap;
217 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
219 vector<string>::iterator k;
220 vector<string>::iterator p;
221 vector<string>::iterator t;
222 vector<string>::iterator l;
224 available_action_model->clear ();
226 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
229 vector<string> parts;
233 split (*p, parts, '/');
239 //kinda kludgy way to avoid displaying menu items as mappable
240 if ( parts[1] == _("Main_menu") )
242 if ( parts[1] == _("JACK") )
244 if ( parts[1] == _("redirectmenu") )
246 if ( parts[1] == _("Editor_menus") )
248 if ( parts[1] == _("RegionList") )
250 if ( parts[1] == _("ProcessorMenu") )
253 if ((r = nodes.find (parts[1])) == nodes.end()) {
255 /* top level is missing */
258 TreeModel::Row parent;
259 rowp = available_action_model->append();
260 nodes[parts[1]] = rowp;
262 parent[available_action_columns.name] = parts[1];
264 row = *(available_action_model->append (parent.children()));
268 row = *(available_action_model->append ((*r->second)->children()));
272 /* add this action */
275 row[available_action_columns.name] = *t;
278 row[available_action_columns.name] = *l;
282 row[available_action_columns.path] = (*p);
287 MackieControlProtocolGUI::build_function_key_editor ()
289 function_key_editor.append_column (_("Key"), function_key_columns.name);
292 CellRendererCombo* renderer;
294 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
295 col = manage (new TreeViewColumn (_("Plain"), *renderer));
296 col->add_attribute (renderer->property_text(), function_key_columns.plain);
297 function_key_editor.append_column (*col);
299 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
300 col = manage (new TreeViewColumn (_("Shift"), *renderer));
301 col->add_attribute (renderer->property_text(), function_key_columns.shift);
302 function_key_editor.append_column (*col);
304 renderer = make_action_renderer (available_action_model, function_key_columns.control);
305 col = manage (new TreeViewColumn (_("Control"), *renderer));
306 col->add_attribute (renderer->property_text(), function_key_columns.control);
307 function_key_editor.append_column (*col);
309 renderer = make_action_renderer (available_action_model, function_key_columns.option);
310 col = manage (new TreeViewColumn (_("Option"), *renderer));
311 col->add_attribute (renderer->property_text(), function_key_columns.option);
312 function_key_editor.append_column (*col);
314 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
315 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
316 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
317 function_key_editor.append_column (*col);
319 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
320 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
321 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
322 function_key_editor.append_column (*col);
324 function_key_model = ListStore::create (function_key_columns);
325 function_key_editor.set_model (function_key_model);
329 MackieControlProtocolGUI::refresh_function_key_editor ()
331 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
332 function_key_model->clear ();
334 /* now fill with data */
337 DeviceProfile dp (_cp.device_profile());
339 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
341 Mackie::Button::ID bid = (Mackie::Button::ID) n;
343 row = *(function_key_model->append());
344 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
345 row[function_key_columns.id] = bid;
347 Glib::RefPtr<Gtk::Action> act;
349 const string defstring = "\u2022";
351 action = dp.get_button_action (bid, 0);
352 if (action.empty()) {
353 row[function_key_columns.plain] = defstring;
355 act = ActionManager::get_action (action.c_str());
357 row[function_key_columns.plain] = act->get_label();
359 row[function_key_columns.plain] = defstring;
363 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
364 if (action.empty()) {
365 row[function_key_columns.control] = defstring;
367 act = ActionManager::get_action (action.c_str());
369 row[function_key_columns.control] = act->get_label();
371 row[function_key_columns.control] = defstring;
375 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
376 if (action.empty()) {
377 row[function_key_columns.shift] = defstring;
379 act = ActionManager::get_action (action.c_str());
381 row[function_key_columns.shift] = act->get_label();
383 row[function_key_columns.shift] = defstring;
387 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
388 if (action.empty()) {
389 row[function_key_columns.option] = defstring;
391 act = ActionManager::get_action (action.c_str());
393 row[function_key_columns.option] = act->get_label();
395 row[function_key_columns.option] = defstring;
399 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
400 if (action.empty()) {
401 row[function_key_columns.cmdalt] = defstring;
403 act = ActionManager::get_action (action.c_str());
405 row[function_key_columns.cmdalt] = act->get_label();
407 row[function_key_columns.cmdalt] = defstring;
411 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
412 if (action.empty()) {
413 row[function_key_columns.shiftcontrol] = defstring;
415 act = ActionManager::get_action (action.c_str());
417 row[function_key_columns.shiftcontrol] = act->get_label();
419 row[function_key_columns.shiftcontrol] = defstring;
424 function_key_editor.set_model (function_key_model);
428 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
430 Gtk::TreePath path(sPath);
431 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
435 std::map<std::string,std::string>::iterator i = action_map.find (text);
437 if (i == action_map.end()) {
441 cerr << "Changed to " << i->first << " aka " << i->second << endl;
443 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
446 /* update visible text, using string supplied by
447 available action model so that it matches and is found
450 (*row).set_value (col.index(), text);
452 /* update the current DeviceProfile, using the full
458 switch (col.index()) {
460 modifier = MackieControlProtocol::MODIFIER_SHIFT;
463 modifier = MackieControlProtocol::MODIFIER_CONTROL;
466 modifier = MackieControlProtocol::MODIFIER_OPTION;
469 modifier = MackieControlProtocol::MODIFIER_CMDALT;
472 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
478 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
480 std::cerr << "no such action\n";
486 MackieControlProtocolGUI::surface_combo_changed ()
488 _cp.set_device (_surface_combo.get_active_text());
490 /* update ipMIDI field */
492 cerr << "New device called " << _cp.device_info().name() << " with ipMIDI ? " << _cp.device_info().uses_ipmidi() << endl;
494 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
498 MackieControlProtocolGUI::profile_combo_changed ()
500 string profile = _profile_combo.get_active_text();
502 _cp.set_profile (profile);
504 refresh_function_key_editor ();
508 MackieControlProtocolGUI::ipmidi_spinner_changed ()
510 cerr << "Set IP MIDI base to " << ipmidi_base_port_spinner.get_value() << endl;
511 _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));