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