Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / libs / ardour / ardour / route_group.h
1 /*
2     Copyright (C) 2000 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_route_group_h__
21 #define __ardour_route_group_h__
22
23 #include <list>
24 #include <set>
25 #include <string>
26 #include <stdint.h>
27 #include <sigc++/signal.h>
28 #include "pbd/stateful.h"
29 #include "ardour/types.h"
30
31 namespace ARDOUR {
32
33 class Route;
34 class Track;
35 class AudioTrack;
36 class Session;
37
38 class RouteGroup : public PBD::Stateful, public sigc::trackable {
39 public:
40         enum Flag {
41                 Relative = 0x1,
42                 Active = 0x2,
43                 Hidden = 0x4
44         };
45
46         enum Property {
47                 Gain = 0x1,
48                 Mute = 0x2,
49                 Solo = 0x4,
50                 RecEnable = 0x8,
51                 Select = 0x10,
52                 Edit = 0x20
53         };
54
55         RouteGroup (Session& s, const std::string &n, Flag f = Flag(0), Property p = Property(0));
56
57         const std::string& name() { return _name; }
58         void set_name (std::string str);
59
60         bool is_active () const { return _flags & Active; }
61         bool is_relative () const { return _flags & Relative; }
62         bool is_hidden () const { return _flags & Hidden; }
63         bool empty() const {return routes.empty();}
64
65         gain_t get_max_factor(gain_t factor);
66         gain_t get_min_factor(gain_t factor);
67
68         int size() { return routes.size();}
69
70         void set_active (bool yn, void *src);
71         void set_relative (bool yn, void *src);
72         void set_hidden (bool yn, void *src);
73
74         bool property (Property p) const {
75                 return ((_properties & p) == p);
76         }
77
78         bool active_property (Property p) const {
79                 return is_active() && property (p);
80         }
81
82         void set_property (Property p, bool v) {
83                 _properties = (Property) (_properties & ~p);
84                 if (v) {
85                         _properties = (Property) (_properties | p);
86                 }
87         }
88
89         int add (Route *);
90
91         int remove (Route *);
92
93         void apply (void (Route::*func)(void *), void *src) {
94                 for (std::list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
95                         ((*i)->*func)(src);
96                 }
97         }
98
99         template<class T> void apply (void (Route::*func)(T, void *), T val, void *src) {
100                 for (std::list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
101                         ((*i)->*func)(val, src);
102                 }
103         }
104
105         template<class T> void foreach_route (T *obj, void (T::*func)(Route&)) {
106                 for (std::list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
107                         (obj->*func)(**i);
108                 }
109         }
110
111         /* to use these, #include "ardour/route_group_specialized.h" */
112
113         template<class T> void apply (void (Track::*func)(T, void *), T val, void *src);
114
115         /* fills at_set with all members of the group that are AudioTracks */
116
117         void audio_track_group (std::set<AudioTrack*>& at_set);
118
119         void clear () {
120                 routes.clear ();
121                 changed();
122         }
123
124         void make_subgroup ();
125         void destroy_subgroup ();
126
127         const std::list<Route*>& route_list() { return routes; }
128
129         sigc::signal<void> changed;
130         sigc::signal<void,void*> FlagsChanged;
131
132         XMLNode& get_state ();
133
134         int set_state (const XMLNode&);
135
136 private:
137         Session& _session;
138         std::list<Route *> routes;
139         boost::shared_ptr<Route> subgroup_bus;
140         std::string _name;
141         Flag _flags;
142         Property _properties;
143
144         void remove_when_going_away (Route*);
145 };
146
147 } /* namespace */
148
149 #endif /* __ardour_route_group_h__ */