move static scale_midi_velocity() function from Amp to Evoral::Event

This commit is contained in:
Paul Davis 2022-02-02 09:57:44 -07:00
parent 15f248975f
commit 2eadb75bd1
2 changed files with 10 additions and 10 deletions

View File

@ -72,13 +72,6 @@ Amp::configure_io (ChanCount in, ChanCount out)
return Processor::configure_io (in, out);
}
static void
scale_midi_velocity(Evoral::Event<MidiBuffer::TimeType>& ev, float factor)
{
factor = std::max(factor, 0.0f);
ev.set_velocity(std::min(127L, lrintf(ev.velocity() * factor)));
}
void
Amp::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t nframes, bool)
{
@ -103,7 +96,7 @@ Amp::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end_sampl
Evoral::Event<MidiBuffer::TimeType> ev = *m;
if (ev.is_note_on()) {
assert(ev.time() >= 0 && ev.time() < nframes);
scale_midi_velocity (ev, fabsf (gab[ev.time()]));
ev.scale_velocity (fabsf (gab[ev.time()]));
}
}
}
@ -222,7 +215,7 @@ Amp::apply_gain (BufferSet& bufs, samplecnt_t sample_rate, samplecnt_t nframes,
m = mb.erase (m);
continue;
} else if (ev.is_note_on()) {
scale_midi_velocity (ev, scale);
ev.scale_velocity (scale);
}
}
++m;
@ -306,7 +299,7 @@ Amp::apply_simple_gain (BufferSet& bufs, samplecnt_t nframes, gain_t target, boo
for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
Evoral::Event<MidiBuffer::TimeType> ev = *m;
if (ev.is_note_on()) {
scale_midi_velocity(ev, fabsf (target));
ev.scale_velocity (fabsf (target));
}
}
}

View File

@ -23,8 +23,10 @@
#ifndef EVORAL_EVENT_HPP
#define EVORAL_EVENT_HPP
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <sstream>
#include <stdint.h>
@ -179,6 +181,11 @@ public:
void set_cc_value(uint8_t val) { _buf[2] = val; }
void set_pgm_number(uint8_t num) { _buf[1] = num; }
void scale_velocity (float factor) {
factor = std::max (factor, 0.0f);
set_velocity (std::min (127L, lrintf (velocity() * factor)));
}
uint16_t value() const {
switch (type()) {
case MIDI_CMD_CONTROL: