Just like filter UGens modify an input signal, filter patterns modify the stream of values coming from a pattern.
We have already seen some operations that modify a stream of values: math operators (which render as Punop, Pbinop or Pnaryop patterns) and certain collection methods (mainly collect
, select
and reject
). Filter pattern classes can do some other surprising and useful things.
All filter patterns take at least one source pattern, providing the values/events to be filtered. Some filter patterns are designed for value patterns, others for event patterns. A handful work equally well with both single values and events.
Following is a categorized overview. See the separate category documents for more detail.
Pattern Guide 06a: Repetition Constraint Patterns
Pclutch(pattern, connected)
connected
pattern is true, Pclutch returns the next value from pattern
. If connected
is false, the previous pattern value is repeated. It's like a clutch in a car: when engaged, the pattern moves forward; when disconnected, it stays where it is.Pn(pattern, repeats)
repeats
times: simple repetition. This also works on single values: Pn(1, 5)
outputs the number 1 5 times.Pdup(n, pattern)
n
and pattern
are both patterns. Each value from pattern
is repeated n
times. If n
is a pattern, each value can be repeated a different number of times.Psubdivide(n, pattern)
Pfin(count, pattern)
count
values from the source pattern, then stops.Pconst(sum, pattern, tolerance)
Pfindur(dur, pattern, tolerance)
Psync(pattern, quant, maxdur, tolerance)
maxdur
(in which case it behaves like Pfindur, adjusting the last event so the total duration matches maxdur
), or the pattern stops early and the last event is rounded up to the next integer multiple of quant.Pattern Guide 06b: Time Based Patterns
Ptime(repeats)
Pstep(levels, durs, repeats)
level
value for its corresponding duration, then move to the next.Pseg(levels, durs, curves, repeats)
levels
, durs
and curves
should be patterns. Related: Use of Env as a pattern.Pattern Guide 06c: Composition of Patterns
Pbindf(pattern, pairs)
Pchain(patterns)
Pattern Guide 06d: Parallel Patterns
Ppar(list, repeats)
list
at the same time. When the last one finishes, the Ppar also stops. If repeats
> 1, all the subpatterns start over again from the beginning.Ptpar(list, repeats)
[timeOffset0, pattern0, timeOffset1, pattern1...]
. Each pattern starts after the number of beats given as its time offset. The patterns can start at different times relative to each other.Pgpar(list, repeats)
Pgtpar(list, repeats)
Pspawner(routineFunc)
Pspawn(pattern, spawnProtoEvent)
Pattern Guide 06e: Language Control
Some patterns mimic language-style control methods: conditionals ( Pif ), loops ( Pwhile ) and error cleanup ( Pprotect ).
Pif(condition, iftrue, iffalse, default)
condition
that returns true or false. Then, one value is taken from the true or false branch before going back to evaluate the condition again. The default
value or pattern comes into play when the true or false branch stops producing values (returns nil). If the default
is not given, Pif returns control to the parent upon nil from either branch.Pseed(randSeed, pattern)
pattern
, effectively restarting the random number generator at the start of the pattern.Pprotect(pattern, func)
protect
error handling method, if an error occurs while getting the next value from the pattern, the function will be evaluated before the error interrupts execution.Ptrace(pattern, key, printStream, prefix)
trace
message: aPattern.trace(key, printStream, prefix)
--> Ptrace(aPattern, key, printStream, prefix)
.Pwhile(func, pattern)
Pattern Guide 06f: Server Control
Pbus(pattern, dur, fadeTime, numChannels, rate)
Pgroup(pattern)
Pfx(pattern, fxname, pairs)
Pfxb(pattern, fxname, pairs)
out
argument, and write the processed signal onto the same bus using either ReplaceOut or XOut. Pfx uses whatever bus and group are specified in the incoming event. Pfxb allocates a separate bus and group for the effect and the pattern.Pproto(makeFunction, pattern, cleanupFunc)
pattern
. When the pattern stops (or is stopped), the resources can be removed automatically.Pattern Guide 06g: Data Sharing
Pkey(key)
key
in the input event, making previously-calculated values available for other streams.Penvir(envir, pattern, independent)
Pfset(func, pattern)
Plambda(pattern, scope)
Previous: Pattern Guide 05: Math on Patterns
Next: Pattern Guide 06a: Repetition Constraint Patterns