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"
27 #include "gtkmm2ext/actions.h"
28 #include "gtkmm2ext/gtk_ui.h"
29 #include "gtkmm2ext/gui_thread.h"
30 #include "gtkmm2ext/utils.h"
32 #include "ardour/audioengine.h"
34 #include "faderport.h"
40 using namespace ARDOUR;
41 using namespace ArdourSurface;
44 using namespace Gtkmm2ext;
47 FaderPort::get_gui () const
50 const_cast<FaderPort*>(this)->build_gui ();
52 static_cast<Gtk::VBox*>(gui)->show_all();
57 FaderPort::tear_down_gui ()
60 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
66 delete static_cast<FPGUI*> (gui);
71 FaderPort::build_gui ()
73 gui = (void*) new FPGUI (*this);
76 /*--------------------*/
78 FPGUI::FPGUI (FaderPort& p)
82 , ignore_active_change (false)
84 set_border_width (12);
86 table.set_row_spacings (4);
87 table.set_col_spacings (6);
88 table.set_border_width (12);
89 table.set_homogeneous (false);
92 Gtk::Alignment* align;
95 input_combo.pack_start (midi_port_columns.short_name);
96 output_combo.pack_start (midi_port_columns.short_name);
98 input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &input_combo, true));
99 output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &output_combo, false));
101 l = manage (new Gtk::Label (_("Sends MIDI to:")));
102 l->set_alignment (1.0, 0.5);
103 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
104 table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
107 l = manage (new Gtk::Label (_("Receives MIDI from:")));
108 l->set_alignment (1.0, 0.5);
109 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
110 table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
113 build_mix_action_combo (mix_combo[0], FaderPort::ButtonState(0));
114 build_mix_action_combo (mix_combo[1], FaderPort::ShiftDown);
115 build_mix_action_combo (mix_combo[2], FaderPort::LongishPress);
116 build_mix_action_combo (mix_combo[3], FaderPort::LongPress);
118 build_proj_action_combo (proj_combo[0], FaderPort::ButtonState(0));
119 build_proj_action_combo (proj_combo[1], FaderPort::ShiftDown);
120 build_proj_action_combo (proj_combo[2], FaderPort::LongishPress);
121 build_proj_action_combo (proj_combo[3], FaderPort::LongPress);
123 build_trns_action_combo (trns_combo[0], FaderPort::ButtonState(0));
124 build_trns_action_combo (trns_combo[1], FaderPort::ShiftDown);
125 build_trns_action_combo (trns_combo[2], FaderPort::LongishPress);
126 build_trns_action_combo (trns_combo[3], FaderPort::LongPress);
128 action_table.set_row_spacings (4);
129 action_table.set_col_spacings (6);
130 action_table.set_border_width (12);
131 action_table.set_homogeneous (false);
136 l = manage (new Gtk::Label (_("Button")));
137 l->set_alignment (1.0, 0.5);
138 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
139 l = manage (new Gtk::Label (_("Press")));
140 l->set_alignment (1.0, 0.5);
141 action_table.attach (*l, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
142 l = manage (new Gtk::Label (_("Shift")));
143 l->set_alignment (1.0, 0.5);
144 action_table.attach (*l, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
145 l = manage (new Gtk::Label (_("Medium")));
146 l->set_alignment (1.0, 0.5);
147 action_table.attach (*l, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
148 l = manage (new Gtk::Label (_("Long")));
149 l->set_alignment (1.0, 0.5);
150 action_table.attach (*l, 4, 5, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
153 l = manage (new Gtk::Label (_("Mix")));
154 l->set_alignment (1.0, 0.5);
155 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
156 align = manage (new Alignment);
157 align->set (0.0, 0.5);
158 align->add (mix_combo[0]);
159 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
160 align = manage (new Alignment);
161 align->set (0.0, 0.5);
162 align->add (mix_combo[1]);
163 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
164 align = manage (new Alignment);
165 align->set (0.0, 0.5);
166 align->add (mix_combo[2]);
167 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
168 align = manage (new Alignment);
169 align->set (0.0, 0.5);
170 align->add (mix_combo[3]);
171 action_table.attach (*align, 4, 5, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
174 l = manage (new Gtk::Label (_("Proj")));
175 l->set_alignment (1.0, 0.5);
176 action_table.attach (*l, 0, 1, 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 (proj_combo[0]);
180 action_table.attach (*align, 1, 2, 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 (proj_combo[1]);
184 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
185 align = manage (new Alignment);
186 align->set (0.0, 0.5);
187 align->add (proj_combo[2]);
188 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
189 align = manage (new Alignment);
190 align->set (0.0, 0.5);
191 align->add (proj_combo[3]);
192 action_table.attach (*align, 4, 5, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
195 l = manage (new Gtk::Label (_("Trns")));
196 l->set_alignment (1.0, 0.5);
197 action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
198 align = manage (new Alignment);
199 align->set (0.0, 0.5);
200 align->add (trns_combo[0]);
201 action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
202 align = manage (new Alignment);
203 align->set (0.0, 0.5);
204 align->add (trns_combo[1]);
205 action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
206 align = manage (new Alignment);
207 align->set (0.0, 0.5);
208 align->add (trns_combo[2]);
209 action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
210 align = manage (new Alignment);
211 align->set (0.0, 0.5);
212 align->add (trns_combo[3]);
213 action_table.attach (*align, 4, 5, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
216 table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
219 pack_start (table, false, false);
221 /* update the port connection combos */
223 update_port_combos ();
225 /* catch future changes to connection state */
227 fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
235 FPGUI::connection_handler ()
237 /* ignore all changes to combobox active strings here, because we're
238 updating them to match a new ("external") reality - we were called
239 because port connections have changed.
242 PBD::Unwinder<bool> ici (ignore_active_change, true);
244 update_port_combos ();
248 FPGUI::update_port_combos ()
250 vector<string> midi_inputs;
251 vector<string> midi_outputs;
253 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
254 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
256 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
257 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
258 bool input_found = false;
259 bool output_found = false;
262 input_combo.set_model (input);
263 output_combo.set_model (output);
265 Gtk::TreeModel::Children children = input->children();
266 Gtk::TreeModel::Children::iterator i;
267 i = children.begin();
268 ++i; /* skip "Disconnected" */
271 for (n = 1; i != children.end(); ++i, ++n) {
272 string port_name = (*i)[midi_port_columns.full_name];
273 if (fp.input_port()->connected_to (port_name)) {
274 input_combo.set_active (n);
281 input_combo.set_active (0); /* disconnected */
284 children = output->children();
285 i = children.begin();
286 ++i; /* skip "Disconnected" */
288 for (n = 1; i != children.end(); ++i, ++n) {
289 string port_name = (*i)[midi_port_columns.full_name];
290 if (fp.output_port()->connected_to (port_name)) {
291 output_combo.set_active (n);
298 output_combo.set_active (0); /* disconnected */
303 FPGUI::build_available_action_menu ()
305 /* build a model of all available actions (needs to be tree structured
309 available_action_model = TreeStore::create (action_columns);
311 vector<string> paths;
312 vector<string> labels;
313 vector<string> tooltips;
315 vector<AccelKey> bindings;
316 typedef std::map<string,TreeIter> NodeMap;
320 ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
322 vector<string>::iterator k;
323 vector<string>::iterator p;
324 vector<string>::iterator t;
325 vector<string>::iterator l;
327 available_action_model->clear ();
329 /* Because there are button bindings built in that are not
330 in the key binding map, there needs to be a way to undo
333 TreeModel::Row parent;
334 rowp = available_action_model->append();
336 parent[action_columns.name] = _("Remove Binding");
340 rowp = available_action_model->append();
342 parent[action_columns.name] = _("Shift");
343 rowp = available_action_model->append();
345 parent[action_columns.name] = _("Control");
346 rowp = available_action_model->append();
348 parent[action_columns.name] = _("Option");
349 rowp = available_action_model->append();
351 parent[action_columns.name] = _("CmdAlt");
354 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
357 vector<string> parts;
361 split (*p, parts, '/');
367 //kinda kludgy way to avoid displaying menu items as mappable
368 if ( parts[1] == _("Main_menu") )
370 if ( parts[1] == _("JACK") )
372 if ( parts[1] == _("redirectmenu") )
374 if ( parts[1] == _("Editor_menus") )
376 if ( parts[1] == _("RegionList") )
378 if ( parts[1] == _("ProcessorMenu") )
381 if ((r = nodes.find (parts[1])) == nodes.end()) {
383 /* top level is missing */
386 TreeModel::Row parent;
387 rowp = available_action_model->append();
388 nodes[parts[1]] = rowp;
390 parent[action_columns.name] = parts[1];
392 row = *(available_action_model->append (parent.children()));
396 row = *(available_action_model->append ((*r->second)->children()));
400 /* add this action */
403 row[action_columns.name] = *t;
406 row[action_columns.name] = *l;
410 row[action_columns.path] = (*p);
415 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
417 TreeModel::const_iterator row = cb->get_active ();
418 string action_path = (*row)[action_columns.path];
420 /* release binding */
421 cerr << "Reset release for " << id << " to " << action_path << " bs = " << hex << bs << dec << endl;
422 fp.set_action (id, action_path, false, bs);
426 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
428 Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
431 string current_action = fp.get_action (id, true, bs);
434 vector<pair<string,string> >::const_iterator i;
436 rowp = model->append();
438 row[action_columns.name] = _("Disabled");
439 row[action_columns.path] = string();
441 if (current_action.empty()) {
445 for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
446 rowp = model->append();
448 row[action_columns.name] = i->first;
449 row[action_columns.path] = i->second;
450 if (current_action == i->second) {
455 cb.set_model (model);
456 cb.pack_start (action_columns.name);
458 if (active_row >= 0) {
459 cb.set_active (active_row);
462 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
466 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
468 vector<pair<string,string> > actions;
470 actions.push_back (make_pair (string (_("Toggle Editor & Mixer Windows")), string (X_("Common/toggle-editor-mixer"))));
471 actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
473 build_action_combo (cb, actions, FaderPort::Mix, bs);
477 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
479 vector<pair<string,string> > actions;
481 actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
482 actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
483 actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
484 actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
485 actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
486 actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
488 build_action_combo (cb, actions, FaderPort::Proj, bs);
492 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
494 vector<pair<string,string> > actions;
496 actions.push_back (make_pair (string("Toggle Locations"), string(X_("Window/toggle-locations"))));
497 actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
498 actions.push_back (make_pair (string("Toggle Sync"), string(X_("Transport/ToggleExternalSync"))));
499 actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
501 build_action_combo (cb, actions, FaderPort::Trns, bs);
504 Glib::RefPtr<Gtk::ListStore>
505 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
507 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
510 row = *store->append ();
511 row[midi_port_columns.full_name] = string();
512 row[midi_port_columns.short_name] = _("Disconnected");
514 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
515 row = *store->append ();
516 row[midi_port_columns.full_name] = *p;
517 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
519 pn = (*p).substr ((*p).find (':') + 1);
521 row[midi_port_columns.short_name] = pn;
528 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
530 if (ignore_active_change) {
534 TreeModel::iterator active = combo->get_active ();
535 string new_port = (*active)[midi_port_columns.full_name];
537 if (new_port.empty()) {
539 fp.input_port()->disconnect_all ();
541 fp.output_port()->disconnect_all ();
548 if (!fp.input_port()->connected_to (new_port)) {
549 fp.input_port()->disconnect_all ();
550 fp.input_port()->connect (new_port);
553 if (!fp.output_port()->connected_to (new_port)) {
554 fp.output_port()->disconnect_all ();
555 fp.output_port()->connect (new_port);