Tdef:
Filter:
Classes | JITLib > Patterns

Tdef : TaskProxy : PatternProxy : Pattern : AbstractFunction : Object

task reference definition
Source: Pdef.sc

Description

Tdef registers tasks by key. All accesses to the registered tasks go through the Tdef class via that key. Registered tasks can be replaced with other tasks while playing. The old task and its replacement can automatically crossfade and the replacement time can be quantized.

Tdef provides an interface to its superclass TaskProxy. Tdef keeps a reference to a task ( time pattern ) that can be replaced while playing. It continues playing when the old stream ended and a new stream is set and schedules the changes to the beat. One Tdef may be used in many tasks in different places. A change in the task definition Tdef propagates through all tasks.

Graphical overview over all current Tdefs: TdefAllGui. Overview: JITLib

First Example

Class Methods

Tdef.all

Tdef.all = value

A global IdentityDictionary with all proxies.

Creation

Tdef.new(key, item)

Store the task in a global dictionary under key, replacing its routine function with the new one.

Using *new(key) you can access the pattern at that key (if none is given, a default task is created)

Arguments:

key

An identifier for the proxy. Usually, it is a Symbol. The key transparently accesses the global IdentityDictionary.

item

An object for (re)defining the source of the proxy. If nil, the proxy is returned unmodified.

Tdef.default

From superclass: TaskProxy

Default source, if none is given. The default task has a function that waits in 1.0 beat steps and does nothing.

Tdef.removeAll

From superclass: PatternProxy

Remove all proxies from the global dictionary ( *all )

Tdef.clear

From superclass: PatternProxy

Clear all proxies, setting their source to silence.

Tdef.all

Tdef.all = value

Set or return the environment ( IdentityDictionary ) that stores all instances.

Tdef.defaultQuant

Tdef.defaultQuant = value

From superclass: TaskProxy

Set the default quantisation for new instances (default: 1.0). This can be an array [quant, phase, timingOffset, outset]

Inherited class methods

Undocumented class methods

Tdef.hasGlobalDictionary

Instance Methods

Changing the definition / setting the source

One Tdef may have many tasks in different places. A change in the task definition Tdef propagates through all tasks. The change does not have to be immediate - there is a scheme to schedule when the change becomes effective: a quant and clock (like elsewhere) and a condition.

.quant

.quant = val

From superclass: PatternProxy

Set the quantisation time for beat accurate scheduling.

.clock

.clock = value

From superclass: PatternProxy

get or set the instance's default clock, used by -play if no other clock is specified. Defaults to TempoClock.default.

Arguments:

(val)

can be an array [quant, phase, timingOffset, outset], or just [quant, phase] etc.

.condition

.condition = value

From superclass: PatternProxy

Provide a condition under which the pattern is switched when a new one is inserted. The stream value and a count value is passed into the function.

.count(n: 1)

From superclass: PatternProxy

Create and update condition that simply counts up to n and switches the pattern then

.reset

From superclass: PatternProxy

Switch the task immediately (stuck conditions can be subverted by this).

.envir

.envir = value

From superclass: PatternProxy

Set the environment (an Event) for the Tdef. It is passed as first argument into the Task function.

.set( ... args)

From superclass: PatternProxy

Set arguments in the default event. If there is none, it is created and the task routine is rebuilt.

.clear

From superclass: PatternProxy

Set the source to nil

.endless(default)

From superclass: PatternProxy

Returns a Prout that plays the task endlessly, replacing nil with a default value 1. This allows to create streams that idle on until a new pattern is inserted.

Tdef as stream reference

A single Tdef may serve as a definition for multiple tasks. These methods show how to fork off separate routines from one instance. Even if they run in different contexts, their definition may still be changed.

.fork(clock, quant, event)

From superclass: TaskProxy

Play an independent task in parallel.

Arguments:

clock

the clock on which to play the forked task

quant

can be an array of [quant, phase, offset], or a Quant value.

event

an event to pass into the forked task

.embed(val)

From superclass: PatternProxy

Pass a value (typically an Event) into the task function, and embed the Tdef in the stream.

.embedInStream(inval, embed: true, default)

From superclass: PatternProxy

just like any pattern, embeds itself in stream

Tdef as EventStreamPlayer

For live coding, each Tdef also may control one instance that plays one task. This is a PauseStream, accessible in the instance variable -player.

.play(argClock, doReset: false, quant)

From superclass: TaskProxy

Starts the Tdef and creates a player.

Arguments:

argClock

a clock on which to play the Tdef. If nil, uses the instance's -clock, which in turn defaults to TempoClock.default.

doReset

a flag whether to reset the task if already playing

quant

can be an array of [quant, phase, offset] or a Quant value.

.stop

From superclass: TaskProxy

Stops the player

.player

From superclass: TaskProxy

Return the current player (if the Tdef is simply used in other streams this is nil)

.pause

From superclass: TaskProxy

.resume(clock, quant)

From superclass: TaskProxy

.reset

From superclass: PatternProxy

Perform this method on the player.

.isPlaying

From superclass: TaskProxy

Returns true if player is running. If a Tdef is playing and its stream ends, it will schedule a stream for playing as soon as a new one is assigned to it. If it is stopped by stop, it won't.

Inherited instance methods

Undocumented instance methods

.copy(toKey)

.dup(n: 2)

.key

.prAdd(argKey)

Examples

Tdef as a Task player

Embed and fork: Tdef within other Tasks / Routines

Tdef as a time pattern

Instead of using a Pdefn for time values, it can be useful to use a Tdef. When changing its source, it keeps the stream of values synchronized to its clock.