+ gain_t const dg = _gain_control->get_value();
+
+ if (_current_gain != dg) {
+
+ _current_gain = Amp::apply_gain (bufs, _session.nominal_frame_rate(), nframes, _current_gain, dg, _midi_amp);
+
+ } else if (_current_gain != GAIN_COEFF_UNITY) {
+
+ /* gain has not changed, but its non-unity */
+
+ if (_midi_amp) {
+ /* don't Trim midi velocity -- only relevant for Midi on Audio tracks */
+ for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
+
+ MidiBuffer& mb (*i);
+
+ for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
+ Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
+ if (ev.is_note_on()) {
+ ev.scale_velocity (fabsf (_current_gain));
+ }
+ }
+ }
+ }
+
+ for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
+ apply_gain_to_buffer (i->data(), nframes, _current_gain);
+ }
+ }
+ }
+ }
+
+ _active = _pending_active;
+}
+
+gain_t
+Amp::apply_gain (BufferSet& bufs, framecnt_t sample_rate, framecnt_t nframes, gain_t initial, gain_t target, bool midi_amp)
+{
+ /** Apply a (potentially) declicked gain to the buffers of @a bufs */
+ gain_t rv = target;
+
+ if (nframes == 0 || bufs.count().n_total() == 0) {
+ return initial;
+ }