Classes | JITLib > Patterns | Live Coding

Pdefn : PatternProxy : Pattern : AbstractFunction : Object

non event stream reference definition
Source: Pdef.sc


Pdefn provides an interface to its superclass PatternProxy, keeping a reference to a stream that can be replaced while playing. One pattern may be used in many streams in different places. A change in the pattern definition propagates through all streams.

Pdef and Pdefn use separate global collections.

It is very similar to PatternProxy.

Pdefn can be used to store value patterns globally (for event patterns, see Pdef). Overview: JITLib

First Example

Class Methods


Pdefn.new(key, item)

Store the pattern in a global dictionary under key, replacing its pattern with the new one. If the pattern is a function, Pdefn creates a Prout with this function, passing in the envir, if given(see below).

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


From superclass: PatternProxy

Default source, if none is given. The default is a Pattern that returns 1.0 (This is 1 and not 0 to avoid deadlocks when used as a duration pattern. In a sense, 1 is just as generic as 0).


From superclass: PatternProxy

Remove all proxies from the global dictionary ( *all)


From superclass: PatternProxy

Clear all proxies, setting their source to silence.


Pdefn.all = value

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

Inherited class methods

Undocumented class methods


Instance Methods

Inherited instance methods

Undocumented instance methods



.map( ... args)


Pdefn in expressions

Embedding Pdefn in other patterns


When does the definition change?

If quant is set, the update is done at the next beat or whatever is specified:

update condition

In order to be able to switch to a new pattern under a certain condition, the instance variable condition can be set to a function that returns a boolean. Value and a count index are passed to the function. The condition is always valid for the next pattern inserted. For stuck conditions, the reset message can be used.

As counting up (such as "every nth event, a swap can happen") is a common task, there is a method for this, called count(n).


Functions as arguments to Pdefn

The (inner) environment