Trying to use Pdefn to manipulate a Pbindef

I’m not sure what I’m doing wrong. I have a Pbindef repeating one note, c4=261.63, and I’m trying to use Pdefn to then play two notes, c4=261.63 and d4=293.66, but as its playing I try to use the Pdefn but it stays on the first Pseq.


(\pulse, {
	arg s, m, f, freq, width;
	var env, sig;
	env =[0,1,1,0], [s, m, f]), doneAction:2);
	sig =, width, 0.1)!2;, sig*env);

	\instrument, \pulse,
	\s, 0.01,
	\m, 0.1,
	\f, 0.01,
	\freq, Pswitch([
		Pseq([~c4], inf),
		Pseq([~c4, ~d4], inf)], Pdefn(\whichstream, 0)),
	\width, 0.5,
	\dur, Pdefn(\duration, 1/4),
	\stretch, 1,

Pdefn(\whichstream, 1);

it’s because your Pseqs repeat infinitely – once you’ve embedded one in the stream, it will never run out.

from the Pswitch helpfile:

Pswitch chooses elements from the list by a stream of indices ( which ) and embeds them in the stream. If the element is itself a pattern, it first completely embeds it before looking for the next index.

instead, set them to repeat once:

Pbind(\freq, Pswitch([Pseq([50], 1), Pseq([50, 100], 1)], Pdefn(\which, 1))).play

Pdefn(\which, 0)
1 Like