Hi,
I’m looking for a way to modify an incoming OSC or MIDI value, and what I want is to have the options found in an envelope like those used in music; attack, decay, sustain and release.
My inital thought was to use the smooth envelope modifier, but I can’t get it to behave the way I want.
Is there a way to do this inside Notch? I’m currently looking at the expression modifier, but I’m not sure what to put in to get an ADSR function out of it.
So I got this from ChatGPT
var attackTime = 0.2;
var decayTime = 0.3;
var sustainLevel = 0.5;
var releaseTime = 0.4;
var attack = t < attackTime ? t / attackTime : 1.0;
var decay = t < (attackTime + decayTime) ? 1.0 - (1.0 - sustainLevel) * ((t - attackTime) / decayTime) : sustainLevel;
var release = t < (attackTime + decayTime + releaseTime) ? decay - (decay * (t - (attackTime + decayTime)) / releaseTime) : 0.0;
var result = attack * decay * release;
However, the expression modifier is hashed out in red. Any thoughts on how to move forward? I don’t know much about javascript, but maybe @ryan.barth, @jack-hale or @bent.stamnes does?
Hi,
The expression node does not use Javascript so the code you got from ChatGPT won’t work. It uses a simple math expression parser for single line expressions such as those described in the manual page here: Expression | Notch Manual 0.9.23
If you want to use Javascript then use the JS node ( JavaScript Node | Notch Manual 0.9.23) to calculate your result then feed the value into another node using the setFloat() API function: SetFloat() | Notch Manual 0.9.23 for example.
Hope that helps.
Regards,
Tom
Oh, I guess I got that mixed up hehe
Thanks for your help!
PS: please don’t tag individual team members when posting on the forum, because (as you can see), it’s not those whom you think can answer who actually has a good answer (plus, it’s just generally bad form