lincoln's patch from mantis 2757 to add route group property checkboxes in the route...
[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         ARDOUR::Route * first () const { return *routes.begin();}
70         
71         void set_active (bool yn, void *src);
72         void set_relative (bool yn, void *src);
73         void set_hidden (bool yn, void *src);
74
75         bool property (Property p) const {
76                 return ((_properties & p) == p);
77         }
78         
79         bool active_property (Property p) const {
80                 return is_active() && property (p);
81         }
82
83         void set_property (Property p, bool v) {
84                 _properties = (Property) (_properties & ~p);
85                 if (v) {
86                         _properties = (Property) (_properties | p);
87                 }
88         }
89         
90         int add (Route *);
91         
92         int remove (Route *);
93         
94         void apply (void (Route::*func)(void *), void *src) {
95                 for (std::list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
96                         ((*i)->*func)(src);
97                 }
98         }
99         
100         template<class T> void apply (void (Route::*func)(T, void *), T val, void *src) {
101                 for (std::list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
102                         ((*i)->*func)(val, src);
103                 }
104         }
105         
106         template<class T> void foreach_route (T *obj, void (T::*func)(Route&)) {
107                 for (std::list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
108                         (obj->*func)(**i);
109                 }
110         }
111         
112         /* to use these, #include "ardour/route_group_specialized.h" */
113         
114         template<class T> void apply (void (Track::*func)(T, void *), T val, void *src);
115         
116         /* fills at_set with all members of the group that are AudioTracks */
117         
118         void audio_track_group (std::set<AudioTrack*>& at_set);
119         
120         void clear () {
121                 routes.clear ();
122                 changed();
123         }
124
125         void make_subgroup ();
126         void destroy_subgroup ();
127         
128         const std::list<Route*>& route_list() { return routes; }
129         
130         sigc::signal<void> changed;
131         sigc::signal<void,void*> FlagsChanged;
132         
133         XMLNode& get_state ();
134         
135         int set_state (const XMLNode&);
136         
137 private:
138         Session& _session;
139         std::list<Route *> routes;
140         boost::shared_ptr<Route> subgroup_bus;
141         std::string _name;
142         Flag _flags;
143         Property _properties;
144         
145         void remove_when_going_away (Route*);
146 };
147         
148 } /* namespace */
149
150 #endif /* __ardour_route_group_h__ */