From c448b805d1124a2d4a2004efb685ff54674f719f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 17 May 2016 15:05:36 -0400 Subject: fix implementation of Session::get_remote_nth_stripable() --- libs/ardour/session.cc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'libs/ardour/session.cc') diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 39b8e6c50d..d150860584 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4213,25 +4213,39 @@ Session::get_remote_nth_route (uint16_t n) const return boost::dynamic_pointer_cast (get_remote_nth_stripable (n, PresentationInfo::Route)); } +struct GlobalPresentationOrderSorter { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { + return a->presentation_info() < b->presentation_info(); + } +}; + boost::shared_ptr Session::get_remote_nth_stripable (uint16_t n, PresentationInfo::Flag flags) const { - boost::shared_ptr r = routes.reader (); - vector > v; + StripableList sl; + uint32_t match_cnt = 0; + + /* API is one-based, so adjust n */ - if (n >= r->size()) { - return boost::shared_ptr (); + if (n) { + --n; } - v.assign (r->size(), boost::shared_ptr()); + get_stripables (sl); + GlobalPresentationOrderSorter cmp; + sl.sort (cmp); - for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { - if ((*i)->presentation_info().flag_match (flags)) { - v[(*i)->presentation_info().group_order()] = (*i); + for (StripableList::const_iterator s = sl.begin(); s != sl.end(); ++s) { + if ((*s)->presentation_info().flag_match (flags)) { + cerr << '\t' << (*s)->name() << " matches " << enum_2_string (flags) << endl; + if (match_cnt++ == n) { + return *s; + } } } - return v[n]; + /* there is no nth stripable that matches the given flags */ + return boost::shared_ptr(); } boost::shared_ptr -- cgit v1.2.3