Enforce range and integer hints on ratio controls, for predictability

This commit is contained in:
Chris Cannam
2022-01-13 08:42:56 +00:00
parent 1460f39ad4
commit 41ba70fbb9

View File

@@ -496,10 +496,26 @@ RubberBandPitchShifter::activateImpl()
void void
RubberBandPitchShifter::updateRatio() RubberBandPitchShifter::updateRatio()
{ {
double oct = (m_octaves ? *m_octaves : 0.0); // The octaves, semitones, and cents parameters are supposed to be
oct += (m_semitones ? *m_semitones : 0.0) / 12; // integral: enforce that, just to avoid inconsistencies between
oct += (m_cents ? *m_cents : 0.0) / 1200; // hosts if some respect the hints more than others
m_ratio = pow(2.0, oct);
double octaves = round(m_octaves ? *m_octaves : 0.0);
if (octaves < -2.0) octaves = -2.0;
if (octaves > 2.0) octaves = 2.0;
double semitones = round(m_semitones ? *m_semitones : 0.0);
if (semitones < -12.0) semitones = -12.0;
if (semitones > 12.0) semitones = 12.0;
double cents = round(m_cents ? *m_cents : 0.0);
if (cents < -100.0) cents = -100.0;
if (cents > 100.0) cents = 100.0;
m_ratio = pow(2.0,
octaves +
semitones / 12.0 +
cents / 1200.0);
} }
void void