- // Meter what we have
- for (size_t n = 0; n < meterable; ++n) {
- _peak_power[n] = compute_peak (bufs.get_audio(n).data(nframes, offset), nframes, _peak_power[n]);
+ // 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;
+
+ // 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) {
+ 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) {
+ val = this_vel;
+ }
+ } else {
+ val += 1.0 / bufs.get_midi(n).capacity();
+ if (val > 1.0) {
+ val = 1.0;
+ }
+ }
+ }
+ _peak_power[n] = max (val, _peak_power[n]);
+ }
+
+ // 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]);