Add API to compute parameter delta, depending on AutomationType

This commit is contained in:
Robin Gareus 2017-06-20 23:41:05 +02:00
parent 37905d82a6
commit 16624f3139
2 changed files with 43 additions and 0 deletions

View File

@ -73,6 +73,10 @@ struct LIBARDOUR_API ParameterDescriptor : public Evoral::ParameterDescriptor
*/
float from_interface (float) const;
bool is_linear () const;
float compute_delta (float from, float to) const;
float apply_delta (float value, float delta) const;
/** Set step, smallstep, and largestep, based on current description. */
void update_steps();

View File

@ -354,4 +354,43 @@ ParameterDescriptor::from_interface (float val) const
return val;
}
bool
ParameterDescriptor::is_linear () const
{
if (logarithmic) {
return false;
}
switch(type) {
case GainAutomation:
case EnvelopeAutomation:
case BusSendLevel:
return false;
default:
break;
}
return true;
}
float
ParameterDescriptor::compute_delta (float from, float to) const
{
if (is_linear ()) {
return to - from;
}
if (from == 0) {
return 0;
}
return to / from;
}
float
ParameterDescriptor::apply_delta (float val, float delta) const
{
if (is_linear ()) {
return val + delta;
} else {
return val * delta;
}
}
} // namespace ARDOUR