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 (_("Sends MIDI to:")));
114 l->set_alignment (1.0, 0.5);
115 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
116 table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
119 l = manage (new Gtk::Label (_("Receives MIDI from:")));
120 l->set_alignment (1.0, 0.5);
121 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
122 table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
125 build_mix_action_combo (mix_combo[0], FaderPort::ButtonState(0));
126 build_mix_action_combo (mix_combo[1], FaderPort::ShiftDown);
127 build_mix_action_combo (mix_combo[2], FaderPort::LongPress);
129 build_proj_action_combo (proj_combo[0], FaderPort::ButtonState(0));
130 build_proj_action_combo (proj_combo[1], FaderPort::ShiftDown);
131 build_proj_action_combo (proj_combo[2], FaderPort::LongPress);
133 build_trns_action_combo (trns_combo[0], FaderPort::ButtonState(0));
134 build_trns_action_combo (trns_combo[1], FaderPort::ShiftDown);
135 build_trns_action_combo (trns_combo[2], FaderPort::LongPress);
137 action_table.set_row_spacings (4);
138 action_table.set_col_spacings (6);
139 action_table.set_border_width (12);
140 action_table.set_homogeneous (false);
145 l = manage (new Gtk::Label (_("Button")));
146 l->set_alignment (1.0, 0.5);
147 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
148 l = manage (new Gtk::Label (_("Normal Press/Release Action")));
149 l->set_alignment (0.5, 0.5);
150 action_table.attach (*l, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
151 l = manage (new Gtk::Label (_("Shift-Press Action")));
152 l->set_alignment (0.5, 0.5);
153 action_table.attach (*l, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
154 l = manage (new Gtk::Label (_("Long Press Action")));
155 l->set_alignment (0.5, 0.5);
156 action_table.attach (*l, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
159 l = manage (new Gtk::Label (_("Mix")));
160 l->set_alignment (1.0, 0.5);
161 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
162 align = manage (new Alignment);
163 align->set (0.0, 0.5);
164 align->add (mix_combo[0]);
165 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
166 align = manage (new Alignment);
167 align->set (0.0, 0.5);
168 align->add (mix_combo[1]);
169 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
170 align = manage (new Alignment);
171 align->set (0.0, 0.5);
172 align->add (mix_combo[2]);
173 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
176 l = manage (new Gtk::Label (_("Proj")));
177 l->set_alignment (1.0, 0.5);
178 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
179 align = manage (new Alignment);
180 align->set (0.0, 0.5);
181 align->add (proj_combo[0]);
182 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
183 align = manage (new Alignment);
184 align->set (0.0, 0.5);
185 align->add (proj_combo[1]);
186 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
187 align = manage (new Alignment);
188 align->set (0.0, 0.5);
189 align->add (proj_combo[2]);
190 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
193 l = manage (new Gtk::Label (_("Trns")));
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 (trns_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 (trns_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 (trns_combo[2]);
207 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
210 table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
213 hpacker.pack_start (table, true, true);
214 pack_start (hpacker, false, false);
216 /* update the port connection combos */
218 update_port_combos ();
220 /* catch future changes to connection state */
222 fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
230 FPGUI::connection_handler ()
232 /* ignore all changes to combobox active strings here, because we're
233 updating them to match a new ("external") reality - we were called
234 because port connections have changed.
237 PBD::Unwinder<bool> ici (ignore_active_change, true);
239 update_port_combos ();
243 FPGUI::update_port_combos ()
245 vector<string> midi_inputs;
246 vector<string> midi_outputs;
248 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
249 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
251 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
252 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
253 bool input_found = false;
254 bool output_found = false;
257 input_combo.set_model (input);
258 output_combo.set_model (output);
260 Gtk::TreeModel::Children children = input->children();
261 Gtk::TreeModel::Children::iterator i;
262 i = children.begin();
263 ++i; /* skip "Disconnected" */
266 for (n = 1; i != children.end(); ++i, ++n) {
267 string port_name = (*i)[midi_port_columns.full_name];
268 if (fp.input_port()->connected_to (port_name)) {
269 input_combo.set_active (n);
276 input_combo.set_active (0); /* disconnected */
279 children = output->children();
280 i = children.begin();
281 ++i; /* skip "Disconnected" */
283 for (n = 1; i != children.end(); ++i, ++n) {
284 string port_name = (*i)[midi_port_columns.full_name];
285 if (fp.output_port()->connected_to (port_name)) {
286 output_combo.set_active (n);
293 output_combo.set_active (0); /* disconnected */
298 FPGUI::build_available_action_menu ()
300 /* build a model of all available actions (needs to be tree structured
304 available_action_model = TreeStore::create (action_columns);
306 vector<string> paths;
307 vector<string> labels;
308 vector<string> tooltips;
310 vector<AccelKey> bindings;
311 typedef std::map<string,TreeIter> NodeMap;
315 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
317 vector<string>::iterator k;
318 vector<string>::iterator p;
319 vector<string>::iterator t;
320 vector<string>::iterator l;
322 available_action_model->clear ();
324 /* Because there are button bindings built in that are not
325 in the key binding map, there needs to be a way to undo
328 TreeModel::Row parent;
329 rowp = available_action_model->append();
331 parent[action_columns.name] = _("Remove Binding");
335 rowp = available_action_model->append();
337 parent[action_columns.name] = _("Shift");
338 rowp = available_action_model->append();
340 parent[action_columns.name] = _("Control");
341 rowp = available_action_model->append();
343 parent[action_columns.name] = _("Option");
344 rowp = available_action_model->append();
346 parent[action_columns.name] = _("CmdAlt");
349 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
352 vector<string> parts;
356 split (*p, parts, '/');
362 //kinda kludgy way to avoid displaying menu items as mappable
363 if ( parts[1] == _("Main_menu") )
365 if ( parts[1] == _("JACK") )
367 if ( parts[1] == _("redirectmenu") )
369 if ( parts[1] == _("Editor_menus") )
371 if ( parts[1] == _("RegionList") )
373 if ( parts[1] == _("ProcessorMenu") )
376 if ((r = nodes.find (parts[1])) == nodes.end()) {
378 /* top level is missing */
381 TreeModel::Row parent;
382 rowp = available_action_model->append();
383 nodes[parts[1]] = rowp;
385 parent[action_columns.name] = parts[1];
387 row = *(available_action_model->append (parent.children()));
391 row = *(available_action_model->append ((*r->second)->children()));
395 /* add this action */
398 row[action_columns.name] = *t;
401 row[action_columns.name] = *l;
405 row[action_columns.path] = (*p);
410 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
412 TreeModel::const_iterator row = cb->get_active ();
413 string action_path = (*row)[action_columns.path];
415 /* release binding */
416 fp.set_action (id, action_path, false, bs);
420 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
422 Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
425 string current_action = fp.get_action (id, true, bs);
428 vector<pair<string,string> >::const_iterator i;
430 rowp = model->append();
432 row[action_columns.name] = _("Disabled");
433 row[action_columns.path] = string();
435 if (current_action.empty()) {
439 for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
440 rowp = model->append();
442 row[action_columns.name] = i->first;
443 row[action_columns.path] = i->second;
444 if (current_action == i->second) {
449 cb.set_model (model);
450 cb.pack_start (action_columns.name);
452 if (active_row >= 0) {
453 cb.set_active (active_row);
456 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
460 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
462 vector<pair<string,string> > actions;
464 actions.push_back (make_pair (string (_("Toggle Editor & Mixer Windows")), string (X_("Common/toggle-editor-mixer"))));
465 actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
467 build_action_combo (cb, actions, FaderPort::Mix, bs);
471 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
473 vector<pair<string,string> > actions;
475 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
476 actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
477 actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
478 actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
479 actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
480 actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
482 build_action_combo (cb, actions, FaderPort::Proj, bs);
486 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
488 vector<pair<string,string> > actions;
490 actions.push_back (make_pair (string("Toggle Locations"), string(X_("Window/toggle-locations"))));
491 actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
492 actions.push_back (make_pair (string("Toggle Sync"), string(X_("Transport/ToggleExternalSync"))));
493 actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
495 build_action_combo (cb, actions, FaderPort::Trns, bs);
498 Glib::RefPtr<Gtk::ListStore>
499 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
501 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
504 row = *store->append ();
505 row[midi_port_columns.full_name] = string();
506 row[midi_port_columns.short_name] = _("Disconnected");
508 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
509 row = *store->append ();
510 row[midi_port_columns.full_name] = *p;
511 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
513 pn = (*p).substr ((*p).find (':') + 1);
515 row[midi_port_columns.short_name] = pn;
522 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
524 if (ignore_active_change) {
528 TreeModel::iterator active = combo->get_active ();
529 string new_port = (*active)[midi_port_columns.full_name];
531 if (new_port.empty()) {
533 fp.input_port()->disconnect_all ();
535 fp.output_port()->disconnect_all ();
542 if (!fp.input_port()->connected_to (new_port)) {
543 fp.input_port()->disconnect_all ();
544 fp.input_port()->connect (new_port);
547 if (!fp.output_port()->connected_to (new_port)) {
548 fp.output_port()->disconnect_all ();
549 fp.output_port()->connect (new_port);