Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
24 
25 #include <algorithm>
26 #include <iostream>
27 #include <vector>
28 
29 #include "pbd/signals.h"
30 #include "pbd/compose.h"
31 #include "pbd/controllable.h"
32 
34 #include "ardour/types.h"
35 #include "ardour/processor.h"
36 
37 #include "ardour/dB.h"
38 
39 class XMLNode;
40 
41 namespace ARDOUR {
42 
43 class Session;
44 
45 template<typename T>
46 class /*LIBARDOUR_API*/ MPControl : public PBD::Controllable {
47 public:
48  MPControl (T initial, const std::string& name, PBD::Controllable::Flag flag,
49  float lower = 0.0f, float upper = 1.0f)
50  : PBD::Controllable (name, flag)
51  , _value (initial)
52  , _lower (lower)
53  , _upper (upper)
54  , _normal (initial)
55  {}
56 
57  /* Controllable API */
58 
60  T newval = (T) v;
61  if (newval != _value) {
62  _value = std::max (_lower, std::min (_upper, newval));
63  Changed (true, gcd); /* EMIT SIGNAL */
64  }
65  }
66 
67  double get_value () const {
68  return (float) _value;
69  }
70 
71  std::string get_user_string () const
72  {
73  char theBuf[32]; sprintf( theBuf, "%3.1f dB", accurate_coefficient_to_dB (get_value()));
74  return std::string(theBuf);
75  }
76 
77  double lower () const { return _lower; }
78  double upper () const { return _upper; }
79  double normal () const { return _normal; }
80 
81  /* "access as T" API */
82 
83  MPControl& operator=(const T& v) {
84  if (v != _value) {
85  _value = std::max (_lower, std::min (_upper, v));
86  Changed (true, PBD::Controllable::UseGroup); /* EMIT SIGNAL */
87  }
88  return *this;
89  }
90 
91  bool operator==(const T& v) const {
92  return _value == v;
93  }
94 
95  bool operator<(const T& v) const {
96  return _value < v;
97  }
98 
99  bool operator<=(const T& v) const {
100  return _value <= v;
101  }
102 
103  bool operator>(const T& v) const {
104  return _value > v;
105  }
106 
107  bool operator>=(const T& v) const {
108  return _value >= v;
109  }
110 
111  operator T() const { return _value; }
112  T val() const { return _value; }
113 
114 protected:
119 };
120 
122 
124 {
125 public:
128 
129  bool display_to_user() const;
130 
131  void run (BufferSet& /*bufs*/, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t /*nframes*/, bool /*result_required*/);
132 
133  XMLNode& state () const;
134  int set_state (const XMLNode&, int /* version */);
135 
138 
139  void set_cut_all (bool);
140  void set_dim_all (bool);
141  void set_polarity (uint32_t, bool invert);
142  void set_cut (uint32_t, bool cut);
143  void set_dim (uint32_t, bool dim);
144  void set_solo (uint32_t, bool);
145  void set_mono (bool);
146 
147  gain_t dim_level() const { return _dim_level; }
148  gain_t solo_boost_level() const { return _solo_boost_level; }
149 
150  bool dimmed (uint32_t chn) const;
151  bool soloed (uint32_t chn) const;
152  bool inverted (uint32_t chn) const;
153  bool cut (uint32_t chn) const;
154  bool cut_all () const;
155  bool dim_all () const;
156  bool mono () const;
157 
158  bool monitor_active () const { return _monitor_active; }
159 
161 
162  std::shared_ptr<PBD::Controllable> channel_cut_control (uint32_t) const;
163  std::shared_ptr<PBD::Controllable> channel_dim_control (uint32_t) const;
164  std::shared_ptr<PBD::Controllable> channel_polarity_control (uint32_t) const;
165  std::shared_ptr<PBD::Controllable> channel_solo_control (uint32_t) const;
166 
167  std::shared_ptr<PBD::Controllable> dim_control () const { return _dim_all_control; }
168  std::shared_ptr<PBD::Controllable> cut_control () const { return _cut_all_control; }
169  std::shared_ptr<PBD::Controllable> mono_control () const { return _mono_control; }
170  std::shared_ptr<PBD::Controllable> dim_level_control () const { return _dim_level_control; }
171  std::shared_ptr<PBD::Controllable> solo_boost_control () const { return _solo_boost_level_control; }
172 
173 private:
174  struct ChannelRecord {
176 
177  /* pointers - created first, but managed by std::shared_ptr<> */
178 
183 
184  /* shared ptr access and lifetime management, for external users */
185 
186  std::shared_ptr<PBD::Controllable> cut_control;
187  std::shared_ptr<PBD::Controllable> dim_control;
188  std::shared_ptr<PBD::Controllable> polarity_control;
189  std::shared_ptr<PBD::Controllable> soloed_control;
190 
191  /* typed controllables for internal use */
192 
197 
198  ChannelRecord (uint32_t);
200  };
201 
202  std::vector<ChannelRecord*> _channels;
203 
204  uint32_t solo_cnt;
206 
207 
208  /* pointers - created first, but managed by std::shared_ptr<> */
209 
215 
216  /* shared ptr access and lifetime management, for external users */
217 
218  std::shared_ptr<PBD::Controllable> _dim_all_control;
219  std::shared_ptr<PBD::Controllable> _cut_all_control;
220  std::shared_ptr<PBD::Controllable> _mono_control;
221  std::shared_ptr<PBD::Controllable> _dim_level_control;
222  std::shared_ptr<PBD::Controllable> _solo_boost_level_control;
223 
224  /* typed controllables for internal use */
225 
231 
232  void allocate_channels (uint32_t);
234 };
235 
236 } /* namespace */
237 
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
PBD::Signal< void()> Changed
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)
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
Controllable(const std::string &name, Flag f=Flag(0))
std::string name() const
Definition: controllable.h:154
PBD::Signal< void(bool, PBD::Controllable::GroupControlDisposition)> Changed
Definition: controllable.h:149
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