SuperCollider CLASSES (extension)
Libraries>BBCut

# ExternalClock

Externally driven scheduling
Source: /Users/zzk/Library/Application Support/SuperCollider/downloaded-quarks/BBCut/classes/eventscheduling/ExternalClock.sc
Inherits from: Object
Subclasses: ServerClock
See also: BBCut

## Description

Wrapper for a TempoClock that deals with the special scheduling queue required for externally driven scheduling. Subclasses of ExternalClock may deal with the case of a ServerClock (server side clock, as for instance from beat tracking UGens), or control from external applications.

Because of Server latency, perceptual attack time of events and timing groove deviations, the next beat's worth of music must be generated before that beat, and cannot be rescheduled with changes of tempo. You add instances (individual bbcutters, patterns etc) to the clock.

Note that the scheduler compensates for latency- it is built for real-time reactions, so the latency is taken into account to avoid network jitter in communicating with the Server, but there is no delay from the required time of an event. Also, perceptual attack time and time deviations (possibly due to groove/expressive timing) of events are factored in. PAT necessitates pre-scheduling, expressive timing can go either way.

warnings of undefined behaviour:

Tempo is assumed in a moderate range 1-4 bps say.

s.latency must be small, ie 0.05 sec.

Using with Patterns- you can play EventStreams only. See EventStreamPlayer2 class file.

Using as a general scheduler: this scheduler assumes that everything it schedules is an Event that has a \play field, within which is a Function. For default Events this will be the same result as Event.play. For your own special Events you require at least (play:{"something".postln;})

## Class Methods

### *new (tempoclock)

#### Arguments:

tempoclock | A TempoClock object. If a SimpleNumber gets passed in, a new TempoClock is created at that bps. The default is to use TempoClock.default;

### Inherited class methods

## Instance Methods

### Inherited instance methods

### Undocumented instance methods

### -addprovider (provider)

### -getMaterial

### -initExternalClock (tc)

### -lastBeat

### -lastBeatTime

### -lastTempo

### -play (quant: 0)

### -removeprovider (array)

### -sched (list, lastref, provider, alive)

### -stop

### -tempo

### -tempo = val

### -tempoclock

### -tick

## Examples

    s=Server.default;

    s.latency=0.05;

    c=ExternalClock(TempoClock(2.1)).play;

    //playExt= play on External Clock
    p=Pbind.new.playExt(c);

    q= Pbind(\dur,Pseq([0.25,0.25,0.5],inf),\freq,Pseq([330,330,550],inf),\sustain, 0.1).playExt(c);

    q.mute;
    q.unmute;

    p.stop;
    q.stop;

    ~buffers= BBCutBuffer.array([Platform.resourceDir +/+ "sounds/break.aiff",Platform.resourceDir +/+ "sounds/break2.aiff"],[8,4]);

    //will be added to run on this clock as soon as made
    a=BBCut2(CutBuf2(~buffers[0],0.3), BBCutProc11.new).play(c);

    b=BBCut2(CutBuf2(~buffers[1],0.5,dutycycle:0.4), BBCutProc11.new).play(c);

    //stream cut audio in
    g=BBCut2(CutStream1(8), ChooseCutProc(0.5,4)).play(c);

    //remove the first from the clock- don't worry if there are FAILURE messages, some latency queued OSC messages
    //are still waiting that were already sent to the server, they shouldn't cause too much trouble
    a.end

    c.tempoclock.tempo_(1.5);

    b.end

    //remove everything and terminate TempoClock
    c.stop;

helpfile source: /Users/zzk/Library/Application Support/SuperCollider/downloaded-quarks/BBCut/HelpSource/Classes/ExternalClock.schelp
link::Classes/ExternalClock::
sc version: 3.8.0