Revert my revision 6996, which was wrong. Sources need to stay around in the session...
[ardour.git] / libs / ardour / meter.cc
index e8512aa5932706ffb09bbde0dfa7545dfb6ba111..98c46067c7dfcfb6a5b67de50966ebfc44162937 100644 (file)
@@ -1,16 +1,16 @@
 /*
-    Copyright (C) 2006 Paul Davis 
-    
+    Copyright (C) 2006 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.
@@ -31,39 +31,7 @@ using namespace std;
 
 using namespace ARDOUR;
 
-sigc::signal<void> Metering::Meter;
-Glib::StaticMutex  Metering::m_meter_signal_lock;
-
-sigc::connection
-Metering::connect (sigc::slot<void> the_slot)
-{
-       // SignalProcessor::Meter is emitted from another thread so the
-       // Meter signal must be protected.
-       Glib::Mutex::Lock guard (m_meter_signal_lock);
-       return Meter.connect (the_slot);
-}
-
-void
-Metering::disconnect (sigc::connection& c)
-{
-       Glib::Mutex::Lock guard (m_meter_signal_lock);
-       c.disconnect ();
-}
-
-/**
-    Update the meters.
-
-    The meter signal lock is taken to prevent modification of the 
-    Meter signal while updating the meters, taking the meter signal
-    lock prior to taking the io_lock ensures that all IO will remain 
-    valid while metering.
-*/   
-void
-Metering::update_meters()
-{
-       Glib::Mutex::Lock guard (m_meter_signal_lock);
-       Meter(); /* EMIT SIGNAL */
-}
+PBD::Signal0<void> Metering::Meter;
 
 /** Get peaks from @a bufs
  * Input acceptance is lenient - the first n buffers from @a bufs will
@@ -71,7 +39,7 @@ Metering::update_meters()
  * be set to 0.
  */
 void
-PeakMeter::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
+PeakMeter::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_frame*/, nframes_t nframes, bool)
 {
        if (!_active && !_pending_active) {
                return;
@@ -79,9 +47,9 @@ PeakMeter::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfr
 
        const uint32_t n_audio = min(_configured_input.n_audio(), bufs.count().n_audio());
        const uint32_t n_midi  = min(_configured_input.n_midi(), bufs.count().n_midi());
-       
+
        uint32_t n = 0;
-       
+
        // Meter MIDI in to the first n_midi peaks
        for (uint32_t i = 0; i < n_midi; ++i, ++n) {
                float val = 0.0f;
@@ -104,7 +72,7 @@ PeakMeter::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfr
 
        // Meter audio in to the rest of the peaks
        for (uint32_t i = 0; i < n_audio; ++i, ++n) {
-               _peak_power[n] = compute_peak (bufs.get_audio(i).data(), nframes, _peak_power[n]); 
+               _peak_power[n] = compute_peak (bufs.get_audio(i).data(), nframes, _peak_power[n]);
        }
 
        // Zero any excess peaks
@@ -115,11 +83,6 @@ PeakMeter::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfr
        _active = _pending_active;
 }
 
-PeakMeter::PeakMeter (Session& s, const XMLNode& node)
-       : Processor (s, node)
-{
-}
-
 void
 PeakMeter::reset ()
 {
@@ -149,9 +112,25 @@ PeakMeter::configure_io (ChanCount in, ChanCount out)
        if (out != in) { // always 1:1
                return false;
        }
-       
-       uint32_t limit = in.n_total();
-       
+
+       current_meters = in;
+
+        reset_max_channels (in);
+
+       return Processor::configure_io (in, out);
+}
+
+void
+PeakMeter::reflect_inputs (const ChanCount& in)
+{
+       current_meters = in;
+}
+
+void
+PeakMeter::reset_max_channels (const ChanCount& chn)
+{
+       uint32_t limit = chn.n_total();
+
        while (_peak_power.size() > limit) {
                _peak_power.pop_back();
                _visible_peak_power.pop_back();
@@ -167,8 +146,6 @@ PeakMeter::configure_io (ChanCount in, ChanCount out)
        assert(_peak_power.size() == limit);
        assert(_visible_peak_power.size() == limit);
        assert(_max_peak_power.size() == limit);
-
-       return Processor::configure_io (in, out);
 }
 
 /** To be driven by the Meter signal from IO.
@@ -185,27 +162,27 @@ PeakMeter::meter ()
 
        assert(_visible_peak_power.size() == _peak_power.size());
 
-       const size_t limit = _peak_power.size();
+       const size_t limit = min (_peak_power.size(), (size_t) current_meters.n_total ());
 
        for (size_t n = 0; n < limit; ++n) {
 
                /* grab peak since last read */
 
-               float new_peak = _peak_power[n]; /* XXX we should use atomic exchange from here ... */
+               float new_peak = _peak_power[n]; /* XXX we should use atomic exchange from here ... */
                _peak_power[n] = 0;              /* ... to here */
 
                /* compute new visible value using falloff */
 
                if (new_peak > 0.0) {
-                       new_peak = coefficient_to_dB (new_peak);
+                       new_peak = fast_coefficient_to_dB (new_peak);
                } else {
                        new_peak = minus_infinity();
                }
-               
+
                /* update max peak */
-               
+
                _max_peak_power[n] = std::max (new_peak, _max_peak_power[n]);
-               
+
                if (Config->get_meter_falloff() == 0.0f || new_peak > _visible_peak_power[n]) {
                        _visible_peak_power[n] = new_peak;
                } else {
@@ -225,8 +202,3 @@ PeakMeter::state (bool full_state)
 }
 
 
-bool
-PeakMeter::visible() const
-{
-       return true;
-}