From 490fac163211d71ca640da1d072de888f380e643 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 7 May 2020 12:38:09 -0600 Subject: add new template methods for "foreach {route,track}" and use them Also remove redundant double call to Track::set_block_size(). This dates back to 2010 when there used be an additional traversal of the Diskstream RCU-managed list, before they became owned by Tracks --- libs/ardour/ardour/session.h | 6 +++++ libs/ardour/ardour/session_route.h | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'libs/ardour/ardour') diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 52a752d601..86822f3adc 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -350,6 +350,12 @@ public: template void foreach_route (T *obj, void (T::*func)(boost::shared_ptr), bool sort = true); template void foreach_route (T *obj, void (T::*func)(Route&, A), A arg, bool sort = true); + template void foreach_track (void (Track::*method)(A), A arg); + template void foreach_track (void (Track::*method)(A1, A2), A1 arg1, A2 arg2); + + template void foreach_route (void (Route::*method)(A), A arg); + template void foreach_route (void (Route::*method)(A1, A2), A1 arg1, A2 arg2); + static char session_name_is_legal (const std::string&); bool io_name_is_legal (const std::string&) const; boost::shared_ptr route_by_name (std::string) const; diff --git a/libs/ardour/ardour/session_route.h b/libs/ardour/ardour/session_route.h index d6f212ec42..fe5f7ad8c0 100644 --- a/libs/ardour/ardour/session_route.h +++ b/libs/ardour/ardour/session_route.h @@ -76,6 +76,53 @@ Session::foreach_route (T *obj, void (T::*func)(Route&, A), A arg1, bool sort) } } + +template void +Session::foreach_track (void (Track::*method)(A), A arg) +{ + boost::shared_ptr r = routes.reader(); + + for (RouteList::iterator i = r->begin(); i != r->end(); i++) { + boost::shared_ptr tr = boost::dynamic_pointer_cast (*i); + if (tr) { + (tr->*method) (arg); + } + } +} + +template void +Session::foreach_track (void (Track::*method)(A1, A2), A1 arg1, A2 arg2) +{ + boost::shared_ptr r = routes.reader(); + + for (RouteList::iterator i = r->begin(); i != r->end(); i++) { + boost::shared_ptr tr = boost::dynamic_pointer_cast (*i); + if (tr) { + (tr->*method) (arg1, arg2); + } + } +} + +template void +Session::foreach_route (void (Route::*method)(A), A arg) +{ + boost::shared_ptr r = routes.reader(); + + for (RouteList::iterator i = r->begin(); i != r->end(); i++) { + ((*i).get()->*method) (arg); + } +} + +template void +Session::foreach_route (void (Route::*method)(A1, A2), A1 arg1, A2 arg2) +{ + boost::shared_ptr r = routes.reader(); + + for (RouteList::iterator i = r->begin(); i != r->end(); i++) { + ((*i).get()->*method) (arg1, arg2); + } +} + } /* namespace */ #endif /* __ardour_session_route_h__ */ -- cgit v1.2.3