Routines should not be played multiple times simultaneously.
If you take one routine and play it multiple times, the multiple plays will not behave independently – rather, they will be interleaved in time order.
r = Routine {
var i = 0;
loop {
[i, thisThread.beats].postln;
i = i + 1;
1.0.wait;
}
};
r.play(quant: 1); // play once
... snip...
[4, 2103.0]
[5, 2104.0]
[6, 2105.0]
[7, 2106.0]
r.play(quant: [1, 0.25]);
[8, 2107.0]
[9, 2107.25] -- note: this is NOT index 0!
[10, 2108.0]
[11, 2108.25]
[12, 2109.0]
r.stop;
I’m pretty sure this behavior is not what you want.
You can get independent routines by creating multiple Routine instances.
(
f = {
var i = 0;
loop {
[i, thisThread.beats].postln;
i = i + 1;
1.0.wait;
}
};
)
r = Routine(f).play(quant: 1); // play once
[0, 2254.0]
[1, 2255.0]
[2, 2256.0]
[3, 2257.0]
t = Routine(f).play(quant: [1, 0.25]);
[0, 2257.25] -- now they are independent
[4, 2258.0]
[1, 2258.25]
[5, 2259.0]
[2, 2259.25]
r.stop;
t.stop;
My opinion is that Routines are meant to be created when needed, and thrown away easily. Sometimes we’re tempted to try to preserve a routine for reuse, out of some sense that it’s more economical or something. That’s often a mistake. Use the objects according to the desired behavior.
hjh