2 Copyright (C) 2015 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.
20 #include <gtkmm/alignment.h>
21 #include <gtkmm/label.h>
22 #include <gtkmm/liststore.h>
24 #include "pbd/unwind.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/file_utils.h"
28 #include "gtkmm2ext/actions.h"
29 #include "gtkmm2ext/gtk_ui.h"
30 #include "gtkmm2ext/gui_thread.h"
31 #include "gtkmm2ext/utils.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/filesystem_paths.h"
36 #include "faderport.h"
42 using namespace ARDOUR;
43 using namespace ArdourSurface;
46 using namespace Gtkmm2ext;
49 FaderPort::get_gui () const
52 const_cast<FaderPort*>(this)->build_gui ();
54 static_cast<Gtk::VBox*>(gui)->show_all();
59 FaderPort::tear_down_gui ()
62 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
68 delete static_cast<FPGUI*> (gui);
73 FaderPort::build_gui ()
75 gui = (void*) new FPGUI (*this);
78 /*--------------------*/
80 FPGUI::FPGUI (FaderPort& p)
84 , ignore_active_change (false)
86 set_border_width (12);
88 table.set_row_spacings (4);
89 table.set_col_spacings (6);
90 table.set_border_width (12);
91 table.set_homogeneous (false);
93 std::string data_file_path;
94 string name = "faderport-small.png";
95 Searchpath spath(ARDOUR::ardour_data_search_path());
96 spath.add_subdirectory_to_paths ("icons");
97 find_file (spath, name, data_file_path);
98 if (!data_file_path.empty()) {
99 image.set (data_file_path);
100 hpacker.pack_start (image, false, false);
104 Gtk::Alignment* align;
107 input_combo.pack_start (midi_port_columns.short_name);
108 output_combo.pack_start (midi_port_columns.short_name);
110 input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &input_combo, true));
111 output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &output_combo, false));
113 l = manage (new Gtk::Label);
114 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
115 l->set_alignment (1.0, 0.5);
116 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
117 table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
120 l = manage (new Gtk::Label);
121 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
122 l->set_alignment (1.0, 0.5);
123 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
124 table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
127 build_mix_action_combo (mix_combo[0], FaderPort::ButtonState(0));
128 build_mix_action_combo (mix_combo[1], FaderPort::ShiftDown);
129 build_mix_action_combo (mix_combo[2], FaderPort::LongPress);
131 build_proj_action_combo (proj_combo[0], FaderPort::ButtonState(0));
132 build_proj_action_combo (proj_combo[1], FaderPort::ShiftDown);
133 build_proj_action_combo (proj_combo[2], FaderPort::LongPress);
135 build_trns_action_combo (trns_combo[0], FaderPort::ButtonState(0));
136 build_trns_action_combo (trns_combo[1], FaderPort::ShiftDown);
137 build_trns_action_combo (trns_combo[2], FaderPort::LongPress);
139 build_available_action_menu ();
141 /* No shift-press combo for User because that is labelled as "next"
145 build_user_action_combo (user_combo[0], FaderPort::ButtonState(0));
146 build_user_action_combo (user_combo[1], FaderPort::LongPress);
148 action_table.set_row_spacings (4);
149 action_table.set_col_spacings (6);
150 action_table.set_border_width (12);
151 action_table.set_homogeneous (false);
155 l = manage (new Gtk::Label);
156 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Press Action")));
157 l->set_alignment (0.5, 0.5);
158 action_table.attach (*l, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
159 l = manage (new Gtk::Label);
160 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Shift-Press Action")));
161 l->set_alignment (0.5, 0.5);
162 action_table.attach (*l, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
163 l = manage (new Gtk::Label);
164 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Long Press Action")));
165 l->set_alignment (0.5, 0.5);
166 action_table.attach (*l, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
169 l = manage (new Gtk::Label);
170 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Mix")));
171 l->set_alignment (1.0, 0.5);
172 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
173 align = manage (new Alignment);
174 align->set (0.0, 0.5);
175 align->add (mix_combo[0]);
176 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
177 align = manage (new Alignment);
178 align->set (0.0, 0.5);
179 align->add (mix_combo[1]);
180 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
181 align = manage (new Alignment);
182 align->set (0.0, 0.5);
183 align->add (mix_combo[2]);
184 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
187 l = manage (new Gtk::Label);
188 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Proj")));
189 l->set_alignment (1.0, 0.5);
190 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
191 align = manage (new Alignment);
192 align->set (0.0, 0.5);
193 align->add (proj_combo[0]);
194 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
195 align = manage (new Alignment);
196 align->set (0.0, 0.5);
197 align->add (proj_combo[1]);
198 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
199 align = manage (new Alignment);
200 align->set (0.0, 0.5);
201 align->add (proj_combo[2]);
202 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
205 l = manage (new Gtk::Label);
206 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Trns")));
207 l->set_alignment (1.0, 0.5);
208 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
209 align = manage (new Alignment);
210 align->set (0.0, 0.5);
211 align->add (trns_combo[0]);
212 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
213 align = manage (new Alignment);
214 align->set (0.0, 0.5);
215 align->add (trns_combo[1]);
216 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
217 align = manage (new Alignment);
218 align->set (0.0, 0.5);
219 align->add (trns_combo[2]);
220 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
223 l = manage (new Gtk::Label);
224 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("User")));
225 l->set_alignment (1.0, 0.5);
226 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
227 align = manage (new Alignment);
228 align->set (0.0, 0.5);
229 align->add (user_combo[0]);
230 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
231 /* skip shift press combo */
232 align = manage (new Alignment);
233 align->set (0.0, 0.5);
234 align->add (user_combo[1]);
235 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
238 table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
241 hpacker.pack_start (table, true, true);
242 pack_start (hpacker, false, false);
244 /* update the port connection combos */
246 update_port_combos ();
248 /* catch future changes to connection state */
250 fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
258 FPGUI::connection_handler ()
260 /* ignore all changes to combobox active strings here, because we're
261 updating them to match a new ("external") reality - we were called
262 because port connections have changed.
265 PBD::Unwinder<bool> ici (ignore_active_change, true);
267 update_port_combos ();
271 FPGUI::update_port_combos ()
273 vector<string> midi_inputs;
274 vector<string> midi_outputs;
276 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
277 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
279 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
280 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
281 bool input_found = false;
282 bool output_found = false;
285 input_combo.set_model (input);
286 output_combo.set_model (output);
288 Gtk::TreeModel::Children children = input->children();
289 Gtk::TreeModel::Children::iterator i;
290 i = children.begin();
291 ++i; /* skip "Disconnected" */
294 for (n = 1; i != children.end(); ++i, ++n) {
295 string port_name = (*i)[midi_port_columns.full_name];
296 if (fp.input_port()->connected_to (port_name)) {
297 input_combo.set_active (n);
304 input_combo.set_active (0); /* disconnected */
307 children = output->children();
308 i = children.begin();
309 ++i; /* skip "Disconnected" */
311 for (n = 1; i != children.end(); ++i, ++n) {
312 string port_name = (*i)[midi_port_columns.full_name];
313 if (fp.output_port()->connected_to (port_name)) {
314 output_combo.set_active (n);
321 output_combo.set_active (0); /* disconnected */
326 FPGUI::build_available_action_menu ()
328 /* build a model of all available actions (needs to be tree structured
332 available_action_model = TreeStore::create (action_columns);
334 vector<string> paths;
335 vector<string> labels;
336 vector<string> tooltips;
338 vector<AccelKey> bindings;
339 typedef std::map<string,TreeIter> NodeMap;
343 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
345 vector<string>::iterator k;
346 vector<string>::iterator p;
347 vector<string>::iterator t;
348 vector<string>::iterator l;
350 available_action_model->clear ();
353 TreeModel::Row parent;
355 /* Disabled item (row 0) */
357 rowp = available_action_model->append();
359 parent[action_columns.name] = _("Disabled");
363 rowp = available_action_model->append();
365 parent[action_columns.name] = _("Shift");
366 rowp = available_action_model->append();
368 parent[action_columns.name] = _("Control");
369 rowp = available_action_model->append();
371 parent[action_columns.name] = _("Option");
372 rowp = available_action_model->append();
374 parent[action_columns.name] = _("CmdAlt");
377 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
380 vector<string> parts;
384 split (*p, parts, '/');
390 //kinda kludgy way to avoid displaying menu items as mappable
391 if ( parts[1] == _("Main_menu") )
393 if ( parts[1] == _("JACK") )
395 if ( parts[1] == _("redirectmenu") )
397 if ( parts[1] == _("Editor_menus") )
399 if ( parts[1] == _("RegionList") )
401 if ( parts[1] == _("ProcessorMenu") )
404 if ((r = nodes.find (parts[1])) == nodes.end()) {
406 /* top level is missing */
409 TreeModel::Row parent;
410 rowp = available_action_model->append();
411 nodes[parts[1]] = rowp;
413 parent[action_columns.name] = parts[1];
415 row = *(available_action_model->append (parent.children()));
419 row = *(available_action_model->append ((*r->second)->children()));
423 /* add this action */
426 row[action_columns.name] = *t;
429 row[action_columns.name] = *l;
434 /* ControlProtocol::access_action() is not interested in the
435 legacy "<Actions>/" prefix part of a path.
437 path = path.substr (strlen ("<Actions>/"));
439 row[action_columns.path] = path;
444 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
446 TreeModel::const_iterator row = cb->get_active ();
447 string action_path = (*row)[action_columns.path];
449 /* release binding */
450 fp.set_action (id, action_path, false, bs);
454 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
456 Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
459 string current_action = fp.get_action (id, false, bs); /* lookup release action */
462 vector<pair<string,string> >::const_iterator i;
464 rowp = model->append();
466 row[action_columns.name] = _("Disabled");
467 row[action_columns.path] = string();
469 if (current_action.empty()) {
473 for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
474 rowp = model->append();
476 row[action_columns.name] = i->first;
477 row[action_columns.path] = i->second;
478 if (current_action == i->second) {
483 cb.set_model (model);
484 cb.pack_start (action_columns.name);
486 if (active_row >= 0) {
487 cb.set_active (active_row);
490 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
494 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
496 vector<pair<string,string> > actions;
498 actions.push_back (make_pair (string (_("Toggle Editor & Mixer Windows")), string (X_("Common/toggle-editor-mixer"))));
499 actions.push_back (make_pair (string (_("Show/Hide Mixer list")), string (X_("Common/ToggleMixerList"))));
500 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
501 actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
503 build_action_combo (cb, actions, FaderPort::Mix, bs);
507 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
509 vector<pair<string,string> > actions;
511 actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
512 actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
513 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
514 actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
516 // actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
517 // actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
519 build_action_combo (cb, actions, FaderPort::Proj, bs);
523 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
525 vector<pair<string,string> > actions;
527 actions.push_back (make_pair (string("Toggle Big Clock"), string(X_("Window/toggle-big-clock")))); //note: this would really make sense if the Big Clock had transport buttons on it
528 actions.push_back (make_pair (string("Toggle Locations window"), string(X_("Window/toggle-locations"))));
529 actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
530 actions.push_back (make_pair (string("Toggle External Sync"), string(X_("Transport/ToggleExternalSync"))));
531 actions.push_back (make_pair (string("Toggle Follow Playhead"), string(X_("Editor/toggle-follow-playhead"))));
533 // actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
536 build_action_combo (cb, actions, FaderPort::Trns, bs);
540 FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
542 TreeModel::Row row = *iter;
543 string path = row[action_columns.path];
545 if (path == action_path) {
554 FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
556 cb.set_model (available_action_model);
557 cb.pack_start (action_columns.name);
558 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::User, bs));
560 /* set the active "row" to the right value for the current button binding */
562 string current_action = fp.get_action (FaderPort::User, false, bs); /* lookup release action */
564 if (current_action.empty()) {
565 cb.set_active (0); /* "disabled" */
569 TreeModel::iterator iter = available_action_model->children().end();
571 available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
573 if (iter != available_action_model->children().end()) {
574 cb.set_active (iter);
581 Glib::RefPtr<Gtk::ListStore>
582 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
584 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
587 row = *store->append ();
588 row[midi_port_columns.full_name] = string();
589 row[midi_port_columns.short_name] = _("Disconnected");
591 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
592 row = *store->append ();
593 row[midi_port_columns.full_name] = *p;
594 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
596 pn = (*p).substr ((*p).find (':') + 1);
598 row[midi_port_columns.short_name] = pn;
605 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
607 if (ignore_active_change) {
611 TreeModel::iterator active = combo->get_active ();
612 string new_port = (*active)[midi_port_columns.full_name];
614 if (new_port.empty()) {
616 fp.input_port()->disconnect_all ();
618 fp.output_port()->disconnect_all ();
625 if (!fp.input_port()->connected_to (new_port)) {
626 fp.input_port()->disconnect_all ();
627 fp.input_port()->connect (new_port);
630 if (!fp.output_port()->connected_to (new_port)) {
631 fp.output_port()->disconnect_all ();
632 fp.output_port()->connect (new_port);