OSCSched:
Filter:
crucial-library/Classes (extension) | Scheduling | Libraries > crucial > Scheduling

OSCSched
ExtensionExtension

scheduling utility for just-in-time scheduling of OSC bundles

Description

The bundle is kept on the client until the last possible moment, and then actually sent to the server in a time stamped bundle, just before it is due to be executed.

Bundles can be scheduled for precise execution using relative seconds, relative beats, absolute seconds or absolute beats. Bundles can be scheduled on multiple servers, with exact simultaneous execution times.

Bundles can be easily cancelled up until the time they are sent to the server. They are sent to the server just before execution.

The Tempo class is used to specify what the tempo is, and is used for all beat <-> second calculations. A default global Tempo object is used, or you can create a specific Tempo instance.

There is a default global OSCSched that can be addressed through class methods. It uses the SystemClock and the default global Tempo. You may also create individual instances that maintain their own scheduling queues, tempii, and time epochs.

The default clock used is the SystemClock, but you may also specify to use the AppClock.

An optional clientSideFunction can also be supplied that will be evaluated on the client at the exact time as the OSC bundle is scheduled to happen. This could be used to show a change in the gui or to update some setting on a client side object.

All of these methods exist as both

class (the default global scheduler) OSCSched.tsched(seconds,server,bundle,clientSideFunction)

and instance methods (a specific scheduler). oscSched = OSCSched.new; oscSched.tsched(seconds,server,bundle,clientSideFunction)

All of the x-methods establish a block such that a subsequent schedule using another x-method will cause the previous one to be cancelled. This is particularily useful when you are controlling something from a gui or process, and change your mind before the event you have triggered comes due. Another example is a pattern that returns delta beat values, repeatedly scheduling its next note at the time of playing the current one. To switch the pattern with another or abruptly start it over, simply do so: if you used xsched, then the previously scheduled event will be cancelled. In most cases, you will wish to create a private instance of OSCSched when using this technique.

Class Methods

.global

.initClass

.tsched

time based scheduling delta specified in seconds

Arguments:

seconds
server
bundle
onArrival

.xtsched

exclusive time based schedule any previous bundles scheduled using xtsched, xsched or xqsched will be cancelled. this is incredibly useful in situations where several bundles might be sent and you only want the last one to be used as the final answer. example: a monkey is hitting many buttons, changing his mind about which sound to play next. this would result in many bundles being stacked up all at the same time, and the server would choke trying to execute them all. so this forces a kind of monophony of bundles. another example: a sequence plays successive notes, scheduling each one when it plays the previous one. you then switch to a different sequence. you don't want the note that was scheduled from the previous sequence to happen. using one of the x-methods, you don't have to worry about it, it will just be cancelled.

Arguments:

seconds
server
bundle
onArrival

.sched

delta specified in beats

Arguments:

beats
server
bundle
onArrival

.xsched

exclusive beat based scheduling

Arguments:

beats
server
bundle
onArrival

.qsched

will happen at the next even division ( 4.0 means on the downbeat of a 4/4 bar ), or immediately if you happen to be exactly on a division.

Arguments:

quantize
server
bundle
onArrival

.xqsched

exclusive quantized beat based scheduling

Arguments:

quantize
server
bundle
onArrival

.tschedAbs

will happen at the time specified in seconds

Arguments:

time
server
bundle
onArrival

.schedAbs

will happen at the beat specified. this uses TempoClock for scheduling

Arguments:

beat
server
bundle
onArrival

Instance Methods

.tsched

Arguments:

seconds
server
bundle
onArrival

.xtsched

Arguments:

seconds
server
bundle
onArrival

.xtschedFunc

Arguments:

seconds
function

.sched

Arguments:

beats
server
bundle
onArrival
onSend

.xsched

Arguments:

beats
server
bundle
onArrival

.qsched

Arguments:

quantize
server
bundle
onArrival

.xqsched

Arguments:

quantize
server
bundle
onArrival

.tschedAbs

Arguments:

time
server
bundle
onArrival

.schedAbs

Arguments:

beat
server
bundle
onArrival

.aschedFunc

execute the function at this absolute beat

Arguments:

beat
func

Discussion:

.schedAtTime

Arguments:

atTime

see atTime

server
bundle

.xschedAtTime

Arguments:

atTime

see atTime

server
bundle

.xschedBundle

Arguments:

beatDelta
server
bundle

.tschedAbsNext

Examples

Absolute Beat / Time scheduling

continuing with the scheduler and defs created above

scheduling a function

Exclusive x-methods