Ardour  9.2-79-gba93f2fe52
session_route.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2006-2012 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009 David Robillard <d@drobilla.net>
5  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include <iostream>
25 
26 #include "ardour/session.h"
27 #include "ardour/route.h"
28 
29 namespace ARDOUR {
30 
31 template<class T> void
32 Session::foreach_route (T *obj, void (T::*func)(Route&), bool sort)
33 {
34  std::shared_ptr<RouteList const> r = routes.reader();
35  RouteList public_order (*r);
36 
37  if (sort) {
38  public_order.sort (Stripable::Sorter ());
39  }
40 
41  for (RouteList::iterator i = public_order.begin(); i != public_order.end(); i++) {
42  (obj->*func) (**i);
43  }
44 }
45 
46 template<class T> void
47 Session::foreach_route (T *obj, void (T::*func)(std::shared_ptr<Route>), bool sort)
48 {
49  std::shared_ptr<RouteList const> r = routes.reader();
50  RouteList public_order (*r);
51 
52  if (sort) {
53  public_order.sort (Stripable::Sorter ());
54  }
55 
56  for (RouteList::iterator i = public_order.begin(); i != public_order.end(); i++) {
57  (obj->*func) (*i);
58  }
59 }
60 
61 template<class T, class A> void
62 Session::foreach_route (T *obj, void (T::*func)(Route&, A), A arg1, bool sort)
63 {
64  std::shared_ptr<RouteList const> r = routes.reader();
65  RouteList public_order (*r);
66 
67  if (sort) {
68  public_order.sort (Stripable::Sorter ());
69  }
70 
71  for (RouteList::iterator i = public_order.begin(); i != public_order.end(); i++) {
72  (obj->*func) (**i, arg1);
73  }
74 }
75 
76 
77 template<class A> void
78 Session::foreach_track (void (Track::*method)(A), A arg)
79 {
80  std::shared_ptr<RouteList const> r = routes.reader();
81 
82  for (auto const& i : *r) {
83  std::shared_ptr<Track> tr = std::dynamic_pointer_cast<Track> (i);
84  if (tr) {
85  (tr.get()->*method) (arg);
86  }
87  }
88 }
89 
90 template<class A1, class A2> void
91 Session::foreach_track (void (Track::*method)(A1, A2), A1 arg1, A2 arg2)
92 {
93  std::shared_ptr<RouteList const> r = routes.reader();
94 
95  for (auto const& i : *r) {
96  std::shared_ptr<Track> tr = std::dynamic_pointer_cast<Track> (i);
97  if (tr) {
98  (tr.get()->*method) (arg1, arg2);
99  }
100  }
101 }
102 
103 template<class A> void
104 Session::foreach_route (void (Route::*method)(A), A arg)
105 {
106  std::shared_ptr<RouteList const> r = routes.reader();
107  for (auto const& i : *r) {
108  (i.get()->*method) (arg);
109  }
110 }
111 
112 template<class A1, class A2> void
113 Session::foreach_route (void (Route::*method)(A1, A2), A1 arg1, A2 arg2)
114 {
115  std::shared_ptr<RouteList const> r = routes.reader();
116 
117  for (auto const& i : *r) {
118  (i.get()->*method) (arg1, arg2);
119  }
120 }
121 
122 } /* namespace */
123 
void foreach_route(T *obj, void(T::*func)(Route &), bool sort=true)
Definition: session_route.h:32
void foreach_track(void(Track::*method)(A), A arg)
Definition: session_route.h:78
SerializedRCUManager< RouteList > routes
Definition: session.h:1975
std::shared_ptr< T const > reader() const
Definition: rcu.h:69
std::list< std::shared_ptr< Route > > RouteList