add virtual Delivery::pan_outs() so that internal sends correctly configure their...
[ardour.git] / libs / ardour / meter.cc
index 4ad0f585805092d7750051e58743744d67bdeb03..6cdcffb8b65ba807ded984d5aad545206224c01c 100644 (file)
@@ -31,45 +31,7 @@ using namespace std;
 
 using namespace ARDOUR;
 
-boost::signals2::signal<void()> Metering::Meter;
-Glib::StaticMutex  Metering::m_meter_signal_lock;
-
-boost::signals2::connection
-Metering::connect (boost::function<void()> f)
-{
-       // 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 (f);
-}
-
-void
-Metering::disconnect (boost::signals2::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 */
-}
-
-PeakMeter::PeakMeter (Session& s, const XMLNode& node)
-       : Processor (s, node)
-{
-       current_meters = 0;
-}
+PBD::Signal0<void> Metering::Meter;
 
 /** Get peaks from @a bufs
  * Input acceptance is lenient - the first n buffers from @a bufs will
@@ -77,14 +39,16 @@ PeakMeter::PeakMeter (Session& s, const XMLNode& node)
  * be set to 0.
  */
 void
-PeakMeter::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_frame*/, nframes_t nframes, bool)
+PeakMeter::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t nframes, bool)
 {
        if (!_active && !_pending_active) {
                return;
        }
 
-       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());
+       // cerr << "meter " << name() << " runs with " << bufs.available() << " inputs\n";
+
+       const uint32_t n_audio = min (current_meters.n_audio(), bufs.count().n_audio());
+       const uint32_t n_midi  = min (current_meters.n_midi(), bufs.count().n_midi());
 
        uint32_t n = 0;
 
@@ -92,7 +56,7 @@ PeakMeter::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_fram
        for (uint32_t i = 0; i < n_midi; ++i, ++n) {
                float val = 0.0f;
                for (MidiBuffer::iterator e = bufs.get_midi(i).begin(); e != bufs.get_midi(i).end(); ++e) {
-                       const Evoral::MIDIEvent<nframes_t> ev(*e, false);
+                       const Evoral::MIDIEvent<framepos_t> ev(*e, false);
                        if (ev.is_note_on()) {
                                const float this_vel = log(ev.buffer()[2] / 127.0 * (M_E*M_E-M_E) + M_E) - 1.0;
                                if (this_vel > val) {
@@ -105,7 +69,7 @@ PeakMeter::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_fram
                                }
                        }
                }
-               _peak_power[n] = val;
+               _peak_power[n] = max (val, _peak_power[n]);
        }
 
        // Meter audio in to the rest of the peaks
@@ -151,7 +115,9 @@ PeakMeter::configure_io (ChanCount in, ChanCount out)
                return false;
        }
 
-       current_meters = in.n_total ();
+       current_meters = in;
+
+       reset_max_channels (in);
 
        return Processor::configure_io (in, out);
 }
@@ -159,13 +125,13 @@ PeakMeter::configure_io (ChanCount in, ChanCount out)
 void
 PeakMeter::reflect_inputs (const ChanCount& in)
 {
-       current_meters = in.n_total ();
+       current_meters = in;
 }
 
 void
 PeakMeter::reset_max_channels (const ChanCount& chn)
 {
-       uint32_t limit = chn.n_total();
+       uint32_t const limit = chn.n_total();
 
        while (_peak_power.size() > limit) {
                _peak_power.pop_back();
@@ -198,7 +164,7 @@ PeakMeter::meter ()
 
        assert(_visible_peak_power.size() == _peak_power.size());
 
-       const size_t limit = min (_peak_power.size(), (size_t) current_meters);
+       const size_t limit = min (_peak_power.size(), (size_t) current_meters.n_total ());
 
        for (size_t n = 0; n < limit; ++n) {