Ardour  9.0-pre0-582-g084a23a80d
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 <glibmm/threads.h>
27 
28 #include "ardour/session.h"
29 #include "ardour/route.h"
30 
31 namespace ARDOUR {
32 
33 template<class T> void
34 Session::foreach_route (T *obj, void (T::*func)(Route&), bool sort)
35 {
36  std::shared_ptr<RouteList const> r = routes.reader();
37  RouteList public_order (*r);
38 
39  if (sort) {
40  public_order.sort (Stripable::Sorter ());
41  }
42 
43  for (RouteList::iterator i = public_order.begin(); i != public_order.end(); i++) {
44  (obj->*func) (**i);
45  }
46 }
47 
48 template<class T> void
49 Session::foreach_route (T *obj, void (T::*func)(std::shared_ptr<Route>), bool sort)
50 {
51  std::shared_ptr<RouteList const> r = routes.reader();
52  RouteList public_order (*r);
53 
54  if (sort) {
55  public_order.sort (Stripable::Sorter ());
56  }
57 
58  for (RouteList::iterator i = public_order.begin(); i != public_order.end(); i++) {
59  (obj->*func) (*i);
60  }
61 }
62 
63 template<class T, class A> void
64 Session::foreach_route (T *obj, void (T::*func)(Route&, A), A arg1, bool sort)
65 {
66  std::shared_ptr<RouteList const> r = routes.reader();
67  RouteList public_order (*r);
68 
69  if (sort) {
70  public_order.sort (Stripable::Sorter ());
71  }
72 
73  for (RouteList::iterator i = public_order.begin(); i != public_order.end(); i++) {
74  (obj->*func) (**i, arg1);
75  }
76 }
77 
78 
79 template<class A> void
80 Session::foreach_track (void (Track::*method)(A), A arg)
81 {
82  std::shared_ptr<RouteList const> r = routes.reader();
83 
84  for (auto const& i : *r) {
85  std::shared_ptr<Track> tr = std::dynamic_pointer_cast<Track> (i);
86  if (tr) {
87  (tr.get()->*method) (arg);
88  }
89  }
90 }
91 
92 template<class A1, class A2> void
93 Session::foreach_track (void (Track::*method)(A1, A2), A1 arg1, A2 arg2)
94 {
95  std::shared_ptr<RouteList const> r = routes.reader();
96 
97  for (auto const& i : *r) {
98  std::shared_ptr<Track> tr = std::dynamic_pointer_cast<Track> (i);
99  if (tr) {
100  (tr.get()->*method) (arg1, arg2);
101  }
102  }
103 }
104 
105 template<class A> void
106 Session::foreach_route (void (Route::*method)(A), A arg)
107 {
108  std::shared_ptr<RouteList const> r = routes.reader();
109  for (auto const& i : *r) {
110  (i.get()->*method) (arg);
111  }
112 }
113 
114 template<class A1, class A2> void
115 Session::foreach_route (void (Route::*method)(A1, A2), A1 arg1, A2 arg2)
116 {
117  std::shared_ptr<RouteList const> r = routes.reader();
118 
119  for (auto const& i : *r) {
120  (i.get()->*method) (arg1, arg2);
121  }
122 }
123 
124 } /* namespace */
125 
void foreach_route(T *obj, void(T::*func)(Route &), bool sort=true)
Definition: session_route.h:34
void foreach_track(void(Track::*method)(A), A arg)
Definition: session_route.h:80
SerializedRCUManager< RouteList > routes
Definition: session.h:1907
std::shared_ptr< T const > reader() const
Definition: rcu.h:69
std::list< std::shared_ptr< Route > > RouteList