Class: StatefulPatterns
StatefulPatterns()
This is a base class that can be used to automatically define Patterns
that hold state between queries. Derived classes, which must be defined at
module scope, must in their constructor call this.registerPatterns
, which
will automatically register (most of) of their methods as Strudel Patterns,
each of which takes an instance of the class as a first parameter, and the
Pattern as the last parameter. Class methods must have the following syntax
and semantics:
Class.Pat(is_onset, [0 or more arguments to be patternified], hap) {...}
Strudel will pass true
for is_onset
on the onset of the Pattern's cycle,
and false
for is_onset
for every query in that cycle. Therefore, the
class method must update its state if is_onset
is true, and return the
hap, without changing its value; and if 'is_onset' is false, the method must
update and return the hap, and its usually new value.
In this way, derived classes act like stateful values that have Pattern methods as class methods.