use new syntax for connecting to backend signals that enforces explicit connection...
[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 "pbd/signals.h"
28
29 #include "pbd/stateful.h"
30 #include "pbd/signals.h"
31
32 #include "ardour/types.h"
33
34 namespace ARDOUR {
35
36 class Route;
37 class Track;
38 class AudioTrack;
39 class Session;
40
41 class RouteGroup : public PBD::Stateful, public PBD::ScopedConnectionList {
42 public:
43         enum Flag {
44                 Relative = 0x1,
45                 Active = 0x2,
46                 Hidden = 0x4
47         };
48
49         enum Property {
50                 Gain = 0x1,
51                 Mute = 0x2,
52                 Solo = 0x4,
53                 RecEnable = 0x8,
54                 Select = 0x10,
55                 Edit = 0x20
56         };
57
58         RouteGroup (Session& s, const std::string &n, Flag f = Flag(0), Property p = Property(0));
59         ~RouteGroup ();
60
61         const std::string& name() { return _name; }
62         void set_name (std::string str);
63
64         bool is_active () const { return _flags & Active; }
65         bool is_relative () const { return _flags & Relative; }
66         bool is_hidden () const { return _flags & Hidden; }
67         bool empty() const {return routes->empty();}
68         size_t size() const { return routes->size();}
69
70         gain_t get_max_factor(gain_t factor);
71         gain_t get_min_factor(gain_t factor);
72
73         void set_active (bool yn, void *src);
74         void set_relative (bool yn, void *src);
75         void set_hidden (bool yn, void *src);
76
77         bool property (Property p) const {
78                 return ((_properties & p) == p);
79         }
80
81         bool active_property (Property p) const {
82                 return is_active() && property (p);
83         }
84
85         void set_property (Property p, bool v) {
86                 _properties = (Property) (_properties & ~p);
87                 if (v) {
88                         _properties = (Property) (_properties | p);
89                 }
90         }
91
92         int add (boost::shared_ptr<Route>);
93         int remove (boost::shared_ptr<Route>);
94
95         void apply (void (Route::*func)(void *), void *src) {
96                 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
97                         ((*i).get()->*func)(src);
98                 }
99         }
100
101         template<class T> void apply (void (Route::*func)(T, void *), T val, void *src) {
102                 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
103                         ((*i).get()->*func)(val, src);
104                 }
105         }
106
107         template<class T> void foreach_route (T *obj, void (T::*func)(Route&)) {
108                 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
109                         (obj->*func)(**i);
110                 }
111         }
112
113         /* to use these, #include "ardour/route_group_specialized.h" */
114
115         template<class T> void apply (void (Track::*func)(T, void *), T val, void *src);
116
117         /* fills at_set with all members of the group that are AudioTracks */
118
119         void audio_track_group (std::set<boost::shared_ptr<AudioTrack> >& at_set);
120
121         void clear () {
122                 routes->clear ();
123                 changed();
124         }
125
126         void make_subgroup ();
127         void destroy_subgroup ();
128
129         boost::shared_ptr<RouteList> route_list() { return routes; }
130
131         PBD::Signal0<void> changed;
132         PBD::Signal1<void,void*> FlagsChanged;
133
134         XMLNode& get_state ();
135         
136         int set_state (const XMLNode&, int version);
137         
138 private:
139         Session& _session;
140         boost::shared_ptr<RouteList> routes;
141         boost::shared_ptr<Route> subgroup_bus;
142         std::string _name;
143         Flag _flags;
144         Property _properties;
145
146         void remove_when_going_away (boost::weak_ptr<Route>);
147         int set_state_2X (const XMLNode&, int);
148 };
149
150 } /* namespace */
151
152 #endif /* __ardour_route_group_h__ */