I am trying to reconcile two ways of dealing with (musical) time. The context is real-time performance instrument + SC. I have some algorithmic process that generate sounds which I implement as a Task with a loop. The general outline of the loop is:
calculate some values
Synth(\makesound [val1, val2…]
wait
But, sometimes, I want this process to respond to an external event. This event would be an OSCdef triggered either from the instrument (e.g. onset detection) or from outside supercollider. For example, I would like the algorithm to move to the next event in the loop (i.e. stop waiting). In addition i would like to also be able to schedule such an interruption to happen in the future. e.g. in 2 seconds trigger the next event in the loop.
Any thoughts how to integrate these two modes of handling time?
thanks
Oded
There’s a trick to reschedule a Task: assign the Task’s routine into a new task.
t = Task { loop { your stuff, with wait calls etc } }.play;
// to reschedule (do this in the OSCdef)
(
// transfer the stream into a new Task wrapper
// and play it Right Now -- this will interrupt the prior timing
var new = Task.new.stream_(t.stream).play;
// break the connection between the old Task and its stream
// the old timing is forgotten at this point
t.stop;
// and remember the new Task wrapper for next time
t = new;
)
It’s a unique feature of Task / PauseStream; you can’t do this with Routine directly (because of the way Routine handles its playing/stopped status). You also can’t do it with a single, persistent Task – but you can do it by disposing of Task objects after breaking their normal timing.