remove xmmintrin.h, unnecessarily mirroring changes to master
[ardour.git] / libs / ardour / meter.cc
index 1ea3a090dd880dd1e89247ece87c35d6cfc5d03f..4d096aae89118c23f2254776c838e6788f24f007 100644 (file)
     675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include "ardour/meter.h"
 #include <algorithm>
 #include <cmath>
+
+#include "pbd/compose.h"
+
+#include "ardour/audio_buffer.h"
 #include "ardour/buffer_set.h"
-#include "ardour/peak.h"
 #include "ardour/dB.h"
-#include "ardour/session.h"
+#include "ardour/meter.h"
 #include "ardour/midi_buffer.h"
-#include "ardour/audio_buffer.h"
+#include "ardour/rc_configuration.h"
 #include "ardour/runtime_functions.h"
 
 using namespace std;
@@ -33,6 +35,12 @@ using namespace ARDOUR;
 
 PBD::Signal0<void> Metering::Meter;
 
+PeakMeter::PeakMeter (Session& s, const std::string& name)
+    : Processor (s, string_compose ("meter-%1", name)) 
+{
+}
+
+
 /** Get peaks from @a bufs
  * Input acceptance is lenient - the first n buffers from @a bufs will
  * be metered, where n was set by the last call to setup(), excess meters will
@@ -45,6 +53,8 @@ PeakMeter::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_fr
                return;
        }
 
+       // 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());
 
@@ -53,7 +63,9 @@ PeakMeter::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_fr
        // Meter MIDI in to the first n_midi peaks
        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) {
+               MidiBuffer& buf (bufs.get_midi(i));
+               
+               for (MidiBuffer::iterator e = buf.begin(); e != buf.end(); ++e) {
                        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;
@@ -115,7 +127,7 @@ PeakMeter::configure_io (ChanCount in, ChanCount out)
 
        current_meters = in;
 
-        reset_max_channels (in);
+       reset_max_channels (in);
 
        return Processor::configure_io (in, out);
 }
@@ -124,6 +136,20 @@ void
 PeakMeter::reflect_inputs (const ChanCount& in)
 {
        current_meters = in;
+
+       const size_t limit = min (_peak_power.size(), (size_t) current_meters.n_total ());
+       const size_t n_midi  = min (_peak_power.size(), (size_t) current_meters.n_midi());
+
+       for (size_t n = 0; n < limit; ++n) {
+               if (n < n_midi) {
+                       _visible_peak_power[n] = 0;
+               } else {
+                       _visible_peak_power[n] = -INFINITY;
+               }
+       }
+       reset_max();
+
+       ConfigurationChanged (in, in); /* EMIT SIGNAL */
 }
 
 void