Ardour  8.12
monitor_processor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2010-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2011-2014 David Robillard <d@drobilla.net>
5  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2014 Ben Loftis <ben@harrisonconsoles.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef __ardour_monitor_processor_h__
24 #define __ardour_monitor_processor_h__
25 
26 #include <algorithm>
27 #include <iostream>
28 #include <vector>
29 
30 #include "pbd/signals.h"
31 #include "pbd/compose.h"
32 #include "pbd/controllable.h"
33 
35 #include "ardour/types.h"
36 #include "ardour/processor.h"
37 
38 #include "ardour/dB.h"
39 
40 class XMLNode;
41 
42 namespace ARDOUR {
43 
44 class Session;
45 
46 template<typename T>
47 class /*LIBARDOUR_API*/ MPControl : public PBD::Controllable {
48 public:
49  MPControl (T initial, const std::string& name, PBD::Controllable::Flag flag,
50  float lower = 0.0f, float upper = 1.0f)
51  : PBD::Controllable (name, flag)
52  , _value (initial)
53  , _lower (lower)
54  , _upper (upper)
55  , _normal (initial)
56  {}
57 
58  /* Controllable API */
59 
61  T newval = (T) v;
62  if (newval != _value) {
63  _value = std::max (_lower, std::min (_upper, newval));
64  Changed (true, gcd); /* EMIT SIGNAL */
65  }
66  }
67 
68  double get_value () const {
69  return (float) _value;
70  }
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 (true, PBD::Controllable::UseGroup); /* 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 
125 {
126 public:
129 
130  bool display_to_user() const;
131 
132  void run (BufferSet& /*bufs*/, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t /*nframes*/, bool /*result_required*/);
133 
134  XMLNode& state () const;
135  int set_state (const XMLNode&, int /* version */);
136 
139 
140  void set_cut_all (bool);
141  void set_dim_all (bool);
142  void set_polarity (uint32_t, bool invert);
143  void set_cut (uint32_t, bool cut);
144  void set_dim (uint32_t, bool dim);
145  void set_solo (uint32_t, bool);
146  void set_mono (bool);
147 
148  gain_t dim_level() const { return _dim_level; }
149  gain_t solo_boost_level() const { return _solo_boost_level; }
150 
151  bool dimmed (uint32_t chn) const;
152  bool soloed (uint32_t chn) const;
153  bool inverted (uint32_t chn) const;
154  bool cut (uint32_t chn) const;
155  bool cut_all () const;
156  bool dim_all () const;
157  bool mono () const;
158 
159  bool monitor_active () const { return _monitor_active; }
160 
161  PBD::Signal0<void> Changed;
162 
163  std::shared_ptr<PBD::Controllable> channel_cut_control (uint32_t) const;
164  std::shared_ptr<PBD::Controllable> channel_dim_control (uint32_t) const;
165  std::shared_ptr<PBD::Controllable> channel_polarity_control (uint32_t) const;
166  std::shared_ptr<PBD::Controllable> channel_solo_control (uint32_t) const;
167 
168  std::shared_ptr<PBD::Controllable> dim_control () const { return _dim_all_control; }
169  std::shared_ptr<PBD::Controllable> cut_control () const { return _cut_all_control; }
170  std::shared_ptr<PBD::Controllable> mono_control () const { return _mono_control; }
171  std::shared_ptr<PBD::Controllable> dim_level_control () const { return _dim_level_control; }
172  std::shared_ptr<PBD::Controllable> solo_boost_control () const { return _solo_boost_level_control; }
173 
174 private:
175  struct ChannelRecord {
177 
178  /* pointers - created first, but managed by std::shared_ptr<> */
179 
184 
185  /* shared ptr access and lifetime management, for external users */
186 
187  std::shared_ptr<PBD::Controllable> cut_control;
188  std::shared_ptr<PBD::Controllable> dim_control;
189  std::shared_ptr<PBD::Controllable> polarity_control;
190  std::shared_ptr<PBD::Controllable> soloed_control;
191 
192  /* typed controllables for internal use */
193 
198 
199  ChannelRecord (uint32_t);
201  };
202 
203  std::vector<ChannelRecord*> _channels;
204 
205  uint32_t solo_cnt;
207 
208 
209  /* pointers - created first, but managed by std::shared_ptr<> */
210 
216 
217  /* shared ptr access and lifetime management, for external users */
218 
219  std::shared_ptr<PBD::Controllable> _dim_all_control;
220  std::shared_ptr<PBD::Controllable> _cut_all_control;
221  std::shared_ptr<PBD::Controllable> _mono_control;
222  std::shared_ptr<PBD::Controllable> _dim_level_control;
223  std::shared_ptr<PBD::Controllable> _solo_boost_level_control;
224 
225  /* typed controllables for internal use */
226 
232 
233  void allocate_channels (uint32_t);
235 };
236 
237 } /* namespace */
238 
239 #endif /* __ardour_monitor_processor_h__ */
bool operator>=(const T &v) const
double get_value() const
bool operator==(const T &v) const
double normal() const
void set_value(double v, PBD::Controllable::GroupControlDisposition gcd)
bool operator<=(const T &v) const
std::string get_user_string() const
double upper() const
double lower() const
MPControl(T initial, const std::string &name, PBD::Controllable::Flag flag, float lower=0.0f, float upper=1.0f)
bool operator>(const T &v) const
bool operator<(const T &v) const
MPControl & operator=(const T &v)
MPControl< bool > & _dim_all
std::shared_ptr< PBD::Controllable > _solo_boost_level_control
MPControl< volatile gain_t > & _solo_boost_level
MPControl< bool > * _cut_all_ptr
std::shared_ptr< PBD::Controllable > dim_level_control() const
MPControl< bool > & _mono
MPControl< bool > * _mono_ptr
void set_dim(uint32_t, bool dim)
std::shared_ptr< PBD::Controllable > _cut_all_control
void set_cut(uint32_t, bool cut)
std::shared_ptr< PBD::Controllable > _mono_control
std::vector< ChannelRecord * > _channels
bool can_support_io_configuration(const ChanCount &in, ChanCount &out)
MPControl< volatile gain_t > * _dim_level_ptr
bool dimmed(uint32_t chn) const
bool inverted(uint32_t chn) const
std::shared_ptr< PBD::Controllable > _dim_level_control
int set_state(const XMLNode &, int)
std::shared_ptr< PBD::Controllable > dim_control() const
void run(BufferSet &, samplepos_t, samplepos_t, double, pframes_t, bool)
void set_polarity(uint32_t, bool invert)
std::shared_ptr< PBD::Controllable > channel_solo_control(uint32_t) const
std::shared_ptr< PBD::Controllable > solo_boost_control() const
bool cut(uint32_t chn) const
XMLNode & state() const
std::shared_ptr< PBD::Controllable > channel_polarity_control(uint32_t) const
void set_solo(uint32_t, bool)
MPControl< volatile gain_t > & _dim_level
std::shared_ptr< PBD::Controllable > mono_control() const
std::shared_ptr< PBD::Controllable > channel_cut_control(uint32_t) const
void allocate_channels(uint32_t)
std::shared_ptr< PBD::Controllable > channel_dim_control(uint32_t) const
std::shared_ptr< PBD::Controllable > cut_control() const
bool configure_io(ChanCount in, ChanCount out)
PBD::Signal0< void > Changed
bool display_to_user() const
bool soloed(uint32_t chn) const
MPControl< bool > & _cut_all
MPControl< bool > * _dim_all_ptr
std::shared_ptr< PBD::Controllable > _dim_all_control
MPControl< volatile gain_t > * _solo_boost_level_ptr
PBD::Signal2< void, bool, PBD::Controllable::GroupControlDisposition > Changed
Definition: controllable.h:150
Controllable(const std::string &name, Flag f=Flag(0))
std::string name() const
Definition: controllable.h:155
Definition: xml++.h:114
static float accurate_coefficient_to_dB(float coeff)
Definition: dB.h:39
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplepos_t samplepos_t
Definition: axis_view.h:42
std::shared_ptr< PBD::Controllable > soloed_control
std::shared_ptr< PBD::Controllable > cut_control
std::shared_ptr< PBD::Controllable > polarity_control
std::shared_ptr< PBD::Controllable > dim_control