Only show user-presets in favorite sidebar
[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/controllable.h"
29 #include "pbd/signals.h"
30 #include "pbd/stateful.h"
31
32 #include "ardour/control_group.h"
33 #include "ardour/types.h"
34 #include "ardour/session_object.h"
35
36 #include "ardour/libardour_visibility.h"
37
38 namespace ARDOUR {
39
40 namespace Properties {
41         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_relative;
42         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_gain;
43         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_mute;
44         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_solo;
45         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_recenable;
46         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_select;
47         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_route_active;
48         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_color;
49         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> group_monitoring;
50         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> active;
51         LIBARDOUR_API extern PBD::PropertyDescriptor<int32_t> group_master_number;
52         /* we use these declared in region.cc */
53         LIBARDOUR_API extern PBD::PropertyDescriptor<bool> hidden;
54 };
55
56 class Route;
57 class Track;
58 class AudioTrack;
59 class Session;
60
61 /** A group identifier for routes.
62  *
63  * RouteGroups permit to define properties which are shared
64  * among all Routes that use the given identifier.
65  *
66  * A route can at most be in one group.
67  */
68 class LIBARDOUR_API RouteGroup : public SessionObject
69 {
70 public:
71         static void make_property_quarks();
72
73         RouteGroup (Session& s, const std::string &n);
74         ~RouteGroup ();
75
76         bool is_active () const { return _active.val(); }
77         bool is_relative () const { return _relative.val(); }
78         bool is_hidden () const { return _hidden.val(); }
79         bool is_gain () const { return _gain.val(); }
80         bool is_mute () const { return _mute.val(); }
81         bool is_solo () const { return _solo.val(); }
82         bool is_recenable () const { return _recenable.val(); }
83         bool is_select () const { return _select.val(); }
84         bool is_route_active () const { return _route_active.val(); }
85         bool is_color () const { return _color.val(); }
86         bool is_monitoring() const { return _monitoring.val(); }
87         int32_t group_master_number() const { return _group_master_number.val(); }
88         boost::weak_ptr<Route> subgroup_bus() const { return _subgroup_bus; }
89
90         bool empty() const {return routes->empty();}
91         size_t size() const { return routes->size();}
92
93         gain_t get_max_factor(gain_t factor);
94         gain_t get_min_factor(gain_t factor);
95
96         void set_active (bool yn, void *src);
97         void set_relative (bool yn, void *src);
98         void set_hidden (bool yn, void *src);
99
100         void set_gain (bool yn);
101         void set_mute (bool yn);
102         void set_solo (bool yn);
103         void set_recenable (bool yn);
104         void set_select (bool yn);
105         void set_route_active (bool yn);
106         void set_color (bool yn);
107         void set_monitoring (bool yn);
108
109         bool enabled_property (PBD::PropertyID);
110
111         int add (boost::shared_ptr<Route>);
112         int remove (boost::shared_ptr<Route>);
113
114         template<typename Function>
115         void foreach_route (Function f) {
116                 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
117                         f (i->get());
118                 }
119         }
120
121         /* to use these, #include "ardour/route_group_specialized.h" */
122
123         template<class T> void apply (void (Track::*func)(T, PBD::Controllable::GroupControlDisposition), T val, PBD::Controllable::GroupControlDisposition);
124
125         /* fills at_set with all members of the group that are AudioTracks */
126
127         void audio_track_group (std::set<boost::shared_ptr<AudioTrack> >& at_set);
128
129         void clear () {
130                 routes->clear ();
131                 changed();
132         }
133
134         bool has_subgroup() const;
135         void make_subgroup (bool, Placement);
136         void destroy_subgroup ();
137
138         boost::shared_ptr<RouteList> route_list() { return routes; }
139
140         /** Emitted when a route has been added to this group */
141         PBD::Signal2<void, RouteGroup *, boost::weak_ptr<ARDOUR::Route> > RouteAdded;
142         /** Emitted when a route has been removed from this group */
143         PBD::Signal2<void, RouteGroup *, boost::weak_ptr<ARDOUR::Route> > RouteRemoved;
144
145         XMLNode& get_state ();
146
147         int set_state (const XMLNode&, int version);
148
149         void assign_master (boost::shared_ptr<VCA>);
150         void unassign_master (boost::shared_ptr<VCA>);
151         bool has_control_master() const;
152         bool slaved () const;
153
154         uint32_t rgba () const { return _rgba; }
155
156         /** set route-group color and notify UI about change */
157         void set_rgba (uint32_t);
158
159         /* directly set color only, used to convert old 5.x gui-object-state
160          * to libardour color */
161         void migrate_rgba (uint32_t color) { _rgba = color; }
162
163 private:
164         boost::shared_ptr<RouteList> routes;
165         boost::shared_ptr<Route> _subgroup_bus;
166         boost::weak_ptr<VCA> group_master;
167
168         PBD::Property<bool> _relative;
169         PBD::Property<bool> _active;
170         PBD::Property<bool> _hidden;
171         PBD::Property<bool> _gain;
172         PBD::Property<bool> _mute;
173         PBD::Property<bool> _solo;
174         PBD::Property<bool> _recenable;
175         PBD::Property<bool> _select;
176         PBD::Property<bool> _route_active;
177         PBD::Property<bool> _color;
178         PBD::Property<bool> _monitoring;
179         PBD::Property<int32_t> _group_master_number;
180
181         boost::shared_ptr<ControlGroup> _solo_group;
182         boost::shared_ptr<ControlGroup> _mute_group;
183         boost::shared_ptr<ControlGroup> _rec_enable_group;
184         boost::shared_ptr<ControlGroup> _gain_group;
185         boost::shared_ptr<ControlGroup> _monitoring_group;
186
187         void remove_when_going_away (boost::weak_ptr<Route>);
188         int set_state_2X (const XMLNode&, int);
189
190         void post_set (PBD::PropertyChange const &);
191         void push_to_groups ();
192
193         uint32_t _rgba;
194         bool _used_to_share_gain;
195 };
196
197 } /* namespace */
198
199 #endif /* __ardour_route_group_h__ */