Pattern:
Filter:

Pattern : AbstractFunction : Object

abstract class that holds a list
Source: Patterns.sc

Description

Patterns versus Streams

Pattern is an abstract class that is the base for the Patterns library. These classes form a rich and concise score language for music. The series of help files entitled Understanding Streams, Patterns and Events - Part 1 gives a detailed introduction. This attempts a briefer characterization.

A Stream is an object that responds to next, reset, and embedInStream. Streams represent sequences of values that are obtained one at a time by with message next. A reset message will cause the stream to restart (many but not all streams actually repeat themselves.) If a stream runs out of values it returns nil in response to next. The message embedInStream allows a stream definition to allow another stream to "take over control" of the stream. All objects respond to next and reset, most by returning themselves in response to next. Thus, the number 7 defines a Stream that produces an infinite sequence of 7's. Most objects respond to embedInStream with a singleton Stream that returns the object once.

A Pattern is an object that responds to asStream and embedInStream. A Pattern defines the behavior of a Stream and creates such streams in response to the messages asStream. The difference between a Pattern and a Stream is similar to the difference between a score and a performance of that score or a class and an instance of that class. All objects respond to this interface, most by returning themselves. So most objects are patterns that define streams that are an infinite sequence of the object and embed as singleton streams of that object returned once.

Patterns are defined in terms of other Patterns rather than in terms of specific values. This allows a Pattern of arbitrary complexity to be substituted for a single value anywhere within a Pattern definition. A comparison between a Stream definition and a Pattern will help illustrate the usefulness of Patterns.

example 1 - Pseq vs. Routine

The Pattern class Pseq(array, repetitions) defines a Pattern that will create a Stream that iterates an array. The class Routine(func, stackSize) defines a single Stream, the function that runs within that stream is defined to perform the array iteration.

Below a stream is created with Pseq and an asStream message and an identical stream is created directly using Routine.

example 2 - Nesting patterns

In example 1, there is little difference between using Pseq and Routine. But Pseq actually iterates its array as a collection of patterns to be embedded, allowing another Pseq to replace any of the values in the array. The Routine, on the other hand, needs to be completely redefined.

example 3 - Stream-embedInStream

The message embedInStream is what allows Patterns to do this kind of nesting. Most objects (such as the number 3 below) respond to embedInStream by yielding themselves once and returning. Streams respond to embedInStream by iterating themselves to completion, effectively "taking over" the calling stream for that time.

A Routine can perform a pattern simply by replacing calls to yield with calls to embedInStream.

Of course, there is no concise way to define this stream without using Pseq.

NOTE: For reasons of efficiency, the implementation of embedInStream assumes that it is called from within a Routine. Consequently, embedInStream should never be called from within the function that defines a FuncStream or a Pfunc (the pattern that creates FuncStreams).

Event Patterns

An Event is a Environment with a 'play' method. Typically, an Event consists of a collection of key/value pairs that determine what the play method actually does. The values may be any object including functions defined in terms of other named attributes. Changing those values can generate a succession of sounds sometimes called 'music'... The pattern Pbind connects specific patterns with specific names. Consult its help page for details.

Playing Event Patterns

The -play method does not return the pattern itself. Instead, it returns the EventStreamPlayer object that actually runs the pattern. Control instructions -- stop, pause, resume, play, reset -- should be addressed to the EventStreamPlayer. (The same pattern can play many times simultaneously, using different EventStreamPlayers.)

Recording Event Patterns

Patterns may be recorded in realtime or non-realtime. See the method -record for realtime recording.

For non-realtime recording see the Score helpfile, especially "creating Score from a pattern." It can be tricky, because NRT recording launches a new server instance. That server instance is not aware of buffers or other resources loaded into the realtime server you might have been using for tests. The pattern is responsible for (re)loading any resources (buffers, effects etc.). Pfset or Pproto may be useful.

Class Methods

Inherited class methods

Instance Methods

.asStream

Return a Stream from this pattern. One pattern can be used to produce any number of independent streams.

.embedInStream(inval)

Given a Stream like e.g. Routine, yield all values from this pattern before continuing. One pattern can be used to produce values for any number of independent streams.

Arguments:

inval

The inval is passed into all substreams and can be used to control how they behave from the outside.

.play(clock, protoEvent, quant)

Arguments:

clock

The tempo clock that will run the pattern. If omitted, TempoClock.default is used.

protoEvent

The event prototype that will be fed into the pattern stream on each iteration. If omitted, event.default is used.

quant

see the Quant helpfile.

.record(path, headerFormat, sampleFormat, numChannels: 2, dur, fadeTime: 0.2, clock, protoEvent, server, out: 0, outNumChannels)

Opens a disk file for recording and plays the pattern into it.

Arguments:

path

Disk location for the recorded file. If not given, a filename is generated for you and placed in the default recording directory: thisProcess.platform.recordingsDir.

headerFormat

File format, defaults to Server: -recHeaderFormat - see SoundFile for supported header and sample formats.

sampleFormat

Sample format, defaults to Server: -recSampleFormat.

numChannels

Number of channels to record, default 2.

dur

How long to run the pattern before stopping. If nil (default), the pattern will run until it finishes on its own; then recording stops. Or, use cmd-period to stop the recording. If a number is given, the pattern will run for that many beats and then stop (using Pfindur), ending the recording as well.

fadeTime

How many beats to allow after the last event before stopping the recording. Default = 0.2.

clock

Which clock to use for play. Uses TempoClock.default if not otherwise specified.

protoEvent

Which event prototype to use for play. Falls back to Event.default if not otherwise specified.

server

Which server to play and record. Server.default if not otherwise specified.

out

Output bus to hear the pattern while recording, default = 0.

outNumChannels

the number of out channels to play to the recorder. If larger than numChannels, outNumChannels will wrap .

Inherited instance methods

Undocumented instance methods

++(aPattern)

<>(aPattern)

.addDur(x)

.asEventStreamPlayer(protoEvent)

.asScore(duration: 1.0, timeOffset: 0.0, protoEvent)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asScore/asScore.sc

.buildForProxy(proxy, channelOffset: 0)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.clump(n)

.collect(function)

.composeBinaryOp(operator, pattern, adverb)

.composeNAryOp(selector, argList)

.composeUnaryOp(operator)

.ctranspose(n)

.db(db)

.detune(n)

.differentiate

.do(function)

.drop(n)

.dupEach(n)

.fin(n: 1)

.finDur(dur, tolerance: 0.001)

.flatten(n: 1)

.gtranspose(n)

.integrate

.iter

.keep(n)

.lag(t)

.legato(x)

.lock(n: 1)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/Patterns/extRoutine.sc

.mtranspose(n)

.proxyControlClass

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.reject(function)

.repeat(n: inf)

.reverseComposeBinaryOp(operator, pattern, adverb)

.scaleDur(x)

.select(function)

.streamArg

.stretch(x)

.stutter(n)

.trace(key, printStream, prefix: "")

Examples

Below are brief examples for most of the classes derived from Pattern. These examples all rely on the patterns assigned to the Interpreter variable p, q, and r in the first block of code.

EVENT PATTERNS - patterns that generate or require event streams

GENERAL PATTERNS that work with both event and value streams

VALUE PATTERNS: these patterns define or act on streams of numbers