Hi everyone,
I’m trying to wrap my mind around on how could I pass the right amount of time to the Env
considering that I want the env long as \dur from the Pbindef?
While we wait for some more expert voices about Patterns, here are my discoveries:
Only the clock knows durations in seconds? Duration values are in beats up until EventStreamPlayer plays the event on the clock
However, synths get a \dur in beats from patterns. And you can pass the tempo along as well, so that you can do your conversion inside the synth:
// receives \dur in beats, \tempo in bps.
SynthDef(\beatEnv){ |out=0|
// convert dur in seconds
var dur = \dur.kr / \tempo.kr(1);
var env = EnvGen.kr(Env.perc,timeScale:dur);
dur.poll; // let's see some numbers in the post window
Out.kr(out, env);
}.add;
Pbindef(\p,\instrument,\beatEnv,
\tempo,Pfunc{thisThread.clock.tempo},
\dur,Pseq([1,2,3])
).trace.play;
// when changing tempo, synths get updated on the next event
TempoClock.default.tempo = 2;
TempoClock.default.tempo = 1;
I posted a slightly more advanced example of how to use envelope passing in a real workflow here:
Among other things, I’ve got a post-processing phase in \finish where I ensure all my Env parameters are actually Envs, and set their durations to 1…0. Then later, in the synth, I rescale them back to \sustain… this is a bit of a simplification, but I think it’s roughly the right approach for scaling env arguments, depending on use-case of course.