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
This commit is contained in:
parent
55c7a3bf01
commit
c0bb288ff1
@ -263,10 +263,10 @@ GainMeterBase::setup_gain_adjustment ()
|
||||
} else {
|
||||
_data_type = DataType::MIDI;
|
||||
gain_adjustment.set_lower (0.0);
|
||||
gain_adjustment.set_upper (2.0);
|
||||
gain_adjustment.set_step_increment (0.05);
|
||||
gain_adjustment.set_page_increment (0.1);
|
||||
gain_slider->set_default_value (1);
|
||||
gain_adjustment.set_upper (1.0);
|
||||
gain_adjustment.set_step_increment (1.0/128.0);
|
||||
gain_adjustment.set_page_increment (10.0/128.0);
|
||||
gain_slider->set_default_value (1.0);
|
||||
}
|
||||
|
||||
ignore_toggle = false;
|
||||
@ -396,18 +396,30 @@ GainMeterBase::gain_activated ()
|
||||
{
|
||||
float f;
|
||||
|
||||
if (sscanf (gain_display.get_text().c_str(), "%f", &f) == 1) {
|
||||
{
|
||||
// Switch to user's preferred locale so that
|
||||
// if they use different LC_NUMERIC conventions,
|
||||
// we will honor them.
|
||||
|
||||
/* clamp to displayable values */
|
||||
|
||||
f = min (f, 6.0f);
|
||||
|
||||
_amp->set_gain (dB_to_coefficient(f), this);
|
||||
|
||||
if (gain_display.has_focus()) {
|
||||
PublicEditor::instance().reset_focus();
|
||||
PBD::LocaleGuard lg ("");
|
||||
if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* clamp to displayable values */
|
||||
if (_data_type == DataType::AUDIO) {
|
||||
f = min (f, 6.0f);
|
||||
_amp->set_gain (dB_to_coefficient(f), this);
|
||||
} else {
|
||||
f = min (fabs (f), 127.0f);
|
||||
f = Amp::midi_velocity_factor_to_gain_coefficient (f/127.0f);
|
||||
_amp->set_gain (f, this);
|
||||
}
|
||||
|
||||
if (gain_display.has_focus()) {
|
||||
PublicEditor::instance().reset_focus();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -426,7 +438,7 @@ GainMeterBase::show_gain ()
|
||||
}
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
snprintf (buf, sizeof (buf), "%.1f", v);
|
||||
snprintf (buf, sizeof (buf), "%.0f", v * 127.0f);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -436,15 +448,14 @@ GainMeterBase::show_gain ()
|
||||
void
|
||||
GainMeterBase::gain_adjusted ()
|
||||
{
|
||||
gain_t value = 0;
|
||||
gain_t value;
|
||||
|
||||
switch (_data_type) {
|
||||
case DataType::AUDIO:
|
||||
/* convert from adjustment range (0..1) to gain coefficient */
|
||||
|
||||
if (_data_type == DataType::AUDIO) {
|
||||
value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain());
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
value = gain_adjustment.get_value ();
|
||||
break;
|
||||
} else {
|
||||
value = Amp::midi_velocity_factor_to_gain_coefficient (gain_adjustment.get_value());
|
||||
}
|
||||
|
||||
if (!ignore_toggle) {
|
||||
@ -468,7 +479,7 @@ GainMeterBase::effective_gain_display ()
|
||||
value = gain_to_slider_position_with_max (_amp->gain(), Config->get_max_gain());
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
value = _amp->gain ();
|
||||
value = Amp::gain_coefficient_to_midi_velocity_factor (_amp->gain ());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -102,7 +102,17 @@ public:
|
||||
}
|
||||
|
||||
std::string value_as_string (boost::shared_ptr<AutomationControl>) const;
|
||||
|
||||
|
||||
static const float max_gain_coefficient;
|
||||
|
||||
inline static float gain_coefficient_to_midi_velocity_factor (gain_t v) {
|
||||
return (v/max_gain_coefficient);
|
||||
}
|
||||
|
||||
inline static gain_t midi_velocity_factor_to_gain_coefficient (float v) {
|
||||
return v * max_gain_coefficient;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _denormal_protection;
|
||||
bool _apply_gain;
|
||||
|
Loading…
Reference in New Issue
Block a user