From 66760a574a1fc0ccc8a798c2900a717c134838ea Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 29 Jul 2010 19:25:26 +0000 Subject: Don't display empty tabs in the port matrix. git-svn-id: svn://localhost/ardour2/branches/3.0@7521 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/port_group.cc | 85 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 15 deletions(-) (limited to 'gtk2_ardour/port_group.cc') diff --git a/gtk2_ardour/port_group.cc b/gtk2_ardour/port_group.cc index 0af3c24ed9..1382826b90 100644 --- a/gtk2_ardour/port_group.cc +++ b/gtk2_ardour/port_group.cc @@ -311,8 +311,8 @@ public: } }; -/** Gather bundles from around the system and put them in this PortGroupList. - * @param type Type of bundles to collect, or NIL for all types. +/** Gather ports from around the system and put them in this PortGroupList. + * @param type Type of ports to collect, or NIL for all types. */ void PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inputs, bool allow_dups) @@ -356,7 +356,11 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp /* Sort RouteIOs by the routes' editor order keys */ route_ios.sort (RouteIOsComparator ()); - /* Now put the bundles that belong to these sorted RouteIOs into the PortGroup */ + /* Now put the bundles that belong to these sorted RouteIOs into the PortGroup. + Note that if the RouteIO's bundles are multi-type, we may make new Bundles + with only the ports of one type. + */ + for (list::iterator i = route_ios.begin(); i != route_ios.end(); ++i) { TimeAxisView* tv = PublicEditor::instance().axis_view_from_route (i->route); @@ -367,12 +371,15 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp } else { g = bus; } - + for (list >::iterator j = i->ios.begin(); j != i->ios.end(); ++j) { - if (tv) { - g->add_bundle ((*j)->bundle(), *j, tv->color ()); - } else { - g->add_bundle ((*j)->bundle(), *j); + boost::shared_ptr b = bundle_for_type ((*j)->bundle(), type); + if (b) { + if (tv) { + g->add_bundle (b, *j, tv->color ()); + } else { + g->add_bundle (b, *j); + } } } } @@ -385,21 +392,34 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp for (BundleList::iterator i = b->begin(); i != b->end(); ++i) { if (boost::dynamic_pointer_cast (*i) && (*i)->ports_are_inputs() == inputs) { - system->add_bundle (*i, allow_dups); + boost::shared_ptr b = bundle_for_type (*i, type); + if (b) { + system->add_bundle (b, allow_dups); + } } } for (BundleList::iterator i = b->begin(); i != b->end(); ++i) { if (boost::dynamic_pointer_cast (*i) == 0 && (*i)->ports_are_inputs() == inputs) { - system->add_bundle (*i, allow_dups); + boost::shared_ptr b = bundle_for_type (*i, type); + if (b) { + system->add_bundle (b, allow_dups); + } } } /* Ardour stuff */ - if (!inputs && (type == DataType::AUDIO || type == DataType::NIL)) { - ardour->add_bundle (session->the_auditioner()->output()->bundle()); - ardour->add_bundle (session->click_io()->bundle()); + if (!inputs) { + boost::shared_ptr b = bundle_for_type (session->the_auditioner()->output()->bundle(), type); + if (b) { + ardour->add_bundle (b); + } + + b = bundle_for_type (session->click_io()->bundle(), type); + if (b) { + ardour->add_bundle (b); + } } /* Now find all other ports that we haven't thought of yet */ @@ -461,13 +481,21 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { if (!extra_system[*i].empty()) { - system->add_bundle (make_bundle_from_ports (extra_system[*i], *i, inputs)); + boost::shared_ptr b = make_bundle_from_ports (extra_system[*i], *i, inputs); + boost::shared_ptr bt = bundle_for_type (b, type); + if (bt) { + system->add_bundle (bt); + } } } for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { if (!extra_other[*i].empty()) { - other->add_bundle (make_bundle_from_ports (extra_other[*i], *i, inputs)); + boost::shared_ptr b = make_bundle_from_ports (extra_other[*i], *i, inputs); + boost::shared_ptr bt = bundle_for_type (b, type); + if (bt) { + other->add_bundle (bt); + } } } @@ -682,3 +710,30 @@ PortGroupList::empty () const return (i == _groups.end()); } +/** Take a bundle, and either return it, if it contains only ports of type \a t, + * or return a new bundle with those ports from \a b which are of type \a t. + * Note that t == NIL is taken to mean "all types". + */ +boost::shared_ptr +PortGroupList::bundle_for_type (boost::shared_ptr b, DataType t) const +{ + /* We are asked for a bundle with all types, so that's easy */ + if (t == DataType::NIL) { + return b; + } + + if (b->nchannels().get(t) == b->nchannels().n_total()) { + /* All channels on b are of the correct type, so just return b */ + return b; + } + + /* We must build a new bundle */ + boost::shared_ptr n; + for (uint32_t i = 0; i < b->nchannels().n_total(); ++i) { + if (b->channel_type(i) == t) { + n->add_channel (b->channel_name (i), t, b->channel_ports (i)); + } + } + + return n; +} -- cgit v1.2.3