| @@ -71,6 +71,9 @@ public: | |||||
| sustainLevel = newParameters.sustain; | sustainLevel = newParameters.sustain; | ||||
| calculateRates (newParameters); | calculateRates (newParameters); | ||||
| if (currentState != State::idle) | |||||
| checkCurrentState(); | |||||
| } | } | ||||
| /** Returns the parameters currently being used by an ADSR object. | /** Returns the parameters currently being used by an ADSR object. | ||||
| @@ -115,9 +118,16 @@ public: | |||||
| if (currentState != State::idle) | if (currentState != State::idle) | ||||
| { | { | ||||
| if (releaseRate > 0.0f) | if (releaseRate > 0.0f) | ||||
| { | |||||
| if (currentState != State::sustain) | |||||
| releaseRate = static_cast<float> (envelopeVal / (currentParameters.release * sr)); | |||||
| currentState = State::release; | currentState = State::release; | ||||
| } | |||||
| else | else | ||||
| { | |||||
| reset(); | reset(); | ||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -205,6 +215,13 @@ private: | |||||
| releaseRate = (parameters.release > 0.0f ? static_cast<float> (sustainLevel / (parameters.release * sr)) : -1.0f); | releaseRate = (parameters.release > 0.0f ? static_cast<float> (sustainLevel / (parameters.release * sr)) : -1.0f); | ||||
| } | } | ||||
| void checkCurrentState() | |||||
| { | |||||
| if (currentState == State::attack && attackRate <= 0.0f) currentState = decayRate > 0.0f ? State::decay : State::sustain; | |||||
| else if (currentState == State::decay && decayRate <= 0.0f) currentState = State::sustain; | |||||
| else if (currentState == State::release && releaseRate <= 0.0f) reset(); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| enum class State { idle, attack, decay, sustain, release }; | enum class State { idle, attack, decay, sustain, release }; | ||||