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.
A global IdentityDictionary with all proxies.
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)
An object for (re)defining the source of the proxy. If
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).
Remove all proxies from the global dictionary ( *all)
Clear all proxies, setting their source to silence.
Set or return the environment ( IdentityDictionary ) that stores all Pdefns.
When does the definition change?
If quant is set, the update is done at the next beat or whatever is specified:
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).