A Routine runs a Function and allows it to be suspended in the middle and be resumed again where it left off. This functionality is supported by the Routine's superclass Thread. Effectively, Routines can be used to implement co-routines as found in Scheme and some other languages.
A Routine is started the first time -next is called, which will run the Function from the beginning. It is suspended when it "yields" (using Object: -yield within the Function), and then resumed using -next again. When the Function returns, the Routine is considered stopped, and calling -next will have no effect - unless the Routine is reset using -reset, which will rewind the Function to the beginning. You can stop a Routine before its Function returns using -stop.
When a Routine is scheduled on a Clock (e.g. using -play), it will be started or resumed at the scheduled time. The value yielded by the Routine will be used as the time difference for rescheduling the Routine. (See -awake).
Routine also inherits from Stream, and thus shares its ability to be combined using math operations and "filtered".
Creates an instance of Routine, passing it the Function with code to run.
A Function with code for the Thread to run.
Call stack size (an Integer).
This method performs differently according to the Routine's state:
invalargument as the return value of
Since Routine inherits from Thread, it will become the current thread when it is started or resumed; i.e. thisThread used in the Routine Function will return the Routine. It will inherit the parent thread's logical time and clock (see Thread: -parent).
nil, if the Routine has stopped.
When a Routine is started by a call to this method (or one of its synonyms), the method's argument is passed on as the argument to the Routine Function:
After the Routine has yielded (it has been suspended at the point in its Function where
yield is called on an Object), a call to this method (or its synonyms) resumes executing the Function and the argument to this method becomes the return value of
yield. To access that value within the Function, you have to assign it to a variable - typically, the argument of the Function is reused:
Typically, a Routine yields multiple times, and each time the result of the yield is reassigning to the argument of its Function.
Equivalent to -next.
Equivalent to -next.
Causes the Routine to start from the beginning next time -next is called.
A Routine cannot reset itself, except by calling Object: -yieldAndReset.
In the SuperCollider application, a Routine can be played using a Clock, as can any Stream. every time the Routine yields, it should do so with a float, the clock will interpret that, usually pausing for that many seconds, and then resume the routine, passing it the clock's current time.
a Clock, TempoClock by default
see the Quant helpfile
using Object:idle within a routine, return values until this time is over. Time is measured relative to the thread's clock.
This method is called by a Clock on which the Routine was scheduled when its scheduling time is up. It calls -next, passing on the scheduling time in beats as an argument. The value returned by
next (the value yielded by the Routine) will in turn be returned by this method, thus determining the time which the Routine will be rescheduled for.
The scheduling time in beats. This is equal to the current logical time (Thread: -beats).
The scheduling time in seconds. This is equal to the current logical time (Thread: -seconds).
The clock which awoke the Routine.
Routine inherits from Thread, which allows access to some of its state:
The elapsed beats (logical time) of the routine. The beats do not proceed when the routine is not playing.
The elapsed seconds (logical time) of the routine. The seconds do not proceed when the routine is not playing, it is the converted beat value.
The thread's clock. If it has not played, it is the SystemClock.