next region list fix from chris g; more tweaks to port matrix/ioselector; remove...
[ardour.git] / gtk2_ardour / port_matrix.cc
1 /*
2     Copyright (C) 2002-2007 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/label.h>
21 #include <gtkmm/enums.h>
22 #include <gtkmm/image.h>
23 #include <gtkmm/stock.h>
24 #include <gtkmm/messagedialog.h>
25 #include <gtkmm/menu.h>
26 #include <gtkmm/menu_elems.h>
27 #include <gtkmm/menuitem.h>
28 #include <gtkmm/menushell.h>
29 #include <glibmm/objectbase.h>
30 #include <gtkmm2ext/doi.h>
31 #include <ardour/port_insert.h>
32 #include "ardour/session.h"
33 #include "ardour/io.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/track.h"
36 #include "ardour/audio_track.h"
37 #include "ardour/midi_track.h"
38 #include "ardour/data_type.h"
39 #include "io_selector.h"
40 #include "utils.h"
41 #include "gui_thread.h"
42 #include "i18n.h"
43
44 using namespace Gtk;
45
46 /** Add a port to a group.
47  *  @param p Port name, with or without prefix.
48  */
49
50 void
51 PortGroup::add (std::string const & p)
52 {
53         if (prefix.empty() == false && p.substr (0, prefix.length()) == prefix) {
54                 ports.push_back (p.substr (prefix.length()));
55         } else {
56                 ports.push_back (p);
57         }
58 }
59
60 /** PortGroupUI constructor.
61  *  @param m PortMatrix to work for.
62  *  @Param g PortGroup to represent.
63  */
64
65 PortGroupUI::PortGroupUI (PortMatrix& m, PortGroup& g)
66         : _port_matrix (m), _port_group (g), _ignore_check_button_toggle (false),
67           _visibility_checkbutton (g.name)
68 {
69         int const ports = _port_group.ports.size();
70         int const rows = _port_matrix.n_rows ();
71
72         if (rows == 0 || ports == 0) {
73                 return;
74         }
75
76         /* Sort out the table and the checkbuttons inside it */
77         
78         _table.resize (rows, ports);
79         _port_checkbuttons.resize (rows);
80         for (int i = 0; i < rows; ++i) {
81                 _port_checkbuttons[i].resize (ports);
82         }
83
84         for (int i = 0; i < rows; ++i) {
85                 for (uint32_t j = 0; j < _port_group.ports.size(); ++j) {
86                         CheckButton* b = new CheckButton;
87                         
88                         b->signal_toggled().connect (
89                                 sigc::bind (sigc::mem_fun (*this, &PortGroupUI::port_checkbutton_toggled), b, i, j)
90                                 );
91                         
92                         _port_checkbuttons[i][j] = b;
93                         _table.attach (*b, j, j + 1, i, i + 1);
94                 }
95         }
96         
97         _table_box.add (_table);
98
99         _ignore_check_button_toggle = true;
100
101         /* Set the state of the check boxes according to current connections */
102         for (int i = 0; i < rows; ++i) {
103                 for (uint32_t j = 0; j < _port_group.ports.size(); ++j) {
104                         std::string const t = _port_group.prefix + _port_group.ports[j];
105                         bool const s = _port_matrix.get_state (i, t);
106                         _port_checkbuttons[i][j]->set_active (s);
107                         if (s) {
108                                 _port_group.visible = true;
109                         }
110                 }
111         }
112
113         _ignore_check_button_toggle = false;
114
115         _visibility_checkbutton.signal_toggled().connect (sigc::mem_fun (*this, &PortGroupUI::visibility_checkbutton_toggled));
116 }
117
118 /** The visibility of a PortGroupUI has been toggled */
119 void
120 PortGroupUI::visibility_checkbutton_toggled ()
121 {
122         _port_group.visible = _visibility_checkbutton.get_active ();
123 }
124
125 /** @return Width and height of a single checkbutton in a port group table */
126 std::pair<int, int>
127 PortGroupUI::unit_size () const
128 {
129         if (_port_checkbuttons.empty() || _port_checkbuttons[0].empty())
130         {
131                 return std::pair<int, int> (0, 0);
132         }
133
134         int r = 0;
135         /* We can't ask for row spacing unless there >1 rows, otherwise we get a warning */
136         if (_table.property_n_rows() > 1) {
137                 r = _table.get_row_spacing (0);
138         }
139
140         return std::make_pair (
141                 _port_checkbuttons[0][0]->get_width() + _table.get_col_spacing (0),
142                 _port_checkbuttons[0][0]->get_height() + r
143                 );
144 }
145
146 /** @return Table widget containing the port checkbuttons */
147 Widget&
148 PortGroupUI::get_table ()
149 {
150         return _table_box;
151 }
152
153 /** @return Checkbutton used to toggle visibility */
154 Widget&
155 PortGroupUI::get_visibility_checkbutton ()
156 {
157         return _visibility_checkbutton;
158 }
159
160
161 /** Handle a toggle of a port check button */
162 void
163 PortGroupUI::port_checkbutton_toggled (CheckButton* b, int r, int c)
164 {
165         if (_ignore_check_button_toggle == false) {
166                 _port_matrix.set_state (r, _port_group.prefix + _port_group.ports[c], b->get_active());
167         }
168 }
169
170 /** Set up visibility of the port group according to PortGroup::visible */
171 void
172 PortGroupUI::setup_visibility ()
173 {
174         if (!_port_group.ports.empty() && _port_group.visible) {
175                 _table_box.show ();
176         } else {
177                 _table_box.hide ();
178         }
179
180         if (_visibility_checkbutton.get_active () != _port_group.visible) {
181
182                 _visibility_checkbutton.set_active (_port_group.visible);
183         }
184 }
185
186 RotatedLabelSet::RotatedLabelSet (PortGroupList& g)
187         : Glib::ObjectBase ("RotatedLabelSet"), Widget (), _port_group_list (g), _base_width (128)
188 {
189         set_flags (NO_WINDOW);
190         set_angle (30);
191 }
192
193 RotatedLabelSet::~RotatedLabelSet ()
194 {
195         
196 }
197
198
199 /** Set the angle that the labels are drawn at.
200  * @param degrees New angle in degrees.
201  */
202
203 void
204 RotatedLabelSet::set_angle (int degrees)
205 {
206         _angle_degrees = degrees;
207         _angle_radians = M_PI * _angle_degrees / 180;
208
209         queue_resize ();
210 }
211
212 void
213 RotatedLabelSet::on_size_request (Requisition* requisition)
214 {
215         *requisition = Requisition ();
216
217         if (_pango_layout == 0) {
218                 return;
219         }
220
221         /* Our height is the highest label */
222         requisition->height = 0;
223         for (PortGroupList::const_iterator i = _port_group_list.begin(); i != _port_group_list.end(); ++i) {
224                 for (std::vector<std::string>::const_iterator j = (*i)->ports.begin(); j != (*i)->ports.end(); ++j) {
225                         std::pair<int, int> const d = setup_layout (*j);
226                         if (d.second > requisition->height) {
227                                 requisition->height = d.second;
228                         }
229                 }
230         }
231
232         /* And our width is the base plus the width of the last label */
233         requisition->width = _base_width;
234         int const n = _port_group_list.n_visible_ports ();
235         if (n > 0) {
236                 std::pair<int, int> const d = setup_layout (_port_group_list.get_port_by_index (n - 1, false));
237                 requisition->width += d.first;
238         }
239 }
240
241 void
242 RotatedLabelSet::on_size_allocate (Allocation& allocation)
243 {
244         set_allocation (allocation);
245
246         if (_gdk_window) {
247                 _gdk_window->move_resize (
248                         allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height()
249                         );
250         }
251 }
252
253 void
254 RotatedLabelSet::on_realize ()
255 {
256         Widget::on_realize ();
257
258         Glib::RefPtr<Style> style = get_style ();
259
260         if (!_gdk_window) {
261                 GdkWindowAttr attributes;
262                 memset (&attributes, 0, sizeof (attributes));
263
264                 Allocation allocation = get_allocation ();
265                 attributes.x = allocation.get_x ();
266                 attributes.y = allocation.get_y ();
267                 attributes.width = allocation.get_width ();
268                 attributes.height = allocation.get_height ();
269
270                 attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK; 
271                 attributes.window_type = GDK_WINDOW_CHILD;
272                 attributes.wclass = GDK_INPUT_OUTPUT;
273
274                 _gdk_window = Gdk::Window::create (get_window (), &attributes, GDK_WA_X | GDK_WA_Y);
275                 unset_flags (NO_WINDOW);
276                 set_window (_gdk_window);
277
278                 _bg_colour = style->get_bg (STATE_NORMAL );
279                 modify_bg (STATE_NORMAL, _bg_colour);
280                 _fg_colour = style->get_fg (STATE_NORMAL);
281
282                 _gdk_window->set_user_data (gobj ());
283
284                 /* Set up Pango stuff */
285                 _pango_context = create_pango_context ();
286
287                 Pango::Matrix matrix = PANGO_MATRIX_INIT;
288                 pango_matrix_rotate (&matrix, _angle_degrees);
289                 _pango_context->set_matrix (matrix);
290
291                 _pango_layout = Pango::Layout::create (_pango_context);
292                 _gc = Gdk::GC::create (get_window ());
293         }
294 }
295
296 void
297 RotatedLabelSet::on_unrealize()
298 {
299         _gdk_window.clear ();
300
301         Widget::on_unrealize ();
302 }
303
304
305 /** Set up our Pango layout to plot a given string, and compute its dimensions once
306  *  it has been rotated.
307  *  @param s String to use.
308  *  @return width and height of the rotated string, in pixels.
309  */
310
311 std::pair<int, int>
312 RotatedLabelSet::setup_layout (std::string const & s)
313 {
314         _pango_layout->set_text (s);
315
316         /* Here's the unrotated size */
317         int w;
318         int h;
319         _pango_layout->get_pixel_size (w, h);
320
321         /* Rotate the width and height as appropriate.  I thought Pango might be able
322            to do this for us, but I can't find out how... */
323         std::pair<int, int> d;
324         d.first = int (w * cos (_angle_radians) - h * sin (_angle_radians));
325         d.second = int (w * sin (_angle_radians) + h * cos (_angle_radians));
326
327         return d;
328 }
329
330 bool
331 RotatedLabelSet::on_expose_event (GdkEventExpose* event)
332 {
333         if (!_gdk_window) {
334                 return true;
335         }
336
337         int const height = get_allocation().get_height ();
338         double const spacing = double (_base_width) / _port_group_list.n_visible_ports();
339
340         /* Plot all the visible labels; really we should clip for efficiency */
341         int n = 0;
342         for (PortGroupList::const_iterator i = _port_group_list.begin(); i != _port_group_list.end(); ++i) {
343                 if ((*i)->visible) {
344                         for (uint32_t j = 0; j < (*i)->ports.size(); ++j) {
345                                 std::pair<int, int> const d = setup_layout ((*i)->ports[j]);
346                                 get_window()->draw_layout (_gc, int ((n + 0.25) * spacing), height - d.second, _pango_layout, _fg_colour, _bg_colour);
347                                 ++n;
348                         }
349                 }
350         }
351
352         return true;
353 }
354
355 /** Set the `base width'.  This is the width of the base of the label set, ie:
356  *
357  *     L L L L
358  *    E E E E
359  *   B B B B
360  *  A A A A
361  * L L L L
362  * <--w-->
363  */
364     
365 void
366 RotatedLabelSet::set_base_width (int w)
367 {
368         _base_width = w;
369         queue_resize ();
370 }
371
372
373 PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type, bool offer_inputs, PortGroupList::Mask mask)
374         : _offer_inputs (offer_inputs), _port_group_list (session, type, offer_inputs, mask), _type (type),
375           _column_labels (_port_group_list)
376 {
377         _row_labels_vbox = 0;
378         _side_vbox_pad = 0;
379
380         _visibility_checkbutton_box.pack_start (*(manage (new Label (_("Connections displayed: ")))), false, false, 10);
381         pack_start (_visibility_checkbutton_box, false, false);
382         
383         _side_vbox.pack_start (*manage (new Label ("")));
384         _scrolled_window.set_policy (POLICY_ALWAYS, POLICY_AUTOMATIC);
385         _scrolled_window.set_shadow_type (SHADOW_NONE);
386         VBox* b = manage (new VBox);
387         b->pack_start (_column_labels, false, false);
388         b->pack_start (_port_group_hbox, false, false);
389         Alignment* a = manage (new Alignment (0, 1, 0, 0));
390         a->add (*b);
391         _scrolled_window.add (*a);
392
393         if (offer_inputs) {
394                 _overall_hbox.pack_start (_side_vbox, false, false, 10);
395                 _overall_hbox.pack_start (_scrolled_window, true, true);
396         } else {
397                 _overall_hbox.pack_start (_scrolled_window, true, true, 10);
398                 _overall_hbox.pack_start (_side_vbox, false, false);
399         }
400
401         pack_start (_overall_hbox);
402
403         _port_group_hbox.signal_size_allocate().connect (sigc::hide (sigc::mem_fun (*this, &IOSelector::setup_dimensions)));
404 }
405
406 PortMatrix::~PortMatrix ()
407 {
408         clear ();
409 }
410
411 /** Clear out the things that change when the number of source or destination ports changes */
412 void
413 PortMatrix::clear ()
414 {
415         for (std::vector<EventBox*>::iterator j = _row_labels.begin(); j != _row_labels.end(); ++j) {
416                 delete *j;
417         }
418         _row_labels.clear ();
419                 
420         if (_row_labels_vbox) {
421                 _side_vbox.remove (*_row_labels_vbox);
422         }
423         delete _row_labels_vbox;
424         _row_labels_vbox = 0;
425         
426         if (_side_vbox_pad) {
427                 _side_vbox.remove (*_side_vbox_pad);
428         }
429         delete _side_vbox_pad;
430         _side_vbox_pad = 0;
431
432         for (std::vector<PortGroupUI*>::iterator i = _port_group_ui.begin(); i != _port_group_ui.end(); ++i) {
433                 _port_group_hbox.remove ((*i)->get_table());
434                 _visibility_checkbutton_box.remove ((*i)->get_visibility_checkbutton());
435                 delete *i;
436         }
437
438         _port_group_ui.clear ();
439 }
440
441
442 /** Set up dimensions of some of our widgets which depend on other dimensions
443  *  within the dialogue.
444  */
445 void
446 PortMatrix::setup_dimensions ()
447 {
448         /* Get some dimensions from various places */
449         int const scrollbar_height = _scrolled_window.get_hscrollbar()->get_height();
450
451         std::pair<int, int> unit_size (0, 0);
452         int port_group_tables_height = 0;
453         for (std::vector<PortGroupUI*>::iterator i = _port_group_ui.begin(); i != _port_group_ui.end(); ++i) {
454                 std::pair<int, int> const u = (*i)->unit_size ();
455                 unit_size.first = std::max (unit_size.first, u.first);
456                 unit_size.second = std::max (unit_size.second, u.second);
457                 port_group_tables_height = std::max (
458                         port_group_tables_height, (*i)->get_table().get_height()
459                         );
460         }
461
462         /* Column labels */
463         _column_labels.set_base_width (_port_group_list.n_visible_ports () * unit_size.first);
464
465         /* Scrolled window */
466         /* XXX: really shouldn't set a minimum horizontal size here, but if we don't
467            the window starts up very small.
468            The constant value in the set_size_request() computation will control
469            how big the scrolled window will be if we fill the port matrix will a gajillion
470            ports.
471         */
472
473         _scrolled_window.set_size_request (
474                 std::min (_column_labels.get_width(), 400),
475                 _column_labels.get_height() + port_group_tables_height + scrollbar_height + 16
476                 );
477         
478         /* Row labels */
479         for (std::vector<EventBox*>::iterator j = _row_labels.begin(); j != _row_labels.end(); ++j) {
480                 (*j)->get_child()->set_size_request (-1, unit_size.second);
481         }
482         
483         if (_side_vbox_pad) {
484                 _side_vbox_pad->set_size_request (-1, scrollbar_height + unit_size.second / 4);
485         }
486 }
487
488
489 /** Set up the dialogue */
490 void
491 PortMatrix::setup ()
492 {
493         clear ();
494
495         int const rows = n_rows ();
496         
497         /* Row labels */
498
499         _row_labels_vbox = new VBox;
500         int const run_rows = std::max (1, rows);
501
502         for (int j = 0; j < run_rows; ++j) {
503                 
504                 /* embolden the port/channel name */
505                 
506                 string s = "<b>";
507                 s += row_name (j);
508                 s += "</b>";
509                 
510                 Label* label = manage (new Label (s));
511                 EventBox* b = manage (new EventBox);
512                 
513                 label->set_use_markup (true);
514                 
515                 b->set_events (Gdk::BUTTON_PRESS_MASK);
516                 b->signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &IOSelector::row_label_button_pressed), j));
517                 b->add (*label);
518                 
519                 _row_labels.push_back (b);
520                 _row_labels_vbox->pack_start (*b, false, false);
521         }
522
523         _side_vbox.pack_start (*_row_labels_vbox, false, false);
524         _side_vbox_pad = new Label ("");
525         _side_vbox.pack_start (*_side_vbox_pad, false, false);
526
527         /* Checkbutton tables and visibility checkbuttons */
528         for (PortGroupList::iterator i = _port_group_list.begin(); i != _port_group_list.end(); ++i) {
529
530                 PortGroupUI* t = new PortGroupUI (*this, **i);
531                 
532                 _port_group_ui.push_back (t);
533                 _port_group_hbox.pack_start (t->get_table(), false, false);
534                 
535                 _visibility_checkbutton_box.pack_start (t->get_visibility_checkbutton(), false, false);
536
537                 CheckButton* chk = dynamic_cast<CheckButton*>(&t->get_visibility_checkbutton());
538                 if (chk) { 
539                         chk->signal_toggled().connect (sigc::mem_fun (*this, &PortMatrix::reset_visibility));
540                 }
541         }
542
543         show_all ();
544
545         reset_visibility ();
546 }
547
548 void
549 PortMatrix::reset_visibility ()
550 {
551         /* now adjust visibility and coloring */
552
553         bool even = true;
554         Gdk::Color odd_bg (color_from_style ("OddPortGroups", STATE_NORMAL, "fg"));
555         Gdk::Color even_bg (color_from_style ("EvenPortGroups", STATE_NORMAL, "fg"));
556
557         for (std::vector<PortGroupUI*>::iterator i = _port_group_ui.begin(); i != _port_group_ui.end(); ++i) {
558
559                 (*i)->setup_visibility ();
560                 
561                 if ((*i)->port_group().visible) {
562                         if (even) {
563                                 (*i)->get_table().modify_bg (STATE_NORMAL, even_bg);
564                         } else {
565                                 (*i)->get_table().modify_bg (STATE_NORMAL, odd_bg);
566                         }
567                         even = !even;
568                 }
569         }
570 }
571
572 void
573 PortMatrix::redisplay ()
574 {
575         _port_group_list.refresh ();
576         setup ();
577 }
578
579
580 /** Handle a button press on a row label */
581 bool
582 PortMatrix::row_label_button_pressed (GdkEventButton* e, int r)
583 {
584         if (e->type != GDK_BUTTON_PRESS || e->button != 3) {
585                 return false;
586         }
587
588         Menu* menu = manage (new Menu);
589         Menu_Helpers::MenuList& items = menu->items ();
590         menu->set_name ("ArdourContextMenu");
591
592         bool const can_add = maximum_rows () > n_rows ();
593         bool const can_remove = minimum_rows () < n_rows ();
594         std::string const name = row_name (r);
595         
596         items.push_back (
597                 Menu_Helpers::MenuElem (string_compose(_("Add %1"), row_descriptor()), sigc::mem_fun (*this, &PortMatrix::add_row))
598                 );
599
600         items.back().set_sensitive (can_add);
601
602         items.push_back (
603                 Menu_Helpers::MenuElem (string_compose(_("Remove %1 \"%2\""), row_descriptor(), name), sigc::bind (sigc::mem_fun (*this, &PortMatrix::remove_row), r))
604                 );
605
606         items.back().set_sensitive (can_remove);
607
608         menu->popup (e->button, e->time);
609         
610         return true;
611 }
612
613 void
614 PortMatrix::set_type (ARDOUR::DataType t)
615 {
616         _type = t;
617         _port_group_list.set_type (t);
618         redisplay ();
619 }
620
621 void
622 PortMatrix::set_offer_inputs (bool i)
623 {
624         _offer_inputs = i;
625         _port_group_list.set_offer_inputs (i);
626         redisplay ();
627 }
628
629 /** PortGroupList constructor.
630  *  @param session Session to get ports from.
631  *  @param type Type of ports to offer (audio or MIDI)
632  *  @param offer_inputs true to offer output ports, otherwise false.
633  *  @param mask Mask of groups to make visible by default.
634  */
635
636 PortGroupList::PortGroupList (ARDOUR::Session & session, ARDOUR::DataType type, bool offer_inputs, Mask mask)
637         : _session (session), _type (type), _offer_inputs (offer_inputs),
638           buss (_("Bus"), "ardour:", mask & BUSS),
639           track (_("Track"), "ardour:", mask & TRACK),
640           system (_("System"), "system:", mask & SYSTEM),
641           other (_("Other"), "", mask & OTHER)
642 {
643         refresh ();
644 }
645
646 void
647 PortGroupList::refresh ()
648 {
649         clear ();
650         
651         buss.ports.clear ();
652         track.ports.clear ();
653         system.ports.clear ();
654         other.ports.clear ();
655
656         /* Find the ports provided by ardour; we can't derive their type just from their
657            names, so we'll have to be more devious. 
658         */
659
660         boost::shared_ptr<ARDOUR::Session::RouteList> routes = _session.get_routes ();
661
662         for (ARDOUR::Session::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
663
664                 PortGroup* g = 0;
665
666                 if (_type == ARDOUR::DataType::AUDIO) {
667
668                         if (boost::dynamic_pointer_cast<ARDOUR::AudioTrack> (*i)) {
669                                 g = &track;
670                         } else if (!boost::dynamic_pointer_cast<ARDOUR::MidiTrack>(*i)) {
671                                 g = &buss;
672                         } 
673
674
675                 } else if (_type == ARDOUR::DataType::MIDI) {
676
677                         if (boost::dynamic_pointer_cast<ARDOUR::MidiTrack> (*i)) {
678                                 g = &track;
679                         }
680
681                         /* No MIDI busses yet */
682                 } 
683                         
684                 if (g) {
685                         ARDOUR::PortSet const & p = _offer_inputs ? ((*i)->inputs()) : ((*i)->outputs());
686                         for (uint32_t j = 0; j < p.num_ports(); ++j) {
687                                 g->add (p.port(j)->name ());
688                         }
689
690                         std::sort (g->ports.begin(), g->ports.end());
691                 }
692         }
693         
694         /* XXX: inserts, sends, plugin inserts? */
695         
696         /* Now we need to find the non-ardour ports; we do this by first
697            finding all the ports that we can connect to. 
698         */
699
700         const char **ports = _session.engine().get_ports ("", _type.to_jack_type(), _offer_inputs ? 
701                                                           JackPortIsInput : JackPortIsOutput);
702         if (ports) {
703
704                 int n = 0;
705                 string client_matching_string;
706
707                 client_matching_string = _session.engine().client_name();
708                 client_matching_string += ':';
709
710                 while (ports[n]) {
711                         std::string const p = ports[n];
712
713                         if (p.substr(0, strlen ("system:")) == "system:") {
714                                 /* system: prefix */
715                                 system.add (p);
716                         } else {
717                                 if (p.substr(0, client_matching_string.length()) != client_matching_string) {
718                                         /* other (non-ardour) prefix */
719                                         other.add (p);
720                                 }
721                         }
722
723                         ++n;
724                 }
725
726                 free (ports);
727         }
728
729         push_back (&system);
730         push_back (&buss);
731         push_back (&track);
732         push_back (&other);
733 }
734
735 int
736 PortGroupList::n_visible_ports () const
737 {
738         int n = 0;
739         
740         for (const_iterator i = begin(); i != end(); ++i) {
741                 if ((*i)->visible) {
742                         n += (*i)->ports.size();
743                 }
744         }
745
746         return n;
747 }
748
749 std::string
750 PortGroupList::get_port_by_index (int n, bool with_prefix) const
751 {
752         /* XXX: slightly inefficient algorithm */
753
754         for (const_iterator i = begin(); i != end(); ++i) {
755                 for (std::vector<std::string>::const_iterator j = (*i)->ports.begin(); j != (*i)->ports.end(); ++j) {
756                         if (n == 0) {
757                                 if (with_prefix) {
758                                         return (*i)->prefix + *j;
759                                 } else {
760                                         return *j;
761                                 }
762                         }
763                         --n;
764                 }
765         }
766
767         return "";
768 }
769
770 void
771 PortGroupList::set_type (ARDOUR::DataType t)
772 {
773         _type = t;
774 }
775
776 void
777 PortGroupList::set_offer_inputs (bool i)
778 {
779         _offer_inputs = i;
780 }
781