But if you’re using these things to trigger Synths or set values on running Synths, you can skip straight to using Pdef
- with Pbind
(for multi-voice synths - every event is a new voice), Pmono
(for strictly monophonic synths, played once and then every subsequent event just updates the parameters), or PmonoArtic
(a combination of the two, more in the documentation for this).
(
Pdefn(\freq, Pseq([100, 200, 300], inf));
Pdef(\synth, Pbind(
\instrument, SynthDef(\synth, {
var env, sig;
// A proper \gate control and freeSelf ensure the synth can be stopped
// and is cleaned up when it's done
env = Env.adsr.kr(gate:\gate.kr(1), doneAction: Done.freeSelf);
sig = \amp.kr(1) * env * Saw.ar(\freq.kr(100) + SinOsc.ar(16).range(-2, 2));
Out.ar(\out.kr(0), sig * [1, 1]);
}).add,
\freq, Pdefn(\freq);
)).play;
)
Note how you can change the value of Pdefn(\freq)
and it will be hot-swapped into your playing Pdef(\synth)
… Definitely read through the documentation of Event
and Pbind
if this is appealing, because there is some bookkeeping and automatic stuff being done for you here and it’s good to know what it is, else you might get some unexpected results.
And, if the Event
system is daunting to learn and you want to keep it simple, you can use the pattern things from above but simply play things yourself. Everything being played by a Pbind
ultimately calls it’s \play
function - this has access to all the Pbind keys as ~environmentVariables
. You can override this to do whatever you want. So the above example again, but a more “manual” approach with no magic 
(
Pdefn(\freq, Pseq([100, 200, 300], inf));
Pdef(\synth, Pbind(
\instrument, SynthDef(\synth, {
var env, sig;
env = Env.adsr.kr(gate:\gate.kr(1), doneAction: Done.freeSelf);
sig = \amp.kr(1) * env * Saw.ar(\freq.kr(100) + SinOsc.ar(16).range(-2, 2));
Out.ar(\out.kr(0), sig * [1, 1]);
}).add,
\freq, Pdefn(\freq),
\play, {
var synth = Synth(~instrument.asDefName, args:[\freq, ~freq]);
{ synth.release }.defer(0.4); // make sure to free it
}
)).play;
)