The SuperCollider Pattern library provides a means of specifying dynamic structural transformations of musical processes. It provides similar capabilities as one finds in Nyquist, Elody, Siren, Kyma, HMSL, DMix, and Patchwork.
By using coroutines and streams rather than eager functional methods it is able to work in a lazy event by event method instead of the all-at-once method of Elody and Siren. It provides the kind of dynamic live control found in HMSL but with the more general event models of the others. In Nyquist and Siren certain transformation like Stretch and Transpose are specially coded into the framework. In SuperCollider Patterns, any parameter may have transformations applied to it. The only one treated specially is time, so that parallel streams can be merged.
In order to understand the framework, a number of concepts must be covered. These concepts are embodied in the classes for Streams, Patterns, and Events. You should learn these concepts in the order presented. The framework is built up in layers. If you skip ahead to get to the cool stuff first, you will have missed some important points.
A stream represents a lazy sequence of values. The next value in the sequence is obtained by sending the message next to the stream object. The sequence can be restarted from the beginning by sending the message reset to the stream object. A stream can be of finite or infinite length. When a finite length stream has reached the end, it returns nil.
A stream can be any object that responds to the next and reset messages. Any object that responds to these messages can act as a stream. It happens that the class Object defines next and reset for all objects. In Object, both next and reset are defined to return
this. Thus any object is by default a stream that represents an infinite sequence of itself.
In addition to the default streams implemented by Object, there is a class Stream that provides more functionality such as math operations on streams and filtering of streams.
A generally useful subclass of Stream is the class FuncStream which allows the user to provide functions to execute in response to next and reset. Here is a FuncStream that represents an infinite random sequence:
Another useful subclass of Stream is Routine which is a special kind of function that can act like a Stream. Routines are functions that can return a value from the middle and then be resumed from that point when called again. The yield message returns a value from the Routine. The next time the Routine is called it begins by returning from the yield and continues from that point. See the Routine help file.
Here is a Routine that represents a finite sequence of values:
Stream is a subclass of AbstractFunction which means that one can do math operations on streams to produce other streams.
Applying a unary operator to a stream:
Using a binary operator on a stream:
Using a binary operator on two streams:
Streams respond to the messages
reject by returning a new Stream.
collect message returns a stream that is modified by a function in the same way as the collect message sent to a Collection returns a modified Collection.
select message creates a stream that passes only items that return true from a user supplied function.
reject message creates a stream that passes only items that return false from a user supplied function.
Here is a sound example to show how you might use Streams to generate musical material.
More about Streams can be learned from the book A Little Smalltalk by Timothy Budd. He calls them Generators and shows how they can be used to solve problems like the "eight queens" problem etc.
To go to the next file: Understanding Streams, Patterns and Events - Part 2