If I understand your meaning, then… Pdefn doesn’t work that way, I’m afraid. It’s not analogous to a variable, but rather like a lazy reference.
TL;DR If you need the Pdefn values to be unique, then they need to have different names.
That’s a bit abstract… if you write like this:
(
var a;
p = Ppar([
a = 440; Pbind(\freq, a, \dur, Pwhite(0.2, 1.2, inf)),
a = 550; Pbind(\freq, a, \dur, Pwhite(0.2, 1.2, inf)),
a = 660; Pbind(\freq, a, \dur, Pwhite(0.2, 1.2, inf))
]).play;
)
p.stop;
… you get three pitches. (This is valid syntax – each line in the array is an expression sequence, whose result is the result of the last expression, i.e., the Pbind.) All three Pbinds refer to \freq, a, and – here’s the important point – the variable a is resolved immediately when constructing each Pbind object. For the first Pbind, a holds 440; when the variable is evaluated, only its value goes through, so the first Pbind gets \freq, 440, the second \freq, 550 etc.
But if you write it like this:
(
p = Ppar([
Pbind(\freq, Pdefn(\a, 440), \dur, Pwhite(0.2, 1.2, inf)),
Pbind(\freq, Pdefn(\a, 550), \dur, Pwhite(0.2, 1.2, inf)),
Pbind(\freq, Pdefn(\a, 660), \dur, Pwhite(0.2, 1.2, inf))
]).play;
)
p.stop;
The meaning is different. Pdefn(\a) is not a variable to resolve to its value right now. It’s a reference to a stream of values. All 3 Pbinds refer to the same reference to the same stream. There is no way to lock the first Pbind to Pdefn’s stream at the moment of building the Pbind object.
Shorter:
Pdefn(\z, 1);
z = Pdefn(\z).asStream;
Pdefn(\z, 2);
y = Pdefn(\z).asStream;
[z.next, y.next]
-> [2, 2] // and NOT [1, 2]
hjh