Pattern Guide 06a: Repetition Constraint Patterns:

Filter:
Tutorials/A-Practical-Guide
| Streams-Patterns-Events > A-Practical-Guide

Patterns that repeat values, or cut other patterns off early

These are essentially flow of control patterns. Each one takes a source pattern and repeats values from it, or stops the stream early based on a preset constraint.

These patterns allow you to repeat single values, or (in the case of Pn) entire patterns.

`Pclutch(pattern, connected)`

- If the
`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)`

- Embeds the source pattern
`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)`

- Like Pdup, except the pattern value is divided by the number of repeats (so that the total time for the repeat cycle is the duration value from the source pattern).
See also Pstep, described in Pattern Guide 06b: Time Based Patterns. Pstep can be used like Pdup, but repetition is controlled by time rather than number of repeats per item.

Instead of prolonging a stream by repetition, these patterns use different methods to stop a stream dynamically. They are especially useful for modularizing pattern construction. One section of your code might be responsible for generating numeric or event patterns. By using constraint patterns, that part of the code doesn't have to know how many events or how long to play. It can just return an infinite pattern, and another part of the code can wrap it in one of these to stop it based on the appropriate condition.

`Pfin(count, pattern)`

- Returns exactly
`count`

values from the source pattern, then stops. (Pfin has a cousin, Pfinval, that is deprecated.) `Pconst(sum, pattern, tolerance)`

- Output numbers until the sum goes over a predefined limit. The last output value is adjusted so that the sum matches the limit exactly.
`Pfindur(dur, pattern, tolerance)`

- Like Pconst, but applying the "constrain" behavior to the event's rhythmic values. The source pattern runs up to the specified duration, then stops. This is very useful if you know how long a musical behavior should go on, but the number of events to fill up that time is not known.
`Psync(pattern, quant, maxdur, tolerance)`

- Like Pfindur, but does not have a fixed duration limit. Instead, it plays until either it reaches
`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`

. This is hard to explain; a couple of examples might make it clearer.

Previous: Pattern Guide 060: Filter Patterns

Next: Pattern Guide 06b: Time Based Patterns

helpfile source: /usr/local/share/SuperCollider/HelpSource/Tutorials/A-Practical-Guide/PG_06a_Repetition_Contraint_Patterns.schelp

link::Tutorials/A-Practical-Guide/PG_06a_Repetition_Contraint_Patterns::

link::Tutorials/A-Practical-Guide/PG_06a_Repetition_Contraint_Patterns::