oscsupercollider

How to get OSC to interact with Scheduling Routine in Supercollider


I am trying to use OSC messaging as a method of scheduling tasks/routines in Supercollider. Specifically I want a routine to wait until a message is received via OSC before resuming. So instead of (for example) 10.wait I want - something like : wait(OSC listener - message received, so continue). I have combed through the Supercollider documentation but have been unable to find anything that could be adapted to such a situation. Any suggestion as to a solution would be greatly appreciated..


Solution

  • Look at the documentation for the Condition object. You can create a Condition, wait on it in one thread, and then resume that thread later on / from another thread, by using either condition.unhang or condition.test_(true).signal.

    The code for your OSC message handler might look something like:

    ~stepCond = Condition();
    
    Routine({
        "starting".postln;
        ~stepCond.wait;
        "continuing".postln;
    }).play;
    
    OSCfunc(\step, {
        ~stepCond.unhang();
    }, '/step')