[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Make a function into a synthdef



You could do it with an Event type, sure, but a single line Function would also do.
See a simplified example here. The crucial point is releasing the node at correct time. Normally you'd need the current id, which is uncomfortable. Instead you can use a new Group for every event and release the group.

(
SynthDef(\sin, { |out = 0, freq = 440, gate = 1, amp = 0.5, dur = 1|
    Out.ar(out, SinOsc.ar(freq, 0, amp) ! 2 * 
EnvGen.kr(Env.asr(0.01, 1, 0.01), gate, doneAction: 2)
);
}).add;

~off = { |e| s.makeBundle(e[\dur] * e[\legato] + s.latency, { e[\group].release }) }
)

(
p = Pbind(
\instrument, \sin,
\group, Pfunc { Group() },
\type, \on,
\dur, 0.5,
\midinote, Pseq((60..67), inf),
\legato, 0.5,
\off, Pfunc (~off)
).play
)

p.stop

In your example Instead of

{ e[\group].release } 

this should do

{ ~mainCaller.(note, 0) }

Side remark: for portability to other contexts I tend to write

topEnvironment[\mainCaller]

if ~mainCaller is defined in topEnvironment.

Regards

Daniel

-----------------------------
http://daniel-mayer.at
-----------------------------