I came across some wired behaviour were I wanted to overwrite the ADSR Parameters and start over. I did this by just calling setParameters and noteOn.
But if the first set of parameters doesn’t have an attack phase and the second does, the envelopeVal stays at the sustain/decay level, since it is not being set to zero in noteOn.
I ended up just calling reset first, but for me this bug was not only hard to find, but also hard to spot that there was something not going as planed. I think it would be a good addition to make the ADSR class more fool proof.
void noteOn() noexcept
{
if (attackRate > 0.0f)
{
envelopeVal = 0.0f;
state = State::attack;
}
else if (decayRate > 0.0f)
{
envelopeVal = 1.0f;
state = State::decay;
}
else
{
envelopeVal = parameters.sustain;
state = State::sustain;
}
}
(line 5 is the addition I’m proposing)
