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 (21928, 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());
145 vector<string> profiles;
147 profiles.push_back ("default");
149 for (std::map<std::string,DeviceProfile>::iterator i = DeviceProfile::device_profiles.begin(); i != DeviceProfile::device_profiles.end(); ++i) {
150 profiles.push_back (i->first);
152 Gtkmm2ext::set_popdown_strings (_profile_combo, profiles);
153 _profile_combo.set_active_text (p.device_profile().name());
154 _profile_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::profile_combo_changed));
156 append_page (*table, _("Device Setup"));
159 /* function key editor */
161 VBox* fkey_packer = manage (new VBox);
162 HBox* profile_packer = manage (new HBox);
164 l = manage (new Gtk::Label (_("Profile/Settings:")));
165 profile_packer->pack_start (*l, false, false);
166 profile_packer->pack_start (_profile_combo, true, true);
167 profile_packer->set_spacing (12);
168 profile_packer->set_border_width (12);
170 fkey_packer->pack_start (*profile_packer, false, false);
171 fkey_packer->pack_start (function_key_scroller, true, true);
172 fkey_packer->set_spacing (12);
173 function_key_scroller.set_size_request (700,700);
174 function_key_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
175 function_key_scroller.add (function_key_editor);
176 append_page (*fkey_packer, _("Function Keys"));
178 build_available_action_menu ();
179 build_function_key_editor ();
180 refresh_function_key_editor ();
181 fkey_packer->show_all();
185 MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
187 CellRendererCombo* renderer = manage (new CellRendererCombo);
188 renderer->property_model() = model;
189 renderer->property_editable() = true;
190 renderer->property_text_column() = 0;
191 renderer->property_has_entry() = false;
192 renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
198 MackieControlProtocolGUI::build_available_action_menu ()
200 /* build a model of all available actions (needs to be tree structured
204 available_action_model = TreeStore::create (available_action_columns);
206 vector<string> paths;
207 vector<string> labels;
208 vector<string> tooltips;
210 vector<AccelKey> bindings;
211 typedef std::map<string,TreeIter> NodeMap;
215 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
217 vector<string>::iterator k;
218 vector<string>::iterator p;
219 vector<string>::iterator t;
220 vector<string>::iterator l;
222 available_action_model->clear ();
224 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
227 vector<string> parts;
231 split (*p, parts, '/');
237 //kinda kludgy way to avoid displaying menu items as mappable
238 if ( parts[1] == _("Main_menu") )
240 if ( parts[1] == _("JACK") )
242 if ( parts[1] == _("redirectmenu") )
244 if ( parts[1] == _("Editor_menus") )
246 if ( parts[1] == _("RegionList") )
248 if ( parts[1] == _("ProcessorMenu") )
251 if ((r = nodes.find (parts[1])) == nodes.end()) {
253 /* top level is missing */
256 TreeModel::Row parent;
257 rowp = available_action_model->append();
258 nodes[parts[1]] = rowp;
260 parent[available_action_columns.name] = parts[1];
262 row = *(available_action_model->append (parent.children()));
266 row = *(available_action_model->append ((*r->second)->children()));
270 /* add this action */
273 row[available_action_columns.name] = *t;
276 row[available_action_columns.name] = *l;
280 row[available_action_columns.path] = (*p);
285 MackieControlProtocolGUI::build_function_key_editor ()
287 function_key_editor.append_column (_("Key"), function_key_columns.name);
290 CellRendererCombo* renderer;
292 renderer = make_action_renderer (available_action_model, function_key_columns.plain);
293 col = manage (new TreeViewColumn (_("Plain"), *renderer));
294 col->add_attribute (renderer->property_text(), function_key_columns.plain);
295 function_key_editor.append_column (*col);
297 renderer = make_action_renderer (available_action_model, function_key_columns.shift);
298 col = manage (new TreeViewColumn (_("Shift"), *renderer));
299 col->add_attribute (renderer->property_text(), function_key_columns.shift);
300 function_key_editor.append_column (*col);
302 renderer = make_action_renderer (available_action_model, function_key_columns.control);
303 col = manage (new TreeViewColumn (_("Control"), *renderer));
304 col->add_attribute (renderer->property_text(), function_key_columns.control);
305 function_key_editor.append_column (*col);
307 renderer = make_action_renderer (available_action_model, function_key_columns.option);
308 col = manage (new TreeViewColumn (_("Option"), *renderer));
309 col->add_attribute (renderer->property_text(), function_key_columns.option);
310 function_key_editor.append_column (*col);
312 renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
313 col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
314 col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
315 function_key_editor.append_column (*col);
317 renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
318 col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
319 col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
320 function_key_editor.append_column (*col);
322 function_key_model = ListStore::create (function_key_columns);
323 function_key_editor.set_model (function_key_model);
327 MackieControlProtocolGUI::refresh_function_key_editor ()
329 function_key_editor.set_model (Glib::RefPtr<TreeModel>());
330 function_key_model->clear ();
332 /* now fill with data */
335 DeviceProfile dp (_cp.device_profile());
337 for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
339 Mackie::Button::ID bid = (Mackie::Button::ID) n;
341 row = *(function_key_model->append());
342 row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
343 row[function_key_columns.id] = bid;
345 Glib::RefPtr<Gtk::Action> act;
347 const string defstring = "def";
349 action = dp.get_button_action (bid, 0);
350 if (action.empty()) {
351 row[function_key_columns.plain] = defstring;
353 act = ActionManager::get_action (action.c_str());
355 row[function_key_columns.plain] = act->get_label();
357 row[function_key_columns.plain] = defstring;
361 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
362 if (action.empty()) {
363 row[function_key_columns.control] = defstring;
365 act = ActionManager::get_action (action.c_str());
367 row[function_key_columns.control] = act->get_label();
369 row[function_key_columns.control] = defstring;
373 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
374 if (action.empty()) {
375 row[function_key_columns.shift] = defstring;
377 act = ActionManager::get_action (action.c_str());
379 row[function_key_columns.shift] = act->get_label();
381 row[function_key_columns.shift] = defstring;
385 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
386 if (action.empty()) {
387 row[function_key_columns.option] = defstring;
389 act = ActionManager::get_action (action.c_str());
391 row[function_key_columns.option] = act->get_label();
393 row[function_key_columns.option] = defstring;
397 action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
398 if (action.empty()) {
399 row[function_key_columns.cmdalt] = defstring;
401 act = ActionManager::get_action (action.c_str());
403 row[function_key_columns.cmdalt] = act->get_label();
405 row[function_key_columns.cmdalt] = defstring;
409 action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
410 if (action.empty()) {
411 row[function_key_columns.shiftcontrol] = defstring;
413 act = ActionManager::get_action (action.c_str());
415 row[function_key_columns.shiftcontrol] = act->get_label();
417 row[function_key_columns.shiftcontrol] = defstring;
422 function_key_editor.set_model (function_key_model);
426 MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
428 Gtk::TreePath path(sPath);
429 Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
433 std::map<std::string,std::string>::iterator i = action_map.find (text);
435 cerr << "Changed to " << text << endl;
437 if (i == action_map.end()) {
441 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
444 /* update visible text, using string supplied by
445 available action model so that it matches and is found
448 (*row).set_value (col.index(), text);
450 /* update the current DeviceProfile, using the full
456 switch (col.index()) {
458 modifier = MackieControlProtocol::MODIFIER_SHIFT;
461 modifier = MackieControlProtocol::MODIFIER_CONTROL;
464 modifier = MackieControlProtocol::MODIFIER_OPTION;
467 modifier = MackieControlProtocol::MODIFIER_CMDALT;
470 modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
476 _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
483 MackieControlProtocolGUI::surface_combo_changed ()
485 _cp.set_device (_surface_combo.get_active_text());
487 /* update ipMIDI field */
489 cerr << "New device called " << _cp.device_info().name() << " with ipMIDI ? " << _cp.device_info().uses_ipmidi() << endl;
491 ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
495 MackieControlProtocolGUI::profile_combo_changed ()
497 string profile = _profile_combo.get_active_text();
499 _cp.set_profile (profile);
500 ARDOUR::Config->set_mackie_device_profile (profile);
502 refresh_function_key_editor ();