I guess that this question is very basic but I haven’t been able to find a solution. I need to create a random value that can be used in multiples Pbinds inside a Ptpar. I have tried to generate the value in a variable but each time I call the variable, it returns a new random value. Pseed is not a solution here because I need the values to change automatically in a loop.
In the example below, I need that both Pbinds always play the same note.
I vaguely remember, once upon a time, someone proposing a version of Pclutch that would produce a new value only when time had advanced… but I can’t find it at the moment.
That would look like this (in a class file):
PtimeClutch : FilterPattern {
embedInStream { |inval|
var stream = pattern.asStream;
var lastTime;
var event;
while {
event = stream.next(inval);
event.notNil
} {
lastTime = thisThread.beats;
while { thisThread.beats == lastTime } {
inval = event.copy.yield;
};
};
^inval
}
}
And the usage would be something like this – left and right should follow the same rhythm:
Note, though, that both \dur bindings have to be to the same, identical stream object – so it isn’t exactly transparent. (This might be why the class was abandoned.)
Here it is - I use this all the time. Works especially well with @dkmayer 's PS patterns in his miSCellaneous quark, to create global-ish envelopes and the like that many other patterns can pull from.