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/file_utils.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/unwind.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[0] == _("Main Menu") )
418 if (parts[0] == _("JACK") )
420 if (parts[0] == _("redirectmenu") )
422 if (parts[0] == _("RegionList") )
424 if (parts[0] == _("ProcessorMenu") )
427 if ((r = nodes.find (parts[0])) == nodes.end()) {
429 /* top level is missing */
432 TreeModel::Row parent;
433 rowp = available_action_model->append();
434 nodes[parts[0]] = rowp;
436 parent[action_columns.name] = parts[0];
438 row = *(available_action_model->append (parent.children()));
442 row = *(available_action_model->append ((*r->second)->children()));
446 /* add this action */
449 row[action_columns.name] = *t;
452 row[action_columns.name] = *l;
456 row[action_columns.path] = *p;
461 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
463 TreeModel::const_iterator row = cb->get_active ();
464 string action_path = (*row)[action_columns.path];
466 /* release binding */
467 fp.set_action (id, action_path, false, bs);
471 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
473 Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
476 string current_action = fp.get_action (id, false, bs); /* lookup release action */
479 vector<pair<string,string> >::const_iterator i;
481 rowp = model->append();
483 row[action_columns.name] = _("Disabled");
484 row[action_columns.path] = string();
486 if (current_action.empty()) {
490 for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
491 rowp = model->append();
493 row[action_columns.name] = i->first;
494 row[action_columns.path] = i->second;
495 if (current_action == i->second) {
500 cb.set_model (model);
501 cb.pack_start (action_columns.name);
503 if (active_row >= 0) {
504 cb.set_active (active_row);
507 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
511 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
513 vector<pair<string,string> > actions;
515 actions.push_back (make_pair (string (_("Show Mixer Window")), string (X_("Common/show-mixer"))));
516 actions.push_back (make_pair (string (_("Show/Hide Mixer list")), string (X_("Mixer/ToggleMixerList"))));
517 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
518 actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
520 build_action_combo (cb, actions, FaderPort::Mix, bs);
524 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
526 vector<pair<string,string> > actions;
528 actions.push_back (make_pair (string (_("Show Editor Window")), string (X_("Common/show-editor"))));
529 actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
530 actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
531 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
532 actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
534 // actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
535 // actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
537 build_action_combo (cb, actions, FaderPort::Proj, bs);
541 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
543 vector<pair<string,string> > actions;
545 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
546 actions.push_back (make_pair (string("Toggle Locations window"), string(X_("Window/toggle-locations"))));
547 actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
548 actions.push_back (make_pair (string("Toggle External Sync"), string(X_("Transport/ToggleExternalSync"))));
549 actions.push_back (make_pair (string("Toggle Follow Playhead"), string(X_("Editor/toggle-follow-playhead"))));
551 // actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
554 build_action_combo (cb, actions, FaderPort::Trns, bs);
558 FPGUI::build_foot_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
560 vector<pair<string,string> > actions;
562 actions.push_back (make_pair (string("Toggle Roll"), string(X_("Transport/ToggleRoll"))));
563 actions.push_back (make_pair (string("Toggle Rec-Enable"), string(X_("Transport/Record"))));
564 actions.push_back (make_pair (string("Toggle Roll+Rec"), string(X_("Transport/record-roll"))));
565 actions.push_back (make_pair (string("Toggle Loop"), string(X_("Transport/Loop"))));
566 actions.push_back (make_pair (string("Toggle Click"), string(X_("Transport/ToggleClick"))));
567 actions.push_back (make_pair (string("Record with Pre-Roll"), string(X_("Transport/RecordPreroll"))));
568 actions.push_back (make_pair (string("Record with Count-In"), string(X_("Transport/RecordCountIn"))));
570 build_action_combo (cb, actions, FaderPort::Footswitch, bs);
574 FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
576 TreeModel::Row row = *iter;
577 string path = row[action_columns.path];
579 if (path == action_path) {
588 FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
590 cb.set_model (available_action_model);
591 cb.pack_start (action_columns.name);
592 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::User, bs));
594 /* set the active "row" to the right value for the current button binding */
596 string current_action = fp.get_action (FaderPort::User, false, bs); /* lookup release action */
598 if (current_action.empty()) {
599 cb.set_active (0); /* "disabled" */
603 TreeModel::iterator iter = available_action_model->children().end();
605 available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
607 if (iter != available_action_model->children().end()) {
608 cb.set_active (iter);
615 Glib::RefPtr<Gtk::ListStore>
616 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
618 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
621 row = *store->append ();
622 row[midi_port_columns.full_name] = string();
623 row[midi_port_columns.short_name] = _("Disconnected");
625 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
626 row = *store->append ();
627 row[midi_port_columns.full_name] = *p;
628 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
630 pn = (*p).substr ((*p).find (':') + 1);
632 row[midi_port_columns.short_name] = pn;
639 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
641 if (ignore_active_change) {
645 TreeModel::iterator active = combo->get_active ();
646 string new_port = (*active)[midi_port_columns.full_name];
648 if (new_port.empty()) {
650 fp.input_port()->disconnect_all ();
652 fp.output_port()->disconnect_all ();
659 if (!fp.input_port()->connected_to (new_port)) {
660 fp.input_port()->disconnect_all ();
661 fp.input_port()->connect (new_port);
664 if (!fp.output_port()->connected_to (new_port)) {
665 fp.output_port()->disconnect_all ();
666 fp.output_port()->connect (new_port);