Move event specific ringbuffer stuff to evoral.
[ardour.git] / libs / ardour / meter.cc
index fb8dafbc7b9437e759b010585d5a93b7bc68c1cb..5dee1d98451d9089d80c44e1e34ccac3aecad3ce 100644 (file)
@@ -23,7 +23,6 @@
 #include <ardour/peak.h>
 #include <ardour/dB.h>
 #include <ardour/session.h>
-#include <ardour/midi_events.h>
 
 namespace ARDOUR {
 
@@ -34,24 +33,23 @@ namespace ARDOUR {
  * be set to 0.
  */
 void
-PeakMeter::run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
+PeakMeter::run_in_place (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
 {
-       size_t meterable = std::min(bufs.count().n_total(), _peak_power.size());
+       size_t meterable = std::min((size_t)bufs.count().n_total(), _peak_power.size());
 
        size_t n = 0;
 
        // Meter what we have (midi)
        for ( ; n < meterable && n < bufs.count().n_midi(); ++n) {
-               
+       
                float val = 0;
                
                // GUI needs a better MIDI meter, not much information can be
                // expressed through peaks alone
-               const unsigned n_events = bufs.get_midi(n).size();
-               for (size_t i=0; i < n_events; ++i) {
-                       const MidiEvent& ev = bufs.get_midi(n)[i];
-                       if ((ev.buffer[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
-                               const float this_vel = log(ev.buffer[2] / 127.0 * (M_E*M_E-M_E) + M_E) - 1.0;
+               for (MidiBuffer::iterator i = bufs.get_midi(n).begin(); i != bufs.get_midi(n).end(); ++i) {
+                       const Evoral::MIDIEvent& ev = *i;
+                       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;
                                //printf("V %d -> %f\n", (int)((Byte)ev.buffer[2]), this_vel);
                                if (this_vel > val)
                                        val = this_vel;
@@ -97,8 +95,9 @@ bool
 PeakMeter::configure_io (ChanCount in, ChanCount out)
 {
        /* we're transparent no matter what.  fight the power. */
-       if (out != in)
+       if (out != in) {
                return false;
+       }
 
        uint32_t limit = in.n_total();
 
@@ -118,9 +117,7 @@ PeakMeter::configure_io (ChanCount in, ChanCount out)
        assert(_visible_peak_power.size() == limit);
        assert(_max_peak_power.size() == limit);
 
-       Processor::configure_io(in, out);
-
-       return true;
+       return Processor::configure_io (in, out);
 }
 
 /** To be driven by the Meter signal from IO.