Pseq, sequencing differnt synthdefs

I noticed that you can sequence multiple synthdefs withing a single Pbind
\instrument,Pdef([\instrument 1,\instrument 2],inf)
When instr1 and instr.2 share the same arguments , Pseq automation of said argument is affecting both synthdefs
Is there a way to tell the Pbind to affect which instrument ?

(
Pdef(
	\cart,
	Pbind(
		\instrument,Pseq([\twoop,\twoop,\simple],inf),
		\pitch,Pseq([40,52,40,49,60,42,42,54],inf),
		\dur,Pseq([1/2,1/2,1,1/2,1/2,1],inf),
		\fmamt,Pwhite(1,2,inf),
		\dec,0.6,//////dec is a parameter on both twoop and simple instrument
		\filterfreq,Pwhite(500,2000,inf),
		)
	)
)

In general synths do not mind if you send them arguments they don’t have, they’ll ignore it.
If you still want to specify parameters based on the current instrument you can use Pif with a Pfunc inside, where the first argument of the function is the current Event through which we can access the current state of the sequence.

s.boot;

(
SynthDef(\foo, {|out|
	var sig = Saw.ar(\freq.kr(100.0)!2) * \amp.kr(0.2) * EnvGen.kr(Env.perc, doneAction: Done.freeSelf);
	Out.ar(out, sig);
}).add;
)

(
Pdef(\switch, Pbind(
	\dur, Prand((1..5)/5, inf),
	\instrument, Pseq([\default, \foo], inf),
	\degree, Pxrand((0..10), inf),
	\amp, Pif(Pfunc({|ev| ev.instrument!=\default}), {
		// make non-default synth much louder
		0.3
	}, {
		0.02
	});
)).trace.play;
)

Is this what you asked for?

Here is my favorite way to set up parameters that are specific to SynthDefs, integrated into an overall pattern. (At least, I’m assuming this is what you mean… “Pbind affecting instrument” isn’t quite the way patterns work, I think.)

(
SynthDef(\fm, { |out, gate = 1, freq = 440, amp = 0.1,
	ratio = 1, index = 1|
	var eg = EnvGen.kr(Env.adsr(0.01, 0.2, 0.6, 0.1), gate, doneAction: 2);
	var modEg = EnvGen.kr(Env([1, 0.3], [0.7]));
	var mod = SinOsc.ar(freq * ratio) * index * modEg;
	var car = SinOsc.ar(freq, mod % 2pi);
	Out.ar(out, (car * eg * amp).dup);
}).add;

SynthDef(\kl, { |out, freq = 440, amp = 0.1, time = 0.6,
	ratios = #[1, 2, 3.5], rings = #[1, 0.8, 0.7], amps = #[1, 0.7, 0.5],
	excDcy = 0.05|
	var exciterEg = Decay2.ar(Impulse.ar(0), 0.001, excDcy);
	var exciter = PinkNoise.ar * exciterEg;
	var sig = Klank.ar(`[ratios, amps, rings], exciter, freq, decayscale: time);
	DetectSilence.ar(sig, doneAction: 2);
	Out.ar(out, (sig * amp).dup);
}).add;
)

(
// synthdef-specific parameters
// these happen to have different names
// but the two synthdefs could have parameters with the same name
// and they will be independently chosen based on synthdef name
var parms = (
	fm: Pbind(
		\ratio, Pwhite(1, 12, inf) * 0.5,
		\index, Pwhite(0.5, 2.5, inf)
	),
	kl: Pbind(
		\time, Pwhite(0.2, 1.4, inf),
		\ratios, Prand([
			[1, 2, 3.5],
			[1, 1.5, 3.5],
			[1, 2.5, 6.5],
			[1, 2.5, 7]
		], inf)
		.collect { |array| [array] }  // needed for arrayed arg in event
	)
);

p = Pchain(
	Psym1(Pkey(\instrument), parms),
	Pbind(
		\instrument, Prand([\fm, \kl], inf),
		\degree, Pwhite(-7, 14, inf),
		\dur, Pwrand([0.125, 0.25, 0.375, 0.5], [4, 3, 2, 1].normalizeSum, inf)
	)
).play;
)

hjh

1 Like