From 88ce956dd3724f1a08fc97b33c5e284e45e86cf8 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sat, 28 Dec 2019 22:39:20 +0100 Subject: [PATCH] Clamp the values in range for velocity and CC switched envelopes --- src/sfizz/EGDescription.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sfizz/EGDescription.h b/src/sfizz/EGDescription.h index 66c6c820..da35fa8d 100644 --- a/src/sfizz/EGDescription.h +++ b/src/sfizz/EGDescription.h @@ -79,7 +79,7 @@ struct EGDescription */ float getAttack(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccAttack, attack) + normalizeVelocity(velocity)*vel2attack; + return Default::egTimeRange.clamp(ccSwitchedValue(ccValues, ccAttack, attack) + normalizeVelocity(velocity)*vel2attack); } /** * @brief Get the decay with possibly a CC modifier and a velocity modifier @@ -90,7 +90,7 @@ struct EGDescription */ float getDecay(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccDecay, decay) + normalizeVelocity(velocity)*vel2decay; + return Default::egTimeRange.clamp(ccSwitchedValue(ccValues, ccDecay, decay) + normalizeVelocity(velocity)*vel2decay); } /** * @brief Get the delay with possibly a CC modifier and a velocity modifier @@ -101,7 +101,7 @@ struct EGDescription */ float getDelay(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccDelay, delay) + normalizeVelocity(velocity)*vel2delay; + return Default::egTimeRange.clamp(ccSwitchedValue(ccValues, ccDelay, delay) + normalizeVelocity(velocity)*vel2delay); } /** * @brief Get the holding duration with possibly a CC modifier and a velocity modifier @@ -112,7 +112,7 @@ struct EGDescription */ float getHold(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccHold, hold) + normalizeVelocity(velocity)*vel2hold; + return Default::egTimeRange.clamp(ccSwitchedValue(ccValues, ccHold, hold) + normalizeVelocity(velocity)*vel2hold); } /** * @brief Get the release duration with possibly a CC modifier and a velocity modifier @@ -123,7 +123,7 @@ struct EGDescription */ float getRelease(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccRelease, release) + normalizeVelocity(velocity)*vel2release; + return Default::egTimeRange.clamp(ccSwitchedValue(ccValues, ccRelease, release) + normalizeVelocity(velocity)*vel2release); } /** * @brief Get the starting level with possibly a CC modifier and a velocity modifier @@ -134,7 +134,7 @@ struct EGDescription */ float getStart(const SfzCCArray &ccValues, uint8_t velocity [[maybe_unused]]) const noexcept { - return ccSwitchedValue(ccValues, ccStart, start); + return Default::egPercentRange.clamp(ccSwitchedValue(ccValues, ccStart, start)); } /** * @brief Get the sustain level with possibly a CC modifier and a velocity modifier @@ -145,7 +145,7 @@ struct EGDescription */ float getSustain(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccSustain, sustain) + normalizeVelocity(velocity)*vel2sustain; + return Default::egPercentRange.clamp(ccSwitchedValue(ccValues, ccSustain, sustain) + normalizeVelocity(velocity)*vel2sustain); } LEAK_DETECTOR(EGDescription); };