68c89007b14534e26c6e1dde6814cc777c23134a
[ardour.git] / libs / surfaces / faderport / gui.cc
1 /*
2     Copyright (C) 2015 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <gtkmm/alignment.h>
21 #include <gtkmm/label.h>
22 #include <gtkmm/liststore.h>
23
24 #include "pbd/unwind.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/file_utils.h"
27
28 #include "gtkmm2ext/bindings.h"
29 #include "gtkmm2ext/gtk_ui.h"
30 #include "gtkmm2ext/gui_thread.h"
31 #include "gtkmm2ext/utils.h"
32
33 #include "ardour/audioengine.h"
34 #include "ardour/filesystem_paths.h"
35
36 #include "faderport.h"
37 #include "gui.h"
38
39 #include "pbd/i18n.h"
40
41 using namespace PBD;
42 using namespace ARDOUR;
43 using namespace ArdourSurface;
44 using namespace std;
45 using namespace Gtk;
46 using namespace Gtkmm2ext;
47
48 void*
49 FaderPort::get_gui () const
50 {
51         if (!gui) {
52                 const_cast<FaderPort*>(this)->build_gui ();
53         }
54         static_cast<Gtk::VBox*>(gui)->show_all();
55         return gui;
56 }
57
58 void
59 FaderPort::tear_down_gui ()
60 {
61         if (gui) {
62                 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
63                 if (w) {
64                         w->hide();
65                         delete w;
66                 }
67         }
68         delete static_cast<FPGUI*> (gui);
69         gui = 0;
70 }
71
72 void
73 FaderPort::build_gui ()
74 {
75         gui = (void*) new FPGUI (*this);
76 }
77
78 /*--------------------*/
79
80 FPGUI::FPGUI (FaderPort& p)
81         : fp (p)
82         , table (2, 5)
83         , action_table (5, 4)
84         , ignore_active_change (false)
85 {
86         set_border_width (12);
87
88         table.set_row_spacings (4);
89         table.set_col_spacings (6);
90         table.set_border_width (12);
91         table.set_homogeneous (false);
92
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);
101         }
102
103         Gtk::Label* l;
104         Gtk::Alignment* align;
105         int row = 0;
106
107         input_combo.pack_start (midi_port_columns.short_name);
108         output_combo.pack_start (midi_port_columns.short_name);
109
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));
112
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);
118         row++;
119
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);
125         row++;
126
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);
130
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);
134
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);
138
139         build_available_action_menu ();
140
141         build_foot_action_combo (foot_combo[0], FaderPort::ButtonState(0));
142         build_foot_action_combo (foot_combo[1], FaderPort::ShiftDown);
143         build_foot_action_combo (foot_combo[2], FaderPort::LongPress);
144
145         /* No shift-press combo for User because that is labelled as "next"
146          * (marker)
147          */
148
149         build_user_action_combo (user_combo[0], FaderPort::ButtonState(0));
150         build_user_action_combo (user_combo[1], FaderPort::LongPress);
151
152         action_table.set_row_spacings (4);
153         action_table.set_col_spacings (6);
154         action_table.set_border_width (12);
155         action_table.set_homogeneous (false);
156
157         int action_row = 0;
158
159         l = manage (new Gtk::Label);
160         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Press Action")));
161         l->set_alignment (0.5, 0.5);
162         action_table.attach (*l, 1, 2, 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>", _("Shift-Press Action")));
165         l->set_alignment (0.5, 0.5);
166         action_table.attach (*l, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
167         l = manage (new Gtk::Label);
168         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Long Press Action")));
169         l->set_alignment (0.5, 0.5);
170         action_table.attach (*l, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
171         action_row++;
172
173         l = manage (new Gtk::Label);
174         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Mix")));
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 (mix_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 (mix_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 (mix_combo[2]);
188         action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
189         action_row++;
190
191         l = manage (new Gtk::Label);
192         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Proj")));
193         l->set_alignment (1.0, 0.5);
194         action_table.attach (*l, 0, 1, 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[0]);
198         action_table.attach (*align, 1, 2, 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[1]);
202         action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
203         align = manage (new Alignment);
204         align->set (0.0, 0.5);
205         align->add (proj_combo[2]);
206         action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
207         action_row++;
208
209         l = manage (new Gtk::Label);
210         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Trns")));
211         l->set_alignment (1.0, 0.5);
212         action_table.attach (*l, 0, 1, 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[0]);
216         action_table.attach (*align, 1, 2, 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[1]);
220         action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
221         align = manage (new Alignment);
222         align->set (0.0, 0.5);
223         align->add (trns_combo[2]);
224         action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
225         action_row++;
226
227         l = manage (new Gtk::Label);
228         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("User")));
229         l->set_alignment (1.0, 0.5);
230         action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
231         align = manage (new Alignment);
232         align->set (0.0, 0.5);
233         align->add (user_combo[0]);
234         action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
235         /* skip shift press combo */
236         align = manage (new Alignment);
237         align->set (0.0, 0.5);
238         align->add (user_combo[1]);
239         action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
240         action_row++;
241
242         l = manage (new Gtk::Label);
243         l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Footswitch")));
244         l->set_alignment (1.0, 0.5);
245         action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
246         align = manage (new Alignment);
247         align->set (0.0, 0.5);
248         align->add (foot_combo[0]);
249         action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
250         align = manage (new Alignment);
251         align->set (0.0, 0.5);
252         align->add (foot_combo[1]);
253         action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
254         align = manage (new Alignment);
255         align->set (0.0, 0.5);
256         align->add (foot_combo[2]);
257         action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
258         action_row++;
259
260         table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
261         row++;
262
263         hpacker.pack_start (table, true, true);
264         pack_start (hpacker, false, false);
265
266         /* update the port connection combos */
267
268         update_port_combos ();
269
270         /* catch future changes to connection state */
271
272         fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
273 }
274
275 FPGUI::~FPGUI ()
276 {
277 }
278
279 void
280 FPGUI::connection_handler ()
281 {
282         /* ignore all changes to combobox active strings here, because we're
283            updating them to match a new ("external") reality - we were called
284            because port connections have changed.
285         */
286
287         PBD::Unwinder<bool> ici (ignore_active_change, true);
288
289         update_port_combos ();
290 }
291
292 void
293 FPGUI::update_port_combos ()
294 {
295         vector<string> midi_inputs;
296         vector<string> midi_outputs;
297
298         ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
299         ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
300
301         Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
302         Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
303         bool input_found = false;
304         bool output_found = false;
305         int n;
306
307         input_combo.set_model (input);
308         output_combo.set_model (output);
309
310         Gtk::TreeModel::Children children = input->children();
311         Gtk::TreeModel::Children::iterator i;
312         i = children.begin();
313         ++i; /* skip "Disconnected" */
314
315
316         for (n = 1;  i != children.end(); ++i, ++n) {
317                 string port_name = (*i)[midi_port_columns.full_name];
318                 if (fp.input_port()->connected_to (port_name)) {
319                         input_combo.set_active (n);
320                         input_found = true;
321                         break;
322                 }
323         }
324
325         if (!input_found) {
326                 input_combo.set_active (0); /* disconnected */
327         }
328
329         children = output->children();
330         i = children.begin();
331         ++i; /* skip "Disconnected" */
332
333         for (n = 1;  i != children.end(); ++i, ++n) {
334                 string port_name = (*i)[midi_port_columns.full_name];
335                 if (fp.output_port()->connected_to (port_name)) {
336                         output_combo.set_active (n);
337                         output_found = true;
338                         break;
339                 }
340         }
341
342         if (!output_found) {
343                 output_combo.set_active (0); /* disconnected */
344         }
345 }
346
347 void
348 FPGUI::build_available_action_menu ()
349 {
350         /* build a model of all available actions (needs to be tree structured
351          * more)
352          */
353
354         available_action_model = TreeStore::create (action_columns);
355
356         vector<string> paths;
357         vector<string> labels;
358         vector<string> tooltips;
359         vector<string> keys;
360         vector<Glib::RefPtr<Gtk::Action> > actions;
361
362         Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
363
364         typedef std::map<string,TreeIter> NodeMap;
365         NodeMap nodes;
366         NodeMap::iterator r;
367
368
369         vector<string>::iterator k;
370         vector<string>::iterator p;
371         vector<string>::iterator t;
372         vector<string>::iterator l;
373
374         available_action_model->clear ();
375
376         TreeIter rowp;
377         TreeModel::Row parent;
378
379         /* Disabled item (row 0) */
380
381         rowp = available_action_model->append();
382         parent = *(rowp);
383         parent[action_columns.name] = _("Disabled");
384
385         /* Key aliasing */
386
387         rowp = available_action_model->append();
388         parent = *(rowp);
389         parent[action_columns.name] = _("Shift");
390         rowp = available_action_model->append();
391         parent = *(rowp);
392         parent[action_columns.name] = _("Control");
393         rowp = available_action_model->append();
394         parent = *(rowp);
395         parent[action_columns.name] = _("Option");
396         rowp = available_action_model->append();
397         parent = *(rowp);
398         parent[action_columns.name] = _("CmdAlt");
399
400
401         for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
402
403                 TreeModel::Row row;
404                 vector<string> parts;
405
406                 parts.clear ();
407
408                 split (*p, parts, '/');
409
410                 if (parts.empty()) {
411                         continue;
412                 }
413
414                 //kinda kludgy way to avoid displaying menu items as mappable
415                 if ( parts[1] == _("Main_menu") )
416                         continue;
417                 if ( parts[1] == _("JACK") )
418                         continue;
419                 if ( parts[1] == _("redirectmenu") )
420                         continue;
421                 if ( parts[1] == _("Editor_menus") )
422                         continue;
423                 if ( parts[1] == _("RegionList") )
424                         continue;
425                 if ( parts[1] == _("ProcessorMenu") )
426                         continue;
427
428                 if ((r = nodes.find (parts[1])) == nodes.end()) {
429
430                         /* top level is missing */
431
432                         TreeIter rowp;
433                         TreeModel::Row parent;
434                         rowp = available_action_model->append();
435                         nodes[parts[1]] = rowp;
436                         parent = *(rowp);
437                         parent[action_columns.name] = parts[1];
438
439                         row = *(available_action_model->append (parent.children()));
440
441                 } else {
442
443                         row = *(available_action_model->append ((*r->second)->children()));
444
445                 }
446
447                 /* add this action */
448
449                 if (l->empty ()) {
450                         row[action_columns.name] = *t;
451                         action_map[*t] = *p;
452                 } else {
453                         row[action_columns.name] = *l;
454                         action_map[*l] = *p;
455                 }
456
457                 string path = (*p);
458                 /* ControlProtocol::access_action() is not interested in the
459                    legacy "<Actions>/" prefix part of a path.
460                 */
461                 path = path.substr (strlen ("<Actions>/"));
462
463                 row[action_columns.path] = path;
464         }
465 }
466
467 void
468 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
469 {
470         TreeModel::const_iterator row = cb->get_active ();
471         string action_path = (*row)[action_columns.path];
472
473         /* release binding */
474         fp.set_action (id, action_path, false, bs);
475 }
476
477 void
478 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
479 {
480         Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
481         TreeIter rowp;
482         TreeModel::Row row;
483         string current_action = fp.get_action (id, false, bs); /* lookup release action */
484         int active_row = -1;
485         int n;
486         vector<pair<string,string> >::const_iterator i;
487
488         rowp = model->append();
489         row = *(rowp);
490         row[action_columns.name] = _("Disabled");
491         row[action_columns.path] = string();
492
493         if (current_action.empty()) {
494                 active_row = 0;
495         }
496
497         for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
498                 rowp = model->append();
499                 row = *(rowp);
500                 row[action_columns.name] = i->first;
501                 row[action_columns.path] = i->second;
502                 if (current_action == i->second) {
503                         active_row = n+1;
504                 }
505         }
506
507         cb.set_model (model);
508         cb.pack_start (action_columns.name);
509
510         if (active_row >= 0) {
511                 cb.set_active (active_row);
512         }
513
514         cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
515 }
516
517 void
518 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
519 {
520         vector<pair<string,string> > actions;
521
522         actions.push_back (make_pair (string (_("Show Mixer Window")), string (X_("Window/show-mixer"))));
523         actions.push_back (make_pair (string (_("Show/Hide Mixer list")), string (X_("Common/ToggleMixerList"))));
524         actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
525         actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
526
527         build_action_combo (cb, actions, FaderPort::Mix, bs);
528 }
529
530 void
531 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
532 {
533         vector<pair<string,string> > actions;
534
535         actions.push_back (make_pair (string (_("Show Editor Window")), string (X_("Mixer/show-editor"))));
536         actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
537         actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
538         actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
539         actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
540
541 //      actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
542 //      actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
543
544         build_action_combo (cb, actions, FaderPort::Proj, bs);
545 }
546
547 void
548 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
549 {
550         vector<pair<string,string> > actions;
551
552         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
553         actions.push_back (make_pair (string("Toggle Locations window"), string(X_("Window/toggle-locations"))));
554         actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
555         actions.push_back (make_pair (string("Toggle External Sync"), string(X_("Transport/ToggleExternalSync"))));
556         actions.push_back (make_pair (string("Toggle Follow Playhead"), string(X_("Editor/toggle-follow-playhead"))));
557
558 //      actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
559
560
561         build_action_combo (cb, actions, FaderPort::Trns, bs);
562 }
563
564 void
565 FPGUI::build_foot_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
566 {
567         vector<pair<string,string> > actions;
568
569         actions.push_back (make_pair (string("Toggle Roll"), string(X_("Transport/ToggleRoll"))));
570         actions.push_back (make_pair (string("Toggle Rec-Enable"), string(X_("Transport/Record"))));
571         actions.push_back (make_pair (string("Toggle Roll+Rec"), string(X_("Transport/record-roll"))));
572         actions.push_back (make_pair (string("Toggle Loop"), string(X_("Transport/Loop"))));
573         actions.push_back (make_pair (string("Toggle Click"), string(X_("Transport/ToggleClick"))));
574         actions.push_back (make_pair (string("Record with Pre-Roll"), string(X_("Transport/RecordPreroll"))));
575         actions.push_back (make_pair (string("Record with Count-In"), string(X_("Transport/RecordCountIn"))));
576
577         build_action_combo (cb, actions, FaderPort::Footswitch, bs);
578 }
579
580 bool
581 FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
582 {
583         TreeModel::Row row = *iter;
584         string path = row[action_columns.path];
585
586         if (path == action_path) {
587                 *found = iter;
588                 return true;
589         }
590
591         return false;
592 }
593
594 void
595 FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
596 {
597         cb.set_model (available_action_model);
598         cb.pack_start (action_columns.name);
599         cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::User, bs));
600
601         /* set the active "row" to the right value for the current button binding */
602
603         string current_action = fp.get_action (FaderPort::User, false, bs); /* lookup release action */
604
605         if (current_action.empty()) {
606                 cb.set_active (0); /* "disabled" */
607                 return;
608         }
609
610         TreeModel::iterator iter = available_action_model->children().end();
611
612         available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
613
614         if (iter != available_action_model->children().end()) {
615                 cb.set_active (iter);
616         } else {
617                 cb.set_active (0);
618         }
619
620 }
621
622 Glib::RefPtr<Gtk::ListStore>
623 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
624 {
625         Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
626         TreeModel::Row row;
627
628         row = *store->append ();
629         row[midi_port_columns.full_name] = string();
630         row[midi_port_columns.short_name] = _("Disconnected");
631
632         for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
633                 row = *store->append ();
634                 row[midi_port_columns.full_name] = *p;
635                 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
636                 if (pn.empty ()) {
637                         pn = (*p).substr ((*p).find (':') + 1);
638                 }
639                 row[midi_port_columns.short_name] = pn;
640         }
641
642         return store;
643 }
644
645 void
646 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
647 {
648         if (ignore_active_change) {
649                 return;
650         }
651
652         TreeModel::iterator active = combo->get_active ();
653         string new_port = (*active)[midi_port_columns.full_name];
654
655         if (new_port.empty()) {
656                 if (for_input) {
657                         fp.input_port()->disconnect_all ();
658                 } else {
659                         fp.output_port()->disconnect_all ();
660                 }
661
662                 return;
663         }
664
665         if (for_input) {
666                 if (!fp.input_port()->connected_to (new_port)) {
667                         fp.input_port()->disconnect_all ();
668                         fp.input_port()->connect (new_port);
669                 }
670         } else {
671                 if (!fp.output_port()->connected_to (new_port)) {
672                         fp.output_port()->disconnect_all ();
673                         fp.output_port()->connect (new_port);
674                 }
675         }
676 }