summaryrefslogtreecommitdiff
path: root/libs/ardour/amp.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-11-13 17:47:39 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-11-13 17:47:39 +0000
commitc0bb288ff148274bd258562b0c718aa5e009cca0 (patch)
treebbc0c9f9c2757e73d01e5fe2e10e7812a96ebd5b /libs/ardour/amp.cc
parent55c7a3bf01ddbc22620eccbf682f5094e6be97e3 (diff)
change handling of MIDI gain so that we present a linear fader spanning 0..127. this is based on the realization that we actually have no idea what the MIDI receiver will do with velocity and/or CC #7 values, and so trying to pretend that we can provide some kind of dB value in the display or the behaviour of the fader is completely wrong; ALSO: fix keyboard entry of fader levels for non EN locales (#5027)
git-svn-id: svn://localhost/ardour2/branches/3.0@13480 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/amp.cc')
-rw-r--r--libs/ardour/amp.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc
index d68f73ef3e..c0cd404cf6 100644
--- a/libs/ardour/amp.cc
+++ b/libs/ardour/amp.cc
@@ -33,6 +33,10 @@
using namespace ARDOUR;
using namespace PBD;
+using std::min;
+
+/* gain range of -inf to +6dB, default 0dB */
+const float Amp::max_gain_coefficient = 1.99526231f;
Amp::Amp (Session& s)
: Processor(s, "Amp")
@@ -42,8 +46,7 @@ Amp::Amp (Session& s)
, _gain_automation_buffer(0)
{
Evoral::Parameter p (GainAutomation);
- /* gain range of -inf to +6dB, default 0dB */
- p.set_range (0, 1.99526231f, 1, false);
+ p.set_range (0, max_gain_coefficient, 1, false);
boost::shared_ptr<AutomationList> gl (new AutomationList (p));
_gain_control = boost::shared_ptr<GainControl> (new GainControl (X_("gaincontrol"), s, this, p, gl));
_gain_control->set_flags (Controllable::GainLike);
@@ -114,11 +117,12 @@ Amp::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/,
for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
MidiBuffer& mb (*i);
-
+ const float midi_velocity_factor = gain_coefficient_to_midi_velocity_factor (_current_gain);
+
for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
if (ev.is_note_on()) {
- ev.scale_velocity (_current_gain);
+ ev.scale_velocity (midi_velocity_factor);
}
}
}
@@ -172,8 +176,8 @@ Amp::apply_gain (BufferSet& bufs, framecnt_t nframes, gain_t initial, gain_t tar
Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
if (ev.is_note_on()) {
- gain_t scale = delta * (ev.time()/(double) nframes);
- ev.scale_velocity (initial+scale);
+ const gain_t scale = delta * (ev.time()/(double) nframes);
+ ev.scale_velocity (gain_coefficient_to_midi_velocity_factor (initial+scale));
}
}
}
@@ -331,11 +335,12 @@ Amp::apply_simple_gain (BufferSet& bufs, framecnt_t nframes, gain_t target)
for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
MidiBuffer& mb (*i);
+ const float midi_velocity_factor = gain_coefficient_to_midi_velocity_factor (target);
for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
if (ev.is_note_on()) {
- ev.scale_velocity (target);
+ ev.scale_velocity (midi_velocity_factor);
}
}
}
@@ -371,10 +376,7 @@ Amp::inc_gain (gain_t factor, void *src)
void
Amp::set_gain (gain_t val, void *src)
{
- // max gain at about +6dB (10.0 ^ ( 6 dB * 0.05))
- if (val > 1.99526231f) {
- val = 1.99526231f;
- }
+ val = min (val, max_gain_coefficient);
if (src != _gain_control.get()) {
_gain_control->set_value (val);