Dynamically update Pdef

hey, i would like to update keys from a Pdef while its playing and tried to use .set. any ideas?

(
SynthDef(\test, {
	arg out=0, pan=0, amp=0.35, freq=150;
	var env = Env.perc.kr(2);
	var sig = Saw.ar(freq);
	sig = Pan2.ar(sig, pan, amp * env);
	Out.ar(out, sig);
}).add;
)

(
~f0 = Pstutter(3, Pseq([55],inf));

Pdef(\overtones,
	Pbind(
		\instrument,\test,
		\multiply, Pseg(Pseq([1, 5],inf), Pseq([4, 1],inf), \linear),
		\scale, Scale.minor(\just),
		\numPartials, 5,
		\freq, (Pn(Plazy {|event|
			Pseries(1, 0.25, event[\numPartials])}, inf) * PL(\f0) * Pkey(\multiply)),
		\dur, Pseq([0.25],inf).trace,
		\amp,0.3,
	)
).play;
)

Pdef(\overtones).set(\dur, 1); //doesnt work

Have a look at Pbindef, that should do what you want.

thanks :slight_smile: i know that Pbindef is working. but im using Pdef with Pbind or PbindFx inside Pspawner and want to be flexible with that. Im just searching for a way to find the extremes in specific pattern configurations and make transitions later on :slight_smile:
Pdef.set is not working?

How is the Pdef Pbind combo different from Pbindef apart from Pbindef being so chatty?

Pbindef can only be used where Pdef is valid.

PbindProxy can be used everywhere that any Pbind can appear, and it can set keys at will, e.g.:

(
SynthDef(\rvb, { |out, mix = 0.33, room = 0.7, damp = 0.3|
	var sig = In.ar(out, 2);
	Out.ar(out, FreeVerb2.ar(sig[0], sig[1], mix, room, damp));
}).add;
)

(
q = PbindProxy(
	\degree, Pn(Pseries(-7, Prand([1, 2], inf), { rrand(5, 9) }), inf),
	\dur, 0.25
);

p = Pfx(q, \rvb).play;
)

q.set(\legato, Pwhite(0.1, 1.5, inf));

q.set(\dur, Pwrand([0.25, Pn(0.125, 2)], [0.8, 0.2], inf));

p.stop;

(I wonder if this is a weakness in Pbindef documentation? It seems that many users find their way easily to Pbindef, but not so many independently discover the above usage pattern.)

Pbind can’t replace the source patterns for its keys on-the-fly. So, with Pdef/Pbind, you can completely replace the entire Pbind but you can’t change only \degree or \dur etc.

PbindProxy does allow the value patterns to be replaced independently.

Pbindef is just a shortcut that combines Pdef and PbindProxy into a bit more convenient interface.

Come to think of it, that might be the documentation weakness. If we are currently talking about Pdef, and then extending Pdef to Pbindef for flexibility with the keys, this actually skips a step. Perhaps it should be:

  • Pdef + Pbind
  • → Pdef + PbindProxy
  • → Pbindef

hjh

I believe Pdef.set is setting values on an Event that is Pchain’ed with Pdef’s source.

So, if you start with

Pdef(\p).source = Pbind(\degree, 0)

and then try to use Pdef.set to alter degree

Pdef(\p).set(\degree, 1)

you actually end up with

Pdef(\p).source = Pbind(\degree, 0) <> (degree: 1)

which results in degree not being changed.

However, if you start with

Pdef(\p).source = Pbind()

and then change degree you end up with

Pdef(\p).source = Pbind() <> (degree: 1)

Which will alter degree.

But you have to be careful about using Patterns with Pdef.set. You’re manipulating an Event and not the source pattern and Events cannot always handle pattens as values especially with duration based keys such as dur and stretch.

Pdef.set is not equivalent to Pbindef.

Probably for the most part stay away form Pdef.set.

I often use something similar to this:

(
~tempo = 1;
Pbind(
	\dur, Pfunc({~tempo})
).play
)
~tempo=0.5

thanks for the explanation. Maybe i misread the post but I thought it would be able to wrap PbindProxy directly into Pdef then for Pdef.set

(
SynthDef(\test, {
	arg out=0, pan=0, amp=0.35, freq=150;
	var env = Env.perc.kr(2);
	var sig = Saw.ar(freq);
	sig = Pan2.ar(sig, pan, amp * env);
	Out.ar(out, sig);
}).add;
)

// working
(
q = PbindProxy(
		\instrument, \test,
		\degree, Pn(Pseries(-7, Prand([1, 2], inf), { rrand(5, 9) }), inf),
		\dur, 0.25
);
)

Pdef(\test, q).play;

q.set(\dur, 0.5);

Pdef(\test).stop;

// not working

(
Pdef(\test,
	PbindProxy(
		\instrument, \test,
		\degree, Pn(Pseries(-7, Prand([1, 2], inf), { rrand(5, 9) }), inf),
		\dur, 0.25
	)
);
)

Pdef(\test).play;

Pdef(\test).set(\dur, 0.5);

Pdef(\test).stop;

No, you can’t. Droptableuser already explained it so I won’t repeat.

hjh

Pbindef is just a shortcut that combines Pdef and PbindProxy into a bit more convenient interface.

as i said, i probably misread this. thanks