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