drastic, deep and wide changes to make RouteGroup use boost::shared_ptr<Route> and...
[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
29 #include "pbd/stateful.h"
30 #include "ardour/types.h"
31
32 namespace ARDOUR {
33
34 class Route;
35 class Track;
36 class AudioTrack;
37 class Session;
38
39 class RouteGroup : public PBD::Stateful, public sigc::trackable {
40 public:
41         enum Flag {
42                 Relative = 0x1,
43                 Active = 0x2,
44                 Hidden = 0x4
45         };
46
47         enum Property {
48                 Gain = 0x1,
49                 Mute = 0x2,
50                 Solo = 0x4,
51                 RecEnable = 0x8,
52                 Select = 0x10,
53                 Edit = 0x20
54         };
55
56         RouteGroup (Session& s, const std::string &n, Flag f = Flag(0), Property p = Property(0));
57         ~RouteGroup ();
58
59         const std::string& name() { return _name; }
60         void set_name (std::string str);
61
62         bool is_active () const { return _flags & Active; }
63         bool is_relative () const { return _flags & Relative; }
64         bool is_hidden () const { return _flags & Hidden; }
65         bool empty() const {return routes->empty();}
66         size_t size() const { return routes->size();}
67
68         gain_t get_max_factor(gain_t factor);
69         gain_t get_min_factor(gain_t factor);
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 (boost::shared_ptr<Route>);
91         int remove (boost::shared_ptr<Route>);
92
93         void apply (void (Route::*func)(void *), void *src) {
94                 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
95                         ((*i).get()->*func)(src);
96                 }
97         }
98
99         template<class T> void apply (void (Route::*func)(T, void *), T val, void *src) {
100                 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
101                         ((*i).get()->*func)(val, src);
102                 }
103         }
104
105         template<class T> void foreach_route (T *obj, void (T::*func)(Route&)) {
106                 for (RouteList::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<boost::shared_ptr<AudioTrack> >& at_set);
118
119         void clear () {
120                 routes->clear ();
121                 changed();
122         }
123
124         void make_subgroup ();
125         void destroy_subgroup ();
126
127         boost::shared_ptr<RouteList> route_list() { return routes; }
128         boost::shared_ptr<RouteList> route_list (Property forProperty);
129
130         sigc::signal<void> changed;
131         sigc::signal<void,void*> FlagsChanged;
132
133         XMLNode& get_state ();
134         
135         int set_state (const XMLNode&, int version);
136         
137 private:
138         Session& _session;
139         boost::shared_ptr<RouteList> 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 (boost::weak_ptr<Route>);
146         int set_state_2X (const XMLNode&, int);
147 };
148
149 } /* namespace */
150
151 #endif /* __ardour_route_group_h__ */