Accessing Pkey values inside a Pfxb

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.

  1. Why is this not working?
  2. 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));


SynthDef(\out, {
	arg out = 0, gain=1;
	var sig =,2)*gain;, sig.tanh);

//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 =[aLev,1,0.001],[3.65,0.01],\exp),doneAction:2);
	sigleft =,buf, * rate)[0];
	sigright =,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 =,cutOff),cutOff),cutOff),cutOff),cutOff);,sig*env*amp);

I just tried your code block with one change, for debugging:

Pdef(\rimOut).source = Pfxb(Pdef(\rimclick), \out, \gain, Pkey(\gain)).collect { |ev| ev.postln; ev };



... init events...
... then...
( 'instrument': playBuf, 'panStart': [ [ 1, 0 ] ], 'dur': 0.25, 'amp': 1, 
  'rate': 1, 'k': 0.8, 'stretch': 2, 'out': 4, 'group': 1007, 
  'rimrate': 1, 'gain': 1 )

... and further...
Pdef(\rimOut).envir[\gain] = 0.1;

... now the events print:
( 'instrument': playBuf, 'panStart': [ [ 0, 1 ] ], 'dur': 0.5, 'amp': 1, 
  'rate': 1, 'k': 0.8, 'stretch': 2, 'out': 4, 'group': 1007, 
  'rimrate': 1, 'gain': 0.1 )


I get gain: 1 initially, and then gain: 0.1 after changing \gain in the environment. It is also working from the Pdef gui.

I can think of two guesses. 1/ Without checking git history, maybe there was a bug about this in 3.12.x or earlier, which has been fixed. Or 2/ Maybe you’re executing some code somewhere else that is interfering…? Probably not no. 2, but there’s no evidence presented to rule it out.

Speaking just for myself, I handle effects using my ddwMixerChannel quark and I do not use Pfx / Pfxb at all.


1 Like

Thank you, it seems the gain in the environment does change for me too when i print the events. However the audible gain doesnt seem to change. So the Pdef does register changes, but the Pfxb somehow doesnt reapply those changes.

That being said, ive started using PbindFx accompanied by VarGui. So for now my problems are solved.

And its nice to see new techniques for debugging. It shows how much i need to work on those skills.

Ahhh… The clue is in the instrument keys – there’s only one event for the effect synth, and many events for the source synths.

I think Pfxb is probably not designed for modulating the effect parameters. Maybe there’s an extension class for it, or you could manage the effect synth by yourself.