Yesterday I had problems understanding why does a SynthDef and it’s Synth instance complain when it’s envelope duration is shorter than duration \dur
. The following code will produce FAILURE IN SERVER /n_set Node 1067 not found
complaints in the post window.
|
// an example of undefined sustain resulting in FAILURE IN SERVER ( // define a simple synth SynthDef(\bip, { |out=0, freq=440, gate=1, amp=0.3| var sig, env; env = Env.linen(0.01, 1, 0.1); sig = Pulse.ar(freq, 0.3) * EnvGen.kr(env, gate, doneAction:2); Out.ar(out, sig * amp); }).add; ) ( // define a simple pattern Pbind( \instrument, \bip, \degree, Pseq([0, 2, 3], inf), \dur, Pseq([1, 2], inf) ).play; ) |
The sound will be generated fine, but the problem is that the doneAction and sustain value in Env.linen result in the Synth instance being freed before Pbind does it. So when Pbind does tries to free it, it’s already gone, it doesn’t exist anymore.
I asked nice SC people on SC FB group and the answer led me to understand that there’s a good use of\sustain
parameter in Pbind, which deals with exactly that. So to properly control sustain time, an example shows how it can be done:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
( SynthDef(\beeps, { arg amp = 0.8, gate = 1, sustain = 1, release = 0.3, freq = 440; var sig, env; env = Env.linen(attackTime:0.01, sustainTime: sustain, releaseTime: release); sig = Pulse.ar([freq,freq*0.001], 0.5) * amp * EnvGen.kr(env, gate, doneAction:2); Out.ar(0, sig * amp); }).add ) ( Pdef(\beepsin, Pbind( \instrument, \beeps, [\degree, \dur], Pseq([[0, 0.5], [2, 0.1], [3, 0.1], [2, 0.1], [5, 1], [Rest, Rest]], inf), //\sustain, 0.1, //\legato, 0.05, \release, 0.1, \amp, 0.1 )); ) Pdef(\beepsin).play; |
It seems like the most important part is that the SynthDef has a sustain argument. Pbind will calculate sustain from \dur
so that it doesn’t even have to be defined in the Pbind.
There’s a nice thing used above, which I was looking for a while – how to defined note and it’s duration in pairs instead of on separate lines for each parameter: [\degree, \dur]
and what follows is a list of pairs.