How to Update Synthesiser Attack and Release

Hi!
I’m working on a Synthesiser plugin and I try to apply new values from slider for Release&Attack but I know I am not doing it the right way. What happen right now is that I don’t want to add the sound at all updates because it gonna fill the memory very quick and I know its wrong doing it like that lol.

void SimpleSynth::updateAttackRelease(double attack, double release)
{
addSound(new juce::SamplerSound(“default”, *audioReader, allNotes, 60, attack, release, 10.0));
}

it must have a way to update only attack and release?

I think what you want is SamplerSound::setEnvelopeParameters

Thanks! this is what i was looking for.
do you know how to use it?

I’m gonna jump into it now.

you just need to create an ADSR::Parameters struct and modify it such that the attack and release are the values passed into your method. Then you can call the setEnvelopeParameters method and pass in the modified ADSR struct

seem to be more then that… im looking into the juce doc and i see that the ADSR need to be properly initialized before using it.
i have try your suggestion and it doesn’t seem to work… What i have tried now is to fill the Parameters struct with some values then setEnvelopeParameters with my parameters on my SamplerSound and no change are made on the actual sound. look like i need to set setSampleRate from the ADSR and other things to do…

ADSR is the actual envelope class . ADSR::parameters is just a simple struct that holds 4 numbers. Sampler sound probably uses an ADSR object internally but I dont think you should have to mess with it. Looking at the sampler sound docs it really does seem like you just need to set the parameters and it would work. Can you post the code you tried? It could be something wrong with the way you are adding the sampler voice/sound

thanks a lot for your help! I got it working now :slight_smile:
I was doing it correctly just a tricky part to get my sound

for (int i = 0; i < synth.getNumSounds(); ++i)
{
if (auto sound = dynamic_cast<SamplerSound*>(synth.getSound(i).get()))
{
sound->setEnvelopeParameters(adsrParam);
}
}

1 Like

glad I could help : )