Hello and apologies if the following seems a bit chaotic.
Here is the context, followed by the questions:
I have several Synths, which I am playing with Pdefs.
My goal is to create a looping sequence with these Pdefs.
Inside that routine, I would like to play and stop these synths multiple times, sometimes varying one or more parameters.
And here begin the queries:
First of all, I’m trying to figure out if what I need is a Routine, or a Tdef (or both?).
Also, are Pdefs what I should be using, or would Ndefs be more fitting?
Moreover, I’m trying to figure out a syntax where I do not need to write the whole synth each time I want to change one parameter, but instead only call that one parameter that I want to alter.
Something like
z = SynthDef(\name)
z.set(\trig, 1)
And finally, I would like to be able to set a fadeTime in order for the Synths not to start or stop abruptly - and it would be great if I could do that without changing the parameters of the synth (like for example the attack or release of the envelope). Something like the global variable syntax
~synth1.fadeTime = 5;
I’ve tried several combinations of these, some partially working, none successful.
Here are a couple of these synths and a (non-functioning) template of what it could look like:
/* First synth: */
(
SynthDef(\bazz, {
arg freq=60, cutFreq=600, rq=0.4, amp=0.7, atk=0.01, rel=0.1, mod=1, pan=0, out=0;
var sig, env;
env = EnvGen.ar(Env([0,1,0], [atk, rel]), doneAction:2);
sig = Pan2.ar([Saw.ar(freq, 0.4), Saw.ar(freq+mod, 0.4)], pan) * env;
sig = RLPF.ar(sig, cutFreq, rq);
Out.ar(out, sig * amp);
}).add;
)
(
~pbazz = Pdef(\pbazz,
Pbind(
\instrument, \bazz,
\freq, Pwhite(49.0, 51.0),
\cutFreq, 100,
\rq, Pwhite(0.03, 0.7),
\atk, Pwhite(2.5, 6),
\rel, Pwhite(5.0, 10.0),
\dur, Pkey(\rel),
\mod, Prand([1, 2], inf),
\pan, Pwhite(-0.9, 0.9,inf),
\amp, 0.1,
\out,0,
));
)
/* 2nd: */
(
SynthDef(\grain, {
arg buf=0, rate=1, start=0, amp=0.5, dur=0.3, rel=0.1, pan=0, gate=1;
var sig, env, pos;
env = EnvGen.kr(
Env.asr(0.01, amp, rel),
gate: gate,
doneAction: 2
);
pos = start * BufSamples.ir(buf);
sig = PlayBuf.ar(1, buf, rate * BufRateScale.ir(buf), 1, pos, 0);
sig = sig * env;
OffsetOut.ar(0, Pan2.ar(sig, pan));
}).add;
)
(
Pdef(\pgrain,
Pbind(
\instrument, \grain,
\buf, ~klar1.bufnum,
\rate, 1,
\dur, 0.06,
\start, Pwhite(0.0, 0.1), // Random starting point in the buffer
\amp, 0.5,
\rel, 0.1,
\pan, Pwhite(-1.0, 1.0), // Random panning
//\gate, 1, // Gate is open during playback
\amp, 0.5,
\out, 0
)
);
)
/* And a routine template: */
((
Routine({
3.wait;
Pdef(\pbazz).play;
5.wait;
Pdef(\pbazz).set(\freq, 100); // parameter variation?
10.wait;
Pdef(\pbazz).stop;
5.wait;
Pdef(\pgrain).play;
5.wait;
Pdef(\pgrain).set(\rel, 1);
5.wait;
Pdef(\pgrain).stop; //fade out?//
3.wait;
}).loop.play;
)