I have a pattern playing and i want to route that pattern through another synth called \out. I want to be able to control the gain parameter of the \out synth with a Pdef gui. I know how to get parameter control working through the Pdef gui when im using Pbinds. However this does not work when im using Pfxb. The problem is described in more detail in the comments of the source code below.
Ive got two questions.
- Why is this not working?
- Since im new to pattern effects: What method do you recommend for managing pattern effects? My preference goes to something that allows me to just define one pattern per instrument. And for each synth node thats created by that pattern id like to be able to determine the effect routing.
//here i define the environments of each Pdef
(
Pdef(\rimOut).envir = (gain:1);
Pdef(\rimclick).envir = (amp: 1, rimrate: 1);
ControlSpec.specs[\amp] = ControlSpec(0,10);
ControlSpec.specs[\gain] = ControlSpec(0,10);
ControlSpec.specs[\rimrate] = ControlSpec(0.1,5,\exp);
)
(
//My method does work properly for Pdef(\rimclick) by using Pdef(\rimclick).gui
//For example the Pkey(\amp) value here is determined by the corresponding Pdef gui slider
Pdef(\rimclick).source = Pbind(\instrument, \playBuf,
\panStart, Prand([[[0,1]],[[1,0]]],inf),
\rate, Pkey(\rimrate),
\buf, Pseq([\rest, b.rimclick, b.rimclick, b.rimclick], inf),
\k, 0.8,
\dur, Pseq([1/4, 3/16, 1/16, 1/2], inf),
\amp, Pkey(\amp),
\stretch, 2);
//However here \gain does not react to values of Pkey(\gain). Also Pkey(\gain).trace does nothing
//\gain does react properly to just numbers
Pdef(\rimOut).source = Pfxb(Pdef(\rimclick), \out, \gain, Pkey(\gain));
)
(
Pdef(\rimOut).play.gui;
)
SynthDef(\out, {
arg out = 0, gain=1;
var sig = In.ar(out,2)*gain;
ReplaceOut.ar(out, sig.tanh);
}).add;
//this is not important, this is just the source synthdef. I just included it for completeness
SynthDef(\playBuf, {
arg rate, buf, out=0,cutOff=22000, amp = 1, aLev = 1, panStart = #[1,0];
var sig, sigleft, sigright, env;
env = EnvGen.kr(Env([aLev,1,0.001],[3.65,0.01],\exp),doneAction:2);
sigleft = PlayBuf.ar(2,buf,BufRateScale.kr(buf) * rate)[0];
sigright = DelayN.ar(PlayBuf.ar(2,buf,rate),0.02,0.02)[1];
sig = [[sigleft, sigright],[sigright,sigleft]];
sig[0] = (sig[0] * panStart).sum;
sig[1] = (sig[1] * panStart).sum;
sig = LPF.ar(LPF.ar(LPF.ar(LPF.ar(LPF.ar(sig,cutOff),cutOff),cutOff),cutOff),cutOff);
Out.ar(out,sig*env*amp);
}).add;