Some questions about the PdefGui

Ive recently started using the PdefGui, but there are two things i cant figure out. Consider this snippet.

Pdef(\zingy).envir = (dr: 0.1, freqlo: 100, freqhi: 10000);

(Pdef(\zingy).source = Pbind(
	\instrument, \sineperc,
	\freq, Pwhite(Pkey(\freqlo), Pkey(\freqhi)),
	\amp, Pexprand(0.05, 0.1),
	\pan, Pwhite(-1, 1),
	\dur, Pwhite(Pkey(\dr), 2*Pkey(\dr))
));

Pdef(\zingy).play.gui;

(
SynthDef(\sineperc, {
	arg freq;
	var sig;

	sig = SinOsc.ar(freq) * EnvGen.kr(Env.perc(0.01,0.1), doneAction:2);
	
	Out.ar(0,sig!2*0.1);
}).add;
)


  1. How do you change the maximum and minimum values of the sliders, and change it to an exponential or linear slider.

  2. Why does this work

\dur, Pwhite(Pkey(\dr), 2*Pkey(\dr))

But something like this doesnt

\dur, Pseq([Pkey(\dr), 2*Pkey(\dr)],inf)

For controlspecs, this seems to work:

(
s.waitForBoot({
	var pat;
	
	SynthDef(\sineperc, {
		arg freq;
		var sig;
		
		sig = SinOsc.ar(freq) * EnvGen.kr(Env.perc(0.01,0.1), doneAction:2);
		
		Out.ar(0,sig!2*0.1);
	}).add;
	
	s.sync;
	
	Pdef(\zingy).envir = (dr: 0.1, freqlo: 100, freqhi: 10000);
	
	ControlSpec.specs[\freqlo] = ControlSpec(minval:100, maxval:400, warp:\exp);
	ControlSpec.specs[\freqhi] = ControlSpec(minval:5000, maxval:10000, warp:\exp);
	ControlSpec.specs[\dr] = ControlSpec(minval:0.1, maxval:1.0, warp:\lin, step:0.1);
	
	pat = Pbind(
		\instrument, \sineperc,
		\freq, Pwhite(Pkey(\freqlo), Pkey(\freqhi)),
		\amp, Pexprand(0.05, 0.1),
		\pan, Pwhite(-1, 1),
		\dur, Pwhite(Pkey(\dr), 2*Pkey(\dr))
	);
	Pdef(\zingy).source = pat;
	Pdef(\zingy).play.gui;
});

)
1 Like

For the question 2 about the Pkey, it can be very instructive to trace the patterns using a call to trace:

E.g. compare this:

\dur, Pseq([Pkey(\dr).trace(prefix:"1:"), (2*Pkey(\dr)).trace(prefix:"2:")], inf)

to this:

\dur, Pseq([Pkey(\dr,1).trace(prefix:"1:"), (2*Pkey(\dr,1)).trace(prefix:"2:")], inf)

and you will realize the problem is in the default value for “repeats” in Pkey

1 Like

Thank you man. All problems are solved now.
So just two questions so i can understand it a bit better, since im a beginner. The controlspec.specs is like a global dictionary in which specs are stored by key? And with ControlSpec.specs[\someKey] you can get and set that spec? And in the envir of a pdef you create the names(and some initial value) of keys for which behind the scenes controlspecs are made for the gui and are stored in that global dictionary.

And maybe not the most important thing to know, but why does the Pkey(\dr) not repeat in a Pwhite but it does in a Pseq.

To be honest I’m not very familiar with PdefGui internals. Basically I did a lot of trial and error until I had something that worked :wink: Your description sounds plausible, but the only way to know for sure is to dive into the code I’m afraid.

For the Pwhite, what makes you think the Pkey are not repeating? Did you try adding .trace to them?
I’d suggest to try setting their repetition value to 1 in the Pwhite and try out what difference it makes.