The catch here is that streams are almost always Routines. When a Routine is reset, only one thing happens: its status is modified so that it will start over from the beginning of the function. That’s it. There’s no resetFunc for the vast majority of streams. Meaning: for most streams, when you reset them, there is no visible side effect at the moment of being reset. The effect of the reset is seen the next time the Routine is called.
Pbind’s stream is a Routine, and also note in Pbind’s code that it never resets anything. It makes new streams.
FuncStream is structurally different. It has no internal state. But, James McCartney felt some form of reset would be good, so he put in a function to handle that, just calling it directly (meaning any side effects are immediate).
You do have a point here: most patterns, when you call asStream
, start over from the beginning. But, if you define “starting over” as a reset, Pfunc doesn’t. It might be legitimate to call the resetFunc upon asStream – this might also break existing user code, so it would have to be discussed.
That suggests one workaround would be to create your own version of Pfunc:
Pfunc2 : Pfunc {
asStream {
resetFunc.value;
^FuncStream(nextFunc, resetFunc)
}
}
Alternately, this would work too:
r = Pbind(
\dur, Pseq([0.4], 5),
\acc, Plazy {
~tm = 0;
Pfunc({ |ev| ~tm = ~tm + ev[\dur] })
}
).asStream;
With both of those, you would not see ~tm
reset to 0 immediately, but the first next
after reset would reinitialize it. (Unfortunately it’s Pfunc’s reset behavior that has misled you here: it, rather than Pbind, is the odd duck.)
hjh