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/bindings.h"
30 #include "gtkmm2ext/gtk_ui.h"
31 #include "gtkmm2ext/gui_thread.h"
32 #include "gtkmm2ext/utils.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/filesystem_paths.h"
37 #include "faderport.h"
43 using namespace ARDOUR;
44 using namespace ArdourSurface;
47 using namespace Gtkmm2ext;
50 FaderPort::get_gui () const
53 const_cast<FaderPort*>(this)->build_gui ();
55 static_cast<Gtk::VBox*>(gui)->show_all();
60 FaderPort::tear_down_gui ()
63 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
69 delete static_cast<FPGUI*> (gui);
74 FaderPort::build_gui ()
76 gui = (void*) new FPGUI (*this);
79 /*--------------------*/
81 FPGUI::FPGUI (FaderPort& p)
85 , ignore_active_change (false)
87 set_border_width (12);
89 table.set_row_spacings (4);
90 table.set_col_spacings (6);
91 table.set_border_width (12);
92 table.set_homogeneous (false);
94 std::string data_file_path;
95 string name = "faderport-small.png";
96 Searchpath spath(ARDOUR::ardour_data_search_path());
97 spath.add_subdirectory_to_paths ("icons");
98 find_file (spath, name, data_file_path);
99 if (!data_file_path.empty()) {
100 image.set (data_file_path);
101 hpacker.pack_start (image, false, false);
105 Gtk::Alignment* align;
108 input_combo.pack_start (midi_port_columns.short_name);
109 output_combo.pack_start (midi_port_columns.short_name);
111 input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &input_combo, true));
112 output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &output_combo, false));
114 l = manage (new Gtk::Label);
115 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
116 l->set_alignment (1.0, 0.5);
117 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
118 table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
121 l = manage (new Gtk::Label);
122 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
123 l->set_alignment (1.0, 0.5);
124 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
125 table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
128 build_mix_action_combo (mix_combo[0], FaderPort::ButtonState(0));
129 build_mix_action_combo (mix_combo[1], FaderPort::ShiftDown);
130 build_mix_action_combo (mix_combo[2], FaderPort::LongPress);
132 build_proj_action_combo (proj_combo[0], FaderPort::ButtonState(0));
133 build_proj_action_combo (proj_combo[1], FaderPort::ShiftDown);
134 build_proj_action_combo (proj_combo[2], FaderPort::LongPress);
136 build_trns_action_combo (trns_combo[0], FaderPort::ButtonState(0));
137 build_trns_action_combo (trns_combo[1], FaderPort::ShiftDown);
138 build_trns_action_combo (trns_combo[2], FaderPort::LongPress);
140 build_available_action_menu ();
142 build_foot_action_combo (foot_combo[0], FaderPort::ButtonState(0));
143 build_foot_action_combo (foot_combo[1], FaderPort::ShiftDown);
144 build_foot_action_combo (foot_combo[2], FaderPort::LongPress);
146 /* No shift-press combo for User because that is labelled as "next"
150 build_user_action_combo (user_combo[0], FaderPort::ButtonState(0));
151 build_user_action_combo (user_combo[1], FaderPort::LongPress);
153 action_table.set_row_spacings (4);
154 action_table.set_col_spacings (6);
155 action_table.set_border_width (12);
156 action_table.set_homogeneous (false);
160 l = manage (new Gtk::Label);
161 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Press Action")));
162 l->set_alignment (0.5, 0.5);
163 action_table.attach (*l, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
164 l = manage (new Gtk::Label);
165 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Shift-Press Action")));
166 l->set_alignment (0.5, 0.5);
167 action_table.attach (*l, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
168 l = manage (new Gtk::Label);
169 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Long Press Action")));
170 l->set_alignment (0.5, 0.5);
171 action_table.attach (*l, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
174 l = manage (new Gtk::Label);
175 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Mix")));
176 l->set_alignment (1.0, 0.5);
177 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
178 align = manage (new Alignment);
179 align->set (0.0, 0.5);
180 align->add (mix_combo[0]);
181 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
182 align = manage (new Alignment);
183 align->set (0.0, 0.5);
184 align->add (mix_combo[1]);
185 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
186 align = manage (new Alignment);
187 align->set (0.0, 0.5);
188 align->add (mix_combo[2]);
189 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
192 l = manage (new Gtk::Label);
193 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Proj")));
194 l->set_alignment (1.0, 0.5);
195 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
196 align = manage (new Alignment);
197 align->set (0.0, 0.5);
198 align->add (proj_combo[0]);
199 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
200 align = manage (new Alignment);
201 align->set (0.0, 0.5);
202 align->add (proj_combo[1]);
203 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
204 align = manage (new Alignment);
205 align->set (0.0, 0.5);
206 align->add (proj_combo[2]);
207 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
210 l = manage (new Gtk::Label);
211 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Trns")));
212 l->set_alignment (1.0, 0.5);
213 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
214 align = manage (new Alignment);
215 align->set (0.0, 0.5);
216 align->add (trns_combo[0]);
217 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
218 align = manage (new Alignment);
219 align->set (0.0, 0.5);
220 align->add (trns_combo[1]);
221 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
222 align = manage (new Alignment);
223 align->set (0.0, 0.5);
224 align->add (trns_combo[2]);
225 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
228 l = manage (new Gtk::Label);
229 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("User")));
230 l->set_alignment (1.0, 0.5);
231 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
232 align = manage (new Alignment);
233 align->set (0.0, 0.5);
234 align->add (user_combo[0]);
235 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
236 /* skip shift press combo */
237 align = manage (new Alignment);
238 align->set (0.0, 0.5);
239 align->add (user_combo[1]);
240 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
243 l = manage (new Gtk::Label);
244 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Footswitch")));
245 l->set_alignment (1.0, 0.5);
246 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
247 align = manage (new Alignment);
248 align->set (0.0, 0.5);
249 align->add (foot_combo[0]);
250 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
251 align = manage (new Alignment);
252 align->set (0.0, 0.5);
253 align->add (foot_combo[1]);
254 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
255 align = manage (new Alignment);
256 align->set (0.0, 0.5);
257 align->add (foot_combo[2]);
258 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
261 table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
264 hpacker.pack_start (table, true, true);
265 pack_start (hpacker, false, false);
267 /* update the port connection combos */
269 update_port_combos ();
271 /* catch future changes to connection state */
273 fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
281 FPGUI::connection_handler ()
283 /* ignore all changes to combobox active strings here, because we're
284 updating them to match a new ("external") reality - we were called
285 because port connections have changed.
288 PBD::Unwinder<bool> ici (ignore_active_change, true);
290 update_port_combos ();
294 FPGUI::update_port_combos ()
296 vector<string> midi_inputs;
297 vector<string> midi_outputs;
299 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
300 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
302 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
303 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
304 bool input_found = false;
305 bool output_found = false;
308 input_combo.set_model (input);
309 output_combo.set_model (output);
311 Gtk::TreeModel::Children children = input->children();
312 Gtk::TreeModel::Children::iterator i;
313 i = children.begin();
314 ++i; /* skip "Disconnected" */
317 for (n = 1; i != children.end(); ++i, ++n) {
318 string port_name = (*i)[midi_port_columns.full_name];
319 if (fp.input_port()->connected_to (port_name)) {
320 input_combo.set_active (n);
327 input_combo.set_active (0); /* disconnected */
330 children = output->children();
331 i = children.begin();
332 ++i; /* skip "Disconnected" */
334 for (n = 1; i != children.end(); ++i, ++n) {
335 string port_name = (*i)[midi_port_columns.full_name];
336 if (fp.output_port()->connected_to (port_name)) {
337 output_combo.set_active (n);
344 output_combo.set_active (0); /* disconnected */
349 FPGUI::build_available_action_menu ()
351 /* build a model of all available actions (needs to be tree structured
355 available_action_model = TreeStore::create (action_columns);
357 vector<string> paths;
358 vector<string> labels;
359 vector<string> tooltips;
361 vector<Glib::RefPtr<Gtk::Action> > actions;
363 ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
365 typedef std::map<string,TreeIter> NodeMap;
370 vector<string>::iterator k;
371 vector<string>::iterator p;
372 vector<string>::iterator t;
373 vector<string>::iterator l;
375 available_action_model->clear ();
378 TreeModel::Row parent;
380 /* Disabled item (row 0) */
382 rowp = available_action_model->append();
384 parent[action_columns.name] = _("Disabled");
388 rowp = available_action_model->append();
390 parent[action_columns.name] = _("Shift");
391 rowp = available_action_model->append();
393 parent[action_columns.name] = _("Control");
394 rowp = available_action_model->append();
396 parent[action_columns.name] = _("Option");
397 rowp = available_action_model->append();
399 parent[action_columns.name] = _("CmdAlt");
402 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
405 vector<string> parts;
409 split (*p, parts, '/');
415 //kinda kludgy way to avoid displaying menu items as mappable
416 if ( parts[1] == _("Main_menu") )
418 if ( parts[1] == _("JACK") )
420 if ( parts[1] == _("redirectmenu") )
422 if ( parts[1] == _("Editor_menus") )
424 if ( parts[1] == _("RegionList") )
426 if ( parts[1] == _("ProcessorMenu") )
429 if ((r = nodes.find (parts[1])) == nodes.end()) {
431 /* top level is missing */
434 TreeModel::Row parent;
435 rowp = available_action_model->append();
436 nodes[parts[1]] = rowp;
438 parent[action_columns.name] = parts[1];
440 row = *(available_action_model->append (parent.children()));
444 row = *(available_action_model->append ((*r->second)->children()));
448 /* add this action */
451 row[action_columns.name] = *t;
454 row[action_columns.name] = *l;
459 /* ControlProtocol::access_action() is not interested in the
460 legacy "<Actions>/" prefix part of a path.
462 path = path.substr (strlen ("<Actions>/"));
464 row[action_columns.path] = path;
469 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
471 TreeModel::const_iterator row = cb->get_active ();
472 string action_path = (*row)[action_columns.path];
474 /* release binding */
475 fp.set_action (id, action_path, false, bs);
479 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
481 Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
484 string current_action = fp.get_action (id, false, bs); /* lookup release action */
487 vector<pair<string,string> >::const_iterator i;
489 rowp = model->append();
491 row[action_columns.name] = _("Disabled");
492 row[action_columns.path] = string();
494 if (current_action.empty()) {
498 for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
499 rowp = model->append();
501 row[action_columns.name] = i->first;
502 row[action_columns.path] = i->second;
503 if (current_action == i->second) {
508 cb.set_model (model);
509 cb.pack_start (action_columns.name);
511 if (active_row >= 0) {
512 cb.set_active (active_row);
515 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
519 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
521 vector<pair<string,string> > actions;
523 actions.push_back (make_pair (string (_("Show Mixer Window")), string (X_("Window/show-mixer"))));
524 actions.push_back (make_pair (string (_("Show/Hide Mixer list")), string (X_("Common/ToggleMixerList"))));
525 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
526 actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
528 build_action_combo (cb, actions, FaderPort::Mix, bs);
532 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
534 vector<pair<string,string> > actions;
536 actions.push_back (make_pair (string (_("Show Editor Window")), string (X_("Mixer/show-editor"))));
537 actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
538 actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
539 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
540 actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
542 // actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
543 // actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
545 build_action_combo (cb, actions, FaderPort::Proj, bs);
549 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
551 vector<pair<string,string> > actions;
553 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
554 actions.push_back (make_pair (string("Toggle Locations window"), string(X_("Window/toggle-locations"))));
555 actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
556 actions.push_back (make_pair (string("Toggle External Sync"), string(X_("Transport/ToggleExternalSync"))));
557 actions.push_back (make_pair (string("Toggle Follow Playhead"), string(X_("Editor/toggle-follow-playhead"))));
559 // actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
562 build_action_combo (cb, actions, FaderPort::Trns, bs);
566 FPGUI::build_foot_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
568 vector<pair<string,string> > actions;
570 actions.push_back (make_pair (string("Toggle Roll"), string(X_("Transport/ToggleRoll"))));
571 actions.push_back (make_pair (string("Toggle Rec-Enable"), string(X_("Transport/Record"))));
572 actions.push_back (make_pair (string("Toggle Roll+Rec"), string(X_("Transport/record-roll"))));
573 actions.push_back (make_pair (string("Toggle Loop"), string(X_("Transport/Loop"))));
574 actions.push_back (make_pair (string("Toggle Click"), string(X_("Transport/ToggleClick"))));
575 actions.push_back (make_pair (string("Record with Pre-Roll"), string(X_("Transport/RecordPreroll"))));
576 actions.push_back (make_pair (string("Record with Count-In"), string(X_("Transport/RecordCountIn"))));
578 build_action_combo (cb, actions, FaderPort::Footswitch, bs);
582 FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
584 TreeModel::Row row = *iter;
585 string path = row[action_columns.path];
587 if (path == action_path) {
596 FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
598 cb.set_model (available_action_model);
599 cb.pack_start (action_columns.name);
600 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::User, bs));
602 /* set the active "row" to the right value for the current button binding */
604 string current_action = fp.get_action (FaderPort::User, false, bs); /* lookup release action */
606 if (current_action.empty()) {
607 cb.set_active (0); /* "disabled" */
611 TreeModel::iterator iter = available_action_model->children().end();
613 available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
615 if (iter != available_action_model->children().end()) {
616 cb.set_active (iter);
623 Glib::RefPtr<Gtk::ListStore>
624 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
626 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
629 row = *store->append ();
630 row[midi_port_columns.full_name] = string();
631 row[midi_port_columns.short_name] = _("Disconnected");
633 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
634 row = *store->append ();
635 row[midi_port_columns.full_name] = *p;
636 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
638 pn = (*p).substr ((*p).find (':') + 1);
640 row[midi_port_columns.short_name] = pn;
647 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
649 if (ignore_active_change) {
653 TreeModel::iterator active = combo->get_active ();
654 string new_port = (*active)[midi_port_columns.full_name];
656 if (new_port.empty()) {
658 fp.input_port()->disconnect_all ();
660 fp.output_port()->disconnect_all ();
667 if (!fp.input_port()->connected_to (new_port)) {
668 fp.input_port()->disconnect_all ();
669 fp.input_port()->connect (new_port);
672 if (!fp.output_port()->connected_to (new_port)) {
673 fp.output_port()->disconnect_all ();
674 fp.output_port()->connect (new_port);