mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Ensure that the current state is valid when calling ADSR::setParameters() after calling ADSR::noteOn() and recalculate the release rate if ADSR::noteOff() is called when not in the sustain stage
This commit is contained in:
parent
4c58efa407
commit
55bc08f3cd
1 changed files with 17 additions and 0 deletions
|
|
@ -71,6 +71,9 @@ public:
|
|||
|
||||
sustainLevel = newParameters.sustain;
|
||||
calculateRates (newParameters);
|
||||
|
||||
if (currentState != State::idle)
|
||||
checkCurrentState();
|
||||
}
|
||||
|
||||
/** Returns the parameters currently being used by an ADSR object.
|
||||
|
|
@ -115,9 +118,16 @@ public:
|
|||
if (currentState != State::idle)
|
||||
{
|
||||
if (releaseRate > 0.0f)
|
||||
{
|
||||
if (currentState != State::sustain)
|
||||
releaseRate = static_cast<float> (envelopeVal / (currentParameters.release * sr));
|
||||
|
||||
currentState = State::release;
|
||||
}
|
||||
else
|
||||
{
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -205,6 +215,13 @@ private:
|
|||
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 };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue