ardour
monitor_processor.h
Go to the documentation of this file.
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 <algorithm>
24 #include <iostream>
25 #include <vector>
26 
27 #include "pbd/signals.h"
28 #include "pbd/compose.h"
29 #include "pbd/controllable.h"
30 
32 #include "ardour/types.h"
33 #include "ardour/processor.h"
34 
35 #include "ardour/dB.h"
36 
37 class XMLNode;
38 
39 namespace ARDOUR {
40 
41 class Session;
42 
43 template<typename T>
44 class /*LIBARDOUR_API*/ MPControl : public PBD::Controllable {
45 public:
46  MPControl (T initial, const std::string& name, PBD::Controllable::Flag flag,
47  float lower = 0.0f, float upper = 1.0f)
48  : PBD::Controllable (name, flag)
49  , _value (initial)
50  , _lower (lower)
51  , _upper (upper)
52  , _normal (initial)
53  {}
54 
55  /* Controllable API */
56 
57  void set_value (double v) {
58  T newval = (T) v;
59  if (newval != _value) {
60  _value = std::max (_lower, std::min (_upper, newval));
61  Changed(); /* EMIT SIGNAL */
62  }
63  }
64 
65  double get_value () const {
66  return (float) _value;
67  }
68 
69  double internal_to_user (double i) const { return accurate_coefficient_to_dB (i);}
70  double user_to_internal (double u) const { return dB_to_coefficient(u) ;}
71 
72  std::string get_user_string () const
73  {
74  char theBuf[32]; sprintf( theBuf, "%3.1f dB", accurate_coefficient_to_dB (get_value()));
75  return std::string(theBuf);
76  }
77 
78  double lower () const { return _lower; }
79  double upper () const { return _upper; }
80  double normal () const { return _normal; }
81 
82  /* "access as T" API */
83 
84  MPControl& operator=(const T& v) {
85  if (v != _value) {
86  _value = std::max (_lower, std::min (_upper, v));
87  Changed (); /* EMIT SIGNAL */
88  }
89  return *this;
90  }
91 
92  bool operator==(const T& v) const {
93  return _value == v;
94  }
95 
96  bool operator<(const T& v) const {
97  return _value < v;
98  }
99 
100  bool operator<=(const T& v) const {
101  return _value <= v;
102  }
103 
104  bool operator>(const T& v) const {
105  return _value > v;
106  }
107 
108  bool operator>=(const T& v) const {
109  return _value >= v;
110  }
111 
112  operator T() const { return _value; }
113  T val() const { return _value; }
114 
115 protected:
120 };
121 
123 {
124 public:
126  ~MonitorProcessor ();
127 
128  bool display_to_user() const;
129 
130  void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t /*nframes*/, bool /*result_required*/);
131 
132  XMLNode& state (bool full);
133  int set_state (const XMLNode&, int /* version */);
134 
135  bool configure_io (ChanCount in, ChanCount out);
136  bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
137 
138  void set_cut_all (bool);
139  void set_dim_all (bool);
140  void set_polarity (uint32_t, bool invert);
141  void set_cut (uint32_t, bool cut);
142  void set_dim (uint32_t, bool dim);
143  void set_solo (uint32_t, bool);
144  void set_mono (bool);
145 
146  gain_t dim_level() const { return _dim_level; }
147  gain_t solo_boost_level() const { return _solo_boost_level; }
148 
149  bool dimmed (uint32_t chn) const;
150  bool soloed (uint32_t chn) const;
151  bool inverted (uint32_t chn) const;
152  bool cut (uint32_t chn) const;
153  bool cut_all () const;
154  bool dim_all () const;
155  bool mono () const;
156 
157  PBD::Signal0<void> Changed;
158 
159  boost::shared_ptr<PBD::Controllable> channel_cut_control (uint32_t) const;
160  boost::shared_ptr<PBD::Controllable> channel_dim_control (uint32_t) const;
161  boost::shared_ptr<PBD::Controllable> channel_polarity_control (uint32_t) const;
162  boost::shared_ptr<PBD::Controllable> channel_solo_control (uint32_t) const;
163 
164  boost::shared_ptr<PBD::Controllable> dim_control () const { return _dim_all_control; }
165  boost::shared_ptr<PBD::Controllable> cut_control () const { return _cut_all_control; }
166  boost::shared_ptr<PBD::Controllable> mono_control () const { return _mono_control; }
167  boost::shared_ptr<PBD::Controllable> dim_level_control () const { return _dim_level_control; }
168  boost::shared_ptr<PBD::Controllable> solo_boost_control () const { return _solo_boost_level_control; }
169 
170 private:
171  struct ChannelRecord {
173 
174  /* pointers - created first, but managed by boost::shared_ptr<> */
175 
180 
181  /* shared ptr access and lifetime management, for external users */
182 
187 
188  /* typed controllables for internal use */
189 
194 
195  ChannelRecord (uint32_t);
196  };
197 
198  std::vector<ChannelRecord*> _channels;
199 
200  uint32_t solo_cnt;
201 
202  /* pointers - created first, but managed by boost::shared_ptr<> */
203 
209 
210  /* shared ptr access and lifetime management, for external users */
211 
217 
218  /* typed controllables for internal use */
219 
225 
226  void allocate_channels (uint32_t);
227 };
228 
229 } /* namespace */
230 
231 #endif /* __ardour_monitor_processor_h__ */
boost::shared_ptr< PBD::Controllable > dim_control() const
MPControl< bool > * _dim_all_ptr
MPControl< bool > * _mono_ptr
bool operator<=(const T &v) const
gain_t solo_boost_level() const
uint32_t pframes_t
Definition: types.h:61
tuple f
Definition: signals.py:35
double internal_to_user(double i) const
MPControl< bool > & _dim_all
float gain_t
Definition: types.h:58
boost::shared_ptr< PBD::Controllable > soloed_control
bool operator>(const T &v) const
MPControl< volatile gain_t > * _dim_level_ptr
boost::shared_ptr< PBD::Controllable > dim_level_control() const
MPControl(T initial, const std::string &name, PBD::Controllable::Flag flag, float lower=0.0f, float upper=1.0f)
boost::shared_ptr< PBD::Controllable > _dim_level_control
MPControl< volatile gain_t > & _dim_level
static float accurate_coefficient_to_dB(float coeff)
Definition: dB.h:38
boost::shared_ptr< PBD::Controllable > solo_boost_control() const
boost::shared_ptr< PBD::Controllable > cut_control() const
MPControl & operator=(const T &v)
boost::shared_ptr< PBD::Controllable > polarity_control
double upper() const
boost::shared_ptr< PBD::Controllable > _mono_control
boost::shared_ptr< PBD::Controllable > _cut_all_control
bool operator==(const T &v) const
boost::shared_ptr< PBD::Controllable > mono_control() const
MPControl< bool > & _cut_all
Definition: amp.h:29
boost::shared_ptr< PBD::Controllable > _solo_boost_level_control
bool operator<(const T &v) const
int64_t framepos_t
Definition: types.h:66
MPControl< bool > & _mono
boost::shared_ptr< PBD::Controllable > cut_control
#define LIBARDOUR_API
double get_value() const
std::vector< ChannelRecord * > _channels
double normal() const
MPControl< volatile gain_t > & _solo_boost_level
double lower() const
void set_value(double v)
MPControl< bool > * _cut_all_ptr
Definition: xml++.h:95
PBD::Signal0< void > Changed
Definition: controllable.h:94
Definition: debug.h:30
static float dB_to_coefficient(float dB)
Definition: dB.h:30
MPControl< volatile gain_t > * _solo_boost_level_ptr
bool operator>=(const T &v) const
std::string name() const
Definition: controllable.h:99
PBD::Signal0< void > Changed
std::string get_user_string() const
boost::shared_ptr< PBD::Controllable > dim_control
boost::shared_ptr< PBD::Controllable > _dim_all_control
double user_to_internal(double u) const