ListPatterns are Patterns that iterate over arrays of objects in some fashion. All ListPatterns have in common the instance variables list and repeats. The list variable is some Array to be iterated over. The repeats variable is some measure of the number of times to do something, whose meaning varies from subclass to subclass. The default value for repeats is 1.
A Pseq is a Pattern that cycles over a list of values. The repeats variable gives the number of times to repeat the entire list.
Pseq also has an offset argument which gives a starting offset into the list.
You can pass a function for the repeats variable that gets evaluated when the stream is created.
If you specify the value
inf for the repeats variable, then it will repeat indefinitely.
Pseq used as a sequence of pitches:
Remember that math operations like
midicps can be used on streams.
Pseq(...).midicps.asStream is also possible because both pattern and stream inherit from AbstractFunction for which midicps is a method. ( midicps converts a midi value to cycles per second or Hz )
Pser is like Pseq, however the repeats variable gives the number of items returned instead of the number of complete cycles.
Prand returns one item from the list at random for each repeat.
Prand used as a sequence of pitches:
Pxrand, like Prand, returns one item from the list at random for each repeat, but Pxrand never repeats the same element twice in a row.
Pxrand used as a sequence of pitches:
Pshuf iterates over the list in scrambled order. The entire scrambled list is repeated in the same order the number of times given by the repeats variable.
Pshuf used as a sequence of pitches:
If a Pattern encounters another Pattern in its list, it embeds that pattern in its output. That is, it creates a stream on that pattern and iterates that pattern until it ends before moving on.
For example here is one pattern nested in another.
Pseqs nested in a Prand:
Nested sequences of pitches:
b plays pattern a once normally, once transposed up a fifth and once transposed up a fourth.
Adding two patterns together. The second pattern transposes each fifth note of the first pattern down an octave.
Here is the same example given in part 2 rewritten to use ListPatterns. It uses nested patterns and results in much more concise code. SuperCollider allows you to write
SomeClass(params) eliminating the ".new". This can make code like the pattern examples below, which create a lot of objects, more readable.
Here is an example that uses a Pattern to create a rhythmic solo. The values in the pattern specify the amplitudes of impulses fed to the Decay2 generator.
To go to the next file: Understanding Streams, Patterns and Events - Part 4