3 #include "ardour/amp.h"
5 #include "ardour/audio_buffer.h"
6 #include "ardour/monitor_processor.h"
7 #include "ardour/session.h"
11 using namespace ARDOUR;
14 MonitorProcessor::MonitorProcessor (Session& s)
15 : Processor (s, X_("MonitorOut"))
21 _solo_boost_level = 1.0;
24 MonitorProcessor::MonitorProcessor (Session& s, const XMLNode& node)
27 set_state (node, Stateful::loading_state_version);
31 MonitorProcessor::set_state (const XMLNode& node, int version)
33 return Processor::set_state (node, version);
37 MonitorProcessor::state (bool full)
39 XMLNode& node (Processor::state (full));
41 /* this replaces any existing "type" property */
43 node.add_property (X_("type"), X_("monitor"));
49 MonitorProcessor::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_frame*/, nframes_t nframes, bool /*result_required*/)
53 gain_t dim_level_this_time = _dim_level;
54 gain_t global_cut = (_cut_all ? 0.0f : 1.0f);
55 gain_t global_dim = (_dim_all ? dim_level_this_time : 1.0f);
58 if (_session.listening() || _session.soloing()) {
59 solo_boost = _solo_boost_level;
64 for (BufferSet::audio_iterator b = bufs.audio_begin(); b != bufs.audio_end(); ++b) {
66 /* don't double-scale by both track dim and global dim coefficients */
68 gain_t dim_level = (global_dim == 1.0 ? (_dim[chn] ? dim_level_this_time : 1.0) : 1.0);
71 target_gain = _polarity[chn] * _cut[chn] * dim_level * global_cut * global_dim * solo_boost;
74 target_gain = _polarity[chn] * _cut[chn] * dim_level * global_cut * global_dim * solo_boost;
80 if (target_gain != current_gain[chn] || target_gain != 1.0f) {
82 Amp::apply_gain (*b, nframes, current_gain[chn], target_gain);
83 current_gain[chn] = target_gain;
90 /* chn is now the number of channels, use as a scaling factor when mixing
92 gain_t scale = 1.0/chn;
93 BufferSet::audio_iterator b = bufs.audio_begin();
95 Sample* buf = ab.data();
97 /* scale the first channel */
99 for (nframes_t n = 0; n < nframes; ++n) {
103 /* add every other channel into the first channel's buffer */
106 for (; b != bufs.audio_end(); ++b) {
107 AudioBuffer& ob (*b);
108 Sample* obuf = ob.data ();
109 for (nframes_t n = 0; n < nframes; ++n) {
110 buf[n] += obuf[n] * scale;
114 /* copy the first channel to every other channel's buffer */
116 b = bufs.audio_begin();
118 for (; b != bufs.audio_end(); ++b) {
119 AudioBuffer& ob (*b);
120 Sample* obuf = ob.data ();
121 memcpy (obuf, buf, sizeof (Sample) * nframes);
127 MonitorProcessor::configure_io (ChanCount in, ChanCount out)
129 uint32_t needed = in.n_audio();
131 while (current_gain.size() > needed) {
132 current_gain.pop_back ();
135 _polarity.pop_back ();
137 if (_soloed.back()) {
146 while (current_gain.size() < needed) {
147 current_gain.push_back (1.0);
148 _dim.push_back (false);
149 _cut.push_back (1.0);
150 _polarity.push_back (1.0);
151 _soloed.push_back (false);
154 return Processor::configure_io (in, out);
158 MonitorProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
164 MonitorProcessor::set_polarity (uint32_t chn, bool invert)
167 _polarity[chn] = -1.0f;
169 _polarity[chn] = 1.0f;
174 MonitorProcessor::set_dim (uint32_t chn, bool yn)
180 MonitorProcessor::set_cut (uint32_t chn, bool yn)
190 MonitorProcessor::set_solo (uint32_t chn, bool solo)
204 MonitorProcessor::set_mono (bool yn)
210 MonitorProcessor::set_cut_all (bool yn)
216 MonitorProcessor::set_dim_all (bool yn)
222 MonitorProcessor::display_to_user () const
228 MonitorProcessor::set_dim_level (gain_t val)
234 MonitorProcessor::set_solo_boost_level (gain_t val)
236 _solo_boost_level = val;
240 MonitorProcessor::soloed (uint32_t chn) const
247 MonitorProcessor::inverted (uint32_t chn) const
249 return _polarity[chn] < 0.0f;
254 MonitorProcessor::cut (uint32_t chn) const
256 return _cut[chn] == 0.0f;
260 MonitorProcessor::dimmed (uint32_t chn) const
266 MonitorProcessor::mono () const