Fix broken whitespace. I'd apologize for the compile times if it was my fault :D
[ardour.git] / libs / ardour / ardour / monitor_processor.h
1 /*
2     Copyright (C) 2010 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_monitor_processor_h__
21 #define __ardour_monitor_processor_h__
22
23 #include <iostream>
24 #include <vector>
25
26 #include "pbd/signals.h"
27 #include "pbd/compose.h"
28 #include "pbd/controllable.h"
29
30 #include "ardour/types.h"
31 #include "ardour/processor.h"
32
33 class XMLNode;
34
35 namespace ARDOUR {
36
37 class Session;
38
39 template<typename T>
40 class MPControl : public PBD::Controllable {
41 public:
42         MPControl (T initial, const std::string& name, PBD::Controllable::Flag flag,
43                    float lower = 0.0f, float upper = 1.0f)
44                 : PBD::Controllable (name, flag)
45                 , _value (initial)
46                 , _lower (lower)
47                 , _upper (upper)
48         {}
49
50         /* Controllable API */
51
52         void set_value (double v) {
53                 T newval = (T) v;
54                 if (newval != _value) {
55                         _value = newval;
56                         Changed(); /* EMIT SIGNAL */
57                 }
58         }
59
60         double get_value () const {
61                 return (float) _value;
62         }
63
64         double lower () const { return _lower; }
65         double upper () const { return _upper; }
66
67         /* "access as T" API */
68
69         MPControl& operator=(const T& v) {
70                 if (v != _value) {
71                         _value = v;
72                         Changed (); /* EMIT SIGNAL */
73                 }
74                 return *this;
75         }
76
77         bool operator==(const T& v) const {
78                 return _value == v;
79         }
80
81         bool operator<(const T& v) const {
82                 return _value < v;
83         }
84
85         bool operator<=(const T& v) const {
86                 return _value <= v;
87         }
88
89         bool operator>(const T& v) const {
90                 return _value > v;
91         }
92
93         bool operator>=(const T& v) const {
94                 return _value >= v;
95         }
96
97         operator T() const { return _value; }
98         T val() const { return _value; }
99
100 protected:
101         T _value;
102         T _lower;
103         T _upper;
104 };
105
106 class MonitorProcessor : public Processor
107 {
108 public:
109         MonitorProcessor (Session&);
110         ~MonitorProcessor ();
111
112         bool display_to_user() const;
113
114         void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t /*nframes*/, bool /*result_required*/);
115
116         XMLNode& state (bool full);
117         int set_state (const XMLNode&, int /* version */);
118
119         bool configure_io (ChanCount in, ChanCount out);
120         bool can_support_io_configuration (const ChanCount& in, ChanCount& out) const;
121
122         void set_cut_all (bool);
123         void set_dim_all (bool);
124         void set_polarity (uint32_t, bool invert);
125         void set_cut (uint32_t, bool cut);
126         void set_dim (uint32_t, bool dim);
127         void set_solo (uint32_t, bool);
128         void set_mono (bool);
129
130         gain_t dim_level() const { return _dim_level; }
131         gain_t solo_boost_level() const { return _solo_boost_level; }
132
133         bool dimmed (uint32_t chn) const;
134         bool soloed (uint32_t chn) const;
135         bool inverted (uint32_t chn) const;
136         bool cut (uint32_t chn) const;
137         bool cut_all () const;
138         bool dim_all () const;
139         bool mono () const;
140
141         PBD::Signal0<void> Changed;
142
143         boost::shared_ptr<PBD::Controllable> channel_cut_control (uint32_t) const;
144         boost::shared_ptr<PBD::Controllable> channel_dim_control (uint32_t) const;
145         boost::shared_ptr<PBD::Controllable> channel_polarity_control (uint32_t) const;
146         boost::shared_ptr<PBD::Controllable> channel_solo_control (uint32_t) const;
147
148         boost::shared_ptr<PBD::Controllable> dim_control () const { return _dim_all_control; }
149         boost::shared_ptr<PBD::Controllable> cut_control () const { return _cut_all_control; }
150         boost::shared_ptr<PBD::Controllable> mono_control () const { return _mono_control; }
151         boost::shared_ptr<PBD::Controllable> dim_level_control () const { return _dim_level_control; }
152         boost::shared_ptr<PBD::Controllable> solo_boost_control () const { return _solo_boost_level_control; }
153
154 private:
155         struct ChannelRecord {
156                 gain_t current_gain;
157
158                 /* pointers - created first, but managed by boost::shared_ptr<> */
159
160                 MPControl<gain_t>* cut_ptr;
161                 MPControl<bool>*   dim_ptr;
162                 MPControl<gain_t>* polarity_ptr;
163                 MPControl<bool>*   soloed_ptr;
164
165                 /* shared ptr access and lifetime management, for external users */
166
167                 boost::shared_ptr<PBD::Controllable> cut_control;
168                 boost::shared_ptr<PBD::Controllable> dim_control;
169                 boost::shared_ptr<PBD::Controllable> polarity_control;
170                 boost::shared_ptr<PBD::Controllable> soloed_control;
171
172                 /* typed controllables for internal use */
173
174                 MPControl<gain_t>& cut;
175                 MPControl<bool>&   dim;
176                 MPControl<gain_t>& polarity;
177                 MPControl<bool>&   soloed;
178
179                 ChannelRecord (uint32_t);
180         };
181
182         std::vector<ChannelRecord*> _channels;
183
184         uint32_t             solo_cnt;
185
186         /* pointers - created first, but managed by boost::shared_ptr<> */
187
188         MPControl<bool>*            _dim_all_ptr;
189         MPControl<bool>*            _cut_all_ptr;
190         MPControl<bool>*            _mono_ptr;
191         MPControl<volatile gain_t>* _dim_level_ptr;
192         MPControl<volatile gain_t>* _solo_boost_level_ptr;
193
194         /* shared ptr access and lifetime management, for external users */
195
196         boost::shared_ptr<PBD::Controllable> _dim_all_control;
197         boost::shared_ptr<PBD::Controllable> _cut_all_control;
198         boost::shared_ptr<PBD::Controllable> _mono_control;
199         boost::shared_ptr<PBD::Controllable> _dim_level_control;
200         boost::shared_ptr<PBD::Controllable> _solo_boost_level_control;
201
202         /* typed controllables for internal use */
203
204         MPControl<bool>&            _dim_all;
205         MPControl<bool>&            _cut_all;
206         MPControl<bool>&            _mono;
207         MPControl<volatile gain_t>& _dim_level;
208         MPControl<volatile gain_t>& _solo_boost_level;
209
210         void allocate_channels (uint32_t);
211 };
212
213 } /* namespace */
214
215 #endif /* __ardour_monitor_processor_h__ */