It isn’t well documented, but if you need to reschedule a running thread for an arbitrary time, follow this general format.
(
~waitTime = 1;
~reschedulePauseStream = { |player, newQuant|
player.stop;
PauseStream(player.originalStream, player.clock).play(quant: newQuant);
};
~task = PauseStream(Routine {
inf.do { |i|
[i, thisThread.beats].postln;
~waitTime.wait;
}
});
~task.play(quant: 1);
)
(
~waitTime = 0.5;
~task = ~reschedulePauseStream.(~task, 0.5);
)
~task.stop;
The central problem with rescheduling in SC is: Once you schedule something on the clock, there is no way to un-schedule it. You can change the object’s state so that it will do nothing when it wakes up… but it is going to wake up and see if there’s anything to do.
For rescheduling, what you want is for the task to be active at the new time, and inactive at the old time. You can’t have two different states in the same object – the same Routine, Task, whatever cannot be both active and inactive. So the solution above is to create a new player. The new player is active at the new time. The old player is still scheduled on the clock, but deactivated.
Because it’s a new player, it’s important to reassign back: ~task =
when rescheduling is not optional.
hjh