There are a couple of different ways to have several patterns playing at the same time. The most obvious is to play them separately. The patterns' events get scheduled independently on their clock(s) and run concurrently. None of these patterns need to have any knowledge of the others. One advantage of this approach is that the patterns can be stopped and started independently.
The other is to combine them into a parallel stream. The result is a single pattern object that can be played or stopped only as one unit. Some degree of interactive control is lost, but there are times when merging several patterns is necessary -- for instance, converting a pattern into a Score object for NRT rendering.
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)
An excellent example of Ppar and Pseq used together to structure an entire piece (Kraftwerk's "Spacelab") can be found in examples/pieces/spacelab.scd.
Ppar and its cousins are good for a fixed set of parallel patterns -- that is, you need to know in advance how many patterns will be parallelized. Once the parallel pattern starts, there is no way to add more streams to it. To keep adding streams, use Pspawner and Pspawn. For the purpose of this overview, some basic features will be illustrated in a couple of simple examples. These classes have more capabilities; refer to their help files for specifics.
Pspawner(routineFunc)
Pspawn(pattern, spawnProtoEvent)
This example uses Pspawner to trigger overlapping scale segments at different speeds. Unlike Ppar, which could handle a fixed number before stopping, Pspawner can keep going indefinitely.
The same, written using Pspawn :
Previous: Pattern Guide 06c: Composition of Patterns
Next: Pattern Guide 06e: Language Control