add string_compose argument specializations so that empty std::string and empty C...
[ardour.git] / libs / ardour / monitor_processor.cc
index d12db38c27d042e117d93932b6e5cf2c4f10e42b..38ecc14e37e3ba6230a4d97f64cddf04f99d4553 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2010 Paul Davis
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include "pbd/convert.h"
 #include "pbd/error.h"
 #include "pbd/locale_guard.h"
@@ -163,9 +182,9 @@ MonitorProcessor::set_state (const XMLNode& node, int version)
 
                         if ((prop = (*i)->property ("cut")) != 0) {
                                 if (string_is_affirmative (prop->value())){
-                                        cr.cut = 0.0f;
+                                        cr.cut = GAIN_COEFF_ZERO;
                                 } else {
-                                        cr.cut = 1.0f;
+                                        cr.cut = GAIN_COEFF_UNITY;
                                 }
                         }
 
@@ -205,7 +224,7 @@ MonitorProcessor::set_state (const XMLNode& node, int version)
 XMLNode&
 MonitorProcessor::state (bool full)
 {
-       LocaleGuard lg (X_("POSIX"));
+       LocaleGuard lg (X_("C"));
         XMLNode& node (Processor::state (full));
         char buf[64];
 
@@ -237,8 +256,8 @@ MonitorProcessor::state (bool full)
                 snprintf (buf, sizeof (buf), "%u", chn);
                 chn_node->add_property ("id", buf);
 
-                chn_node->add_property (X_("cut"), (*x)->cut == 1.0f ? "no" : "yes");
-                chn_node->add_property (X_("invert"), (*x)->polarity == 1.0f ? "no" : "yes");
+                chn_node->add_property (X_("cut"), (*x)->cut == GAIN_COEFF_UNITY ? "no" : "yes");
+                chn_node->add_property (X_("invert"), (*x)->polarity == GAIN_COEFF_UNITY ? "no" : "yes");
                 chn_node->add_property (X_("dim"), (*x)->dim ? "yes" : "no");
                 chn_node->add_property (X_("solo"), (*x)->soloed ? "yes" : "no");
 
@@ -254,21 +273,21 @@ MonitorProcessor::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /
         uint32_t chn = 0;
         gain_t target_gain;
         gain_t dim_level_this_time = _dim_level;
-        gain_t global_cut = (_cut_all ? 0.0f : 1.0f);
-        gain_t global_dim = (_dim_all ? dim_level_this_time : 1.0);
+        gain_t global_cut = (_cut_all ? GAIN_COEFF_ZERO : GAIN_COEFF_UNITY);
+        gain_t global_dim = (_dim_all ? dim_level_this_time : GAIN_COEFF_UNITY);
         gain_t solo_boost;
 
         if (_session.listening() || _session.soloing()) {
                 solo_boost = _solo_boost_level;
         } else {
-                solo_boost = 1.0;
+                solo_boost = GAIN_COEFF_UNITY;
         }
 
         for (BufferSet::audio_iterator b = bufs.audio_begin(); b != bufs.audio_end(); ++b) {
 
                 /* don't double-scale by both track dim and global dim coefficients */
 
-                gain_t dim_level = (global_dim == 1.0 ? (_channels[chn]->dim ? dim_level_this_time : 1.0) : 1.0);
+                gain_t dim_level = (global_dim == GAIN_COEFF_UNITY ? (_channels[chn]->dim ? dim_level_this_time : GAIN_COEFF_UNITY) : GAIN_COEFF_UNITY);
                
                 if (_channels[chn]->soloed) {
                         target_gain = _channels[chn]->polarity * _channels[chn]->cut * dim_level * global_cut * global_dim * solo_boost;
@@ -276,14 +295,13 @@ MonitorProcessor::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /
                         if (solo_cnt == 0) {
                                 target_gain = _channels[chn]->polarity * _channels[chn]->cut * dim_level * global_cut * global_dim * solo_boost;
                         } else {
-                                target_gain = 0.0;
+                                target_gain = GAIN_COEFF_ZERO;
                         }
                 }
 
-                if (target_gain != _channels[chn]->current_gain || target_gain != 1.0f) {
+                if (target_gain != _channels[chn]->current_gain || target_gain != GAIN_COEFF_UNITY) {
 
-                        Amp::apply_gain (*b, nframes, _channels[chn]->current_gain, target_gain);
-                        _channels[chn]->current_gain = target_gain;
+                        _channels[chn]->current_gain = Amp::apply_gain (*b, _session.nominal_frame_rate(), nframes, _channels[chn]->current_gain, target_gain);
                 }
 
                 ++chn;
@@ -294,7 +312,7 @@ MonitorProcessor::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /
 
                 /* chn is now the number of channels, use as a scaling factor when mixing
                  */
-                gain_t scale = 1.0/chn;
+                gain_t scale = 1.f / (float)chn;
                 BufferSet::audio_iterator b = bufs.audio_begin();
                 AudioBuffer& ab (*b);
                 Sample* buf = ab.data();
@@ -336,7 +354,7 @@ MonitorProcessor::configure_io (ChanCount in, ChanCount out)
 }
 
 bool
-MonitorProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
+MonitorProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out)
 {
        out = in;
        return true;
@@ -362,9 +380,9 @@ void
 MonitorProcessor::set_cut (uint32_t chn, bool yn)
 {
         if (yn) {
-                _channels[chn]->cut = 0.0f;
+                _channels[chn]->cut = GAIN_COEFF_ZERO;
         } else {
-                _channels[chn]->cut = 1.0f;
+                _channels[chn]->cut = GAIN_COEFF_UNITY;
         }
 }
 
@@ -425,7 +443,7 @@ MonitorProcessor::inverted (uint32_t chn) const
 bool
 MonitorProcessor::cut (uint32_t chn) const
 {
-        return _channels[chn]->cut == 0.0f;
+        return _channels[chn]->cut == GAIN_COEFF_ZERO;
 }
 
 bool
@@ -489,10 +507,10 @@ MonitorProcessor::channel_solo_control (uint32_t chn) const
 }
 
 MonitorProcessor::ChannelRecord::ChannelRecord (uint32_t chn)
-       : current_gain (1.0)
+       : current_gain (GAIN_COEFF_UNITY)
        , cut_ptr (new MPControl<gain_t> (1.0, string_compose (_("cut control %1"), chn), PBD::Controllable::GainLike))
        , dim_ptr (new MPControl<bool> (false, string_compose (_("dim control"), chn), PBD::Controllable::Toggle))
-       , polarity_ptr (new MPControl<gain_t> (1.0, string_compose (_("polarity control"), chn), PBD::Controllable::Toggle))
+       , polarity_ptr (new MPControl<gain_t> (1.0, string_compose (_("polarity control"), chn), PBD::Controllable::Toggle, -1, 1))
        , soloed_ptr (new MPControl<bool> (false, string_compose (_("solo control"), chn), PBD::Controllable::Toggle))
 
        , cut_control (cut_ptr)