r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[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     $Id$
19 */
20
21 #ifndef __ardour_route_group_h__
22 #define __ardour_route_group_h__
23
24 #include <list>
25 #include <set>
26 #include <string>
27 #include <stdint.h>
28 #include <sigc++/signal.h>
29 #include <pbd/stateful.h> 
30 #include <ardour/types.h>
31
32 using std::string;
33 using std::list;
34
35 namespace ARDOUR {
36
37 class Route;
38 class Track;
39 class AudioTrack;
40 class Session;
41
42 class RouteGroup : public Stateful, public sigc::trackable {
43   public:
44     enum Flag {
45             Relative = 0x1,
46             Active = 0x2,
47             Hidden = 0x4
48     };
49
50     RouteGroup (Session& s, const string &n, Flag f = Flag(0));
51
52     const string& name() { return _name; }
53     void set_name (std::string str);
54
55     bool is_active () const { return _flags & Active; }
56     bool is_relative () const { return _flags & Relative; }
57     bool is_hidden () const { return _flags & Hidden; }
58     bool empty() const {return routes.empty();}
59
60     gain_t get_max_factor(gain_t factor);
61     gain_t get_min_factor(gain_t factor);
62     
63     int size() { return routes.size();}
64     ARDOUR::Route * first () const { return *routes.begin();}
65
66     void set_active (bool yn, void *src);
67     void set_relative (bool yn, void *src);
68     void set_hidden (bool yn, void *src);
69
70     int add (Route *);
71
72     int remove (Route *);
73
74     void apply (void (Route::*func)(void *), void *src) {
75             for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
76                     ((*i)->*func)(src);
77             }
78     }
79
80     template<class T> void apply (void (Route::*func)(T, void *), T val, void *src) {
81             for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
82                     ((*i)->*func)(val, src);
83             }
84     }
85
86     template<class T> void foreach_route (T *obj, void (T::*func)(Route&)) {
87             for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
88                     (obj->*func)(**i);
89             }
90     }
91
92     /* to use these, #include <ardour/route_group_specialized.h> */
93
94     template<class T> void apply (void (Track::*func)(T, void *), T val, void *src);
95
96     /* fills at_set with all members of the group that are AudioTracks */
97
98     void audio_track_group (std::set<AudioTrack*>& at_set);
99
100     void clear () {
101             routes.clear ();
102             changed();
103     }
104
105     const list<Route*>& route_list() { return routes; }
106     
107     sigc::signal<void> changed;
108     sigc::signal<void,void*> FlagsChanged;
109
110     XMLNode& get_state (void);
111
112     int set_state (const XMLNode&);
113
114  private:
115     Session& _session;
116     list<Route *> routes;
117     string _name;
118     uint32_t _flags;
119
120     void remove_when_going_away (Route*);
121 };
122
123 } /* namespace */
124
125 #endif /* __ardour_route_group_h__ */