Update route colours when they are added to / removed
[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
28 #include "pbd/signals.h"
29 #include "pbd/stateful.h"
30 #include "pbd/signals.h"
31
32 #include "ardour/types.h"
33 #include "ardour/session_object.h"
34
35 namespace ARDOUR {
36
37 namespace Properties {
38         extern PBD::PropertyDescriptor<bool> relative;
39         extern PBD::PropertyDescriptor<bool> active;
40         extern PBD::PropertyDescriptor<bool> gain;
41         extern PBD::PropertyDescriptor<bool> mute;
42         extern PBD::PropertyDescriptor<bool> solo;
43         extern PBD::PropertyDescriptor<bool> recenable;
44         extern PBD::PropertyDescriptor<bool> select;
45         extern PBD::PropertyDescriptor<bool> edit;
46         extern PBD::PropertyDescriptor<bool> route_active;
47         extern PBD::PropertyDescriptor<bool> color;
48         /* we use this, but its declared in region.cc */
49         extern PBD::PropertyDescriptor<bool> hidden;
50 };
51
52 class Route;
53 class Track;
54 class AudioTrack;
55 class Session;
56
57 class RouteGroup : public SessionObject
58 {
59   public:
60         static void make_property_quarks();
61
62         RouteGroup (Session& s, const std::string &n);
63         ~RouteGroup ();
64
65         bool is_active () const { return _active.val(); }
66         bool is_relative () const { return _relative.val(); }
67         bool is_hidden () const { return _hidden.val(); }
68         bool is_gain () const { return _gain.val(); }
69         bool is_mute () const { return _mute.val(); }
70         bool is_solo () const { return _solo.val(); }
71         bool is_recenable () const { return _recenable.val(); }
72         bool is_select () const { return _select.val(); }
73         bool is_edit () const { return _edit.val(); }
74         bool is_route_active () const { return _route_active.val(); }
75         bool is_color () const { return _color.val(); }
76
77         bool empty() const {return routes->empty();}
78         size_t size() const { return routes->size();}
79
80         gain_t get_max_factor(gain_t factor);
81         gain_t get_min_factor(gain_t factor);
82
83         void set_active (bool yn, void *src);
84         void set_relative (bool yn, void *src);
85         void set_hidden (bool yn, void *src);
86
87         void set_gain (bool yn);
88         void set_mute (bool yn);
89         void set_solo (bool yn);
90         void set_recenable (bool yn);
91         void set_select (bool yn);
92         void set_edit (bool yn);
93         void set_route_active (bool yn);
94         void set_color (bool yn);
95
96         bool enabled_property (PBD::PropertyID);
97
98         int add (boost::shared_ptr<Route>);
99         int remove (boost::shared_ptr<Route>);
100
101         template<typename Function>
102         void foreach_route (Function f) {
103                 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
104                         f (i->get());
105                 }
106         }
107
108         /* to use these, #include "ardour/route_group_specialized.h" */
109
110         template<class T> void apply (void (Track::*func)(T, void *), T val, void *src);
111
112         /* fills at_set with all members of the group that are AudioTracks */
113
114         void audio_track_group (std::set<boost::shared_ptr<AudioTrack> >& at_set);
115
116         void clear () {
117                 routes->clear ();
118                 changed();
119         }
120
121         void make_subgroup (bool, Placement);
122         void destroy_subgroup ();
123
124         boost::shared_ptr<RouteList> route_list() { return routes; }
125
126         /** Emitted when a route has been added to this group */
127         PBD::Signal2<void, RouteGroup *, boost::weak_ptr<ARDOUR::Route> > RouteAdded;
128         /** Emitted when a route has been removed from this group */
129         PBD::Signal2<void, RouteGroup *, boost::weak_ptr<ARDOUR::Route> > RouteRemoved;
130
131         XMLNode& get_state ();
132
133         int set_state (const XMLNode&, int version);
134
135 private:
136         boost::shared_ptr<RouteList> routes;
137         boost::shared_ptr<Route> subgroup_bus;
138
139         PBD::Property<bool> _relative;
140         PBD::Property<bool> _active;
141         PBD::Property<bool> _hidden;
142         PBD::Property<bool> _gain;
143         PBD::Property<bool> _mute;
144         PBD::Property<bool> _solo;
145         PBD::Property<bool> _recenable;
146         PBD::Property<bool> _select;
147         PBD::Property<bool> _edit;
148         PBD::Property<bool> _route_active;
149         PBD::Property<bool> _color;
150
151         void remove_when_going_away (boost::weak_ptr<Route>);
152         int set_state_2X (const XMLNode&, int);
153 };
154
155 } /* namespace */
156
157 #endif /* __ardour_route_group_h__ */