84068551402d021cab30f905f160ed1ac240c939
[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/file_utils.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/unwind.h"
27
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"
33
34 #include "ardour/audioengine.h"
35 #include "ardour/filesystem_paths.h"
36
37 #include "faderport.h"
38 #include "gui.h"
39
40 #include "pbd/i18n.h"
41
42 using namespace PBD;
43 using namespace ARDOUR;
44 using namespace ArdourSurface;
45 using namespace std;
46 using namespace Gtk;
47 using namespace Gtkmm2ext;
48
49 void*
50 FaderPort::get_gui () const
51 {
52         if (!gui) {
53                 const_cast<FaderPort*>(this)->build_gui ();
54         }
55         static_cast<Gtk::VBox*>(gui)->show_all();
56         return gui;
57 }
58
59 void
60 FaderPort::tear_down_gui ()
61 {
62         if (gui) {
63                 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
64                 if (w) {
65                         w->hide();
66                         delete w;
67                 }
68         }
69         delete static_cast<FPGUI*> (gui);
70         gui = 0;
71 }
72
73 void
74 FaderPort::build_gui ()
75 {
76         gui = (void*) new FPGUI (*this);
77 }
78
79 /*--------------------*/
80
81 FPGUI::FPGUI (FaderPort& p)
82         : fp (p)
83         , table (2, 5)
84         , action_table (5, 4)
85         , ignore_active_change (false)
86 {
87         set_border_width (12);
88
89         table.set_row_spacings (4);
90         table.set_col_spacings (6);
91         table.set_border_width (12);
92         table.set_homogeneous (false);
93
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);
102         }
103
104         Gtk::Label* l;
105         Gtk::Alignment* align;
106         int row = 0;
107
108         input_combo.pack_start (midi_port_columns.short_name);
109         output_combo.pack_start (midi_port_columns.short_name);
110
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));
113
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);
119         row++;
120
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);
126         row++;
127
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);
131
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);
135
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);
139
140         build_available_action_menu ();
141
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);
145
146         /* No shift-press combo for User because that is labelled as "next"
147          * (marker)
148          */
149
150         build_user_action_combo (user_combo[0], FaderPort::ButtonState(0));
151         build_user_action_combo (user_combo[1], FaderPort::LongPress);
152
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);
157
158         int action_row = 0;
159
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));
172         action_row++;
173
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));
190         action_row++;
191
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));
208         action_row++;
209
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));
226         action_row++;
227
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));
241         action_row++;
242
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));
259         action_row++;
260
261         table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
262         row++;
263
264         hpacker.pack_start (table, true, true);
265         pack_start (hpacker, false, false);
266
267         /* update the port connection combos */
268
269         update_port_combos ();
270
271         /* catch future changes to connection state */
272
273         fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
274 }
275
276 FPGUI::~FPGUI ()
277 {
278 }
279
280 void
281 FPGUI::connection_handler ()
282 {
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.
286         */
287
288         PBD::Unwinder<bool> ici (ignore_active_change, true);
289
290         update_port_combos ();
291 }
292
293 void
294 FPGUI::update_port_combos ()
295 {
296         vector<string> midi_inputs;
297         vector<string> midi_outputs;
298
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);
301
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;
306         int n;
307
308         input_combo.set_model (input);
309         output_combo.set_model (output);
310
311         Gtk::TreeModel::Children children = input->children();
312         Gtk::TreeModel::Children::iterator i;
313         i = children.begin();
314         ++i; /* skip "Disconnected" */
315
316
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);
321                         input_found = true;
322                         break;
323                 }
324         }
325
326         if (!input_found) {
327                 input_combo.set_active (0); /* disconnected */
328         }
329
330         children = output->children();
331         i = children.begin();
332         ++i; /* skip "Disconnected" */
333
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);
338                         output_found = true;
339                         break;
340                 }
341         }
342
343         if (!output_found) {
344                 output_combo.set_active (0); /* disconnected */
345         }
346 }
347
348 void
349 FPGUI::build_available_action_menu ()
350 {
351         /* build a model of all available actions (needs to be tree structured
352          * more)
353          */
354
355         available_action_model = TreeStore::create (action_columns);
356
357         vector<string> paths;
358         vector<string> labels;
359         vector<string> tooltips;
360         vector<string> keys;
361         vector<Glib::RefPtr<Gtk::Action> > actions;
362
363         ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
364
365         typedef std::map<string,TreeIter> NodeMap;
366         NodeMap nodes;
367         NodeMap::iterator r;
368
369
370         vector<string>::iterator k;
371         vector<string>::iterator p;
372         vector<string>::iterator t;
373         vector<string>::iterator l;
374
375         available_action_model->clear ();
376
377         TreeIter rowp;
378         TreeModel::Row parent;
379
380         /* Disabled item (row 0) */
381
382         rowp = available_action_model->append();
383         parent = *(rowp);
384         parent[action_columns.name] = _("Disabled");
385
386         /* Key aliasing */
387
388         rowp = available_action_model->append();
389         parent = *(rowp);
390         parent[action_columns.name] = _("Shift");
391         rowp = available_action_model->append();
392         parent = *(rowp);
393         parent[action_columns.name] = _("Control");
394         rowp = available_action_model->append();
395         parent = *(rowp);
396         parent[action_columns.name] = _("Option");
397         rowp = available_action_model->append();
398         parent = *(rowp);
399         parent[action_columns.name] = _("CmdAlt");
400
401
402         for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
403
404                 TreeModel::Row row;
405                 vector<string> parts;
406
407                 parts.clear ();
408
409                 split (*p, parts, '/');
410
411                 if (parts.empty()) {
412                         continue;
413                 }
414
415                 //kinda kludgy way to avoid displaying menu items as mappable
416                 if (parts[0] == _("Main Menu") )
417                         continue;
418                 if (parts[0] == _("JACK") )
419                         continue;
420                 if (parts[0] == _("redirectmenu") )
421                         continue;
422                 if (parts[0] == _("RegionList") )
423                         continue;
424                 if (parts[0] == _("ProcessorMenu") )
425                         continue;
426
427                 if ((r = nodes.find (parts[0])) == nodes.end()) {
428
429                         /* top level is missing */
430
431                         TreeIter rowp;
432                         TreeModel::Row parent;
433                         rowp = available_action_model->append();
434                         nodes[parts[0]] = rowp;
435                         parent = *(rowp);
436                         parent[action_columns.name] = parts[0];
437
438                         row = *(available_action_model->append (parent.children()));
439
440                 } else {
441
442                         row = *(available_action_model->append ((*r->second)->children()));
443
444                 }
445
446                 /* add this action */
447
448                 if (l->empty ()) {
449                         row[action_columns.name] = *t;
450                         action_map[*t] = *p;
451                 } else {
452                         row[action_columns.name] = *l;
453                         action_map[*l] = *p;
454                 }
455
456                 row[action_columns.path] = *p;
457         }
458 }
459
460 void
461 FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
462 {
463         TreeModel::const_iterator row = cb->get_active ();
464         string action_path = (*row)[action_columns.path];
465
466         /* release binding */
467         fp.set_action (id, action_path, false, bs);
468 }
469
470 void
471 FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
472 {
473         Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
474         TreeIter rowp;
475         TreeModel::Row row;
476         string current_action = fp.get_action (id, false, bs); /* lookup release action */
477         int active_row = -1;
478         int n;
479         vector<pair<string,string> >::const_iterator i;
480
481         rowp = model->append();
482         row = *(rowp);
483         row[action_columns.name] = _("Disabled");
484         row[action_columns.path] = string();
485
486         if (current_action.empty()) {
487                 active_row = 0;
488         }
489
490         for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
491                 rowp = model->append();
492                 row = *(rowp);
493                 row[action_columns.name] = i->first;
494                 row[action_columns.path] = i->second;
495                 if (current_action == i->second) {
496                         active_row = n+1;
497                 }
498         }
499
500         cb.set_model (model);
501         cb.pack_start (action_columns.name);
502
503         if (active_row >= 0) {
504                 cb.set_active (active_row);
505         }
506
507         cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
508 }
509
510 void
511 FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
512 {
513         vector<pair<string,string> > actions;
514
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"))));
519
520         build_action_combo (cb, actions, FaderPort::Mix, bs);
521 }
522
523 void
524 FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
525 {
526         vector<pair<string,string> > actions;
527
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"))));
533
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"))));
536
537         build_action_combo (cb, actions, FaderPort::Proj, bs);
538 }
539
540 void
541 FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
542 {
543         vector<pair<string,string> > actions;
544
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"))));
550
551 //      actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
552
553
554         build_action_combo (cb, actions, FaderPort::Trns, bs);
555 }
556
557 void
558 FPGUI::build_foot_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
559 {
560         vector<pair<string,string> > actions;
561
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"))));
569
570         build_action_combo (cb, actions, FaderPort::Footswitch, bs);
571 }
572
573 bool
574 FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
575 {
576         TreeModel::Row row = *iter;
577         string path = row[action_columns.path];
578
579         if (path == action_path) {
580                 *found = iter;
581                 return true;
582         }
583
584         return false;
585 }
586
587 void
588 FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
589 {
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));
593
594         /* set the active "row" to the right value for the current button binding */
595
596         string current_action = fp.get_action (FaderPort::User, false, bs); /* lookup release action */
597
598         if (current_action.empty()) {
599                 cb.set_active (0); /* "disabled" */
600                 return;
601         }
602
603         TreeModel::iterator iter = available_action_model->children().end();
604
605         available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
606
607         if (iter != available_action_model->children().end()) {
608                 cb.set_active (iter);
609         } else {
610                 cb.set_active (0);
611         }
612
613 }
614
615 Glib::RefPtr<Gtk::ListStore>
616 FPGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
617 {
618         Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
619         TreeModel::Row row;
620
621         row = *store->append ();
622         row[midi_port_columns.full_name] = string();
623         row[midi_port_columns.short_name] = _("Disconnected");
624
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);
629                 if (pn.empty ()) {
630                         pn = (*p).substr ((*p).find (':') + 1);
631                 }
632                 row[midi_port_columns.short_name] = pn;
633         }
634
635         return store;
636 }
637
638 void
639 FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
640 {
641         if (ignore_active_change) {
642                 return;
643         }
644
645         TreeModel::iterator active = combo->get_active ();
646         string new_port = (*active)[midi_port_columns.full_name];
647
648         if (new_port.empty()) {
649                 if (for_input) {
650                         fp.input_port()->disconnect_all ();
651                 } else {
652                         fp.output_port()->disconnect_all ();
653                 }
654
655                 return;
656         }
657
658         if (for_input) {
659                 if (!fp.input_port()->connected_to (new_port)) {
660                         fp.input_port()->disconnect_all ();
661                         fp.input_port()->connect (new_port);
662                 }
663         } else {
664                 if (!fp.output_port()->connected_to (new_port)) {
665                         fp.output_port()->disconnect_all ();
666                         fp.output_port()->connect (new_port);
667                 }
668         }
669 }