Posted Monday, 4 June 2012

QuickRef for SuperCollider

In a previous post I mentioned Scott Wilson's tutorial as a really good starting point for learning SuperCollider (SC). Below I have summarised just about everything (including codeblocks) written in that tutorial, but this time all on one page!

This is so that once you have read the tutorial you have a Quick Reference to help you get started. You can navigate the material quickly using jumplinks:

...or just go ahead and scroll down the whole page.

There are also some common keyboard shortcuts and common SC methods right at the bottom: Common methods and shortcuts

[back to top]Tutorial #1: First Steps

Literals and no-args
You can treat literals as objects, and you can omit brackets for no-argument methods:

  "Hello World!".postln;

Blocks (and variables)
To execute several statements at once, wrap them in a block - double-click anywhere inside the brackets to select the whole block:

  "Call me, ".post;

[back to top]Tutorial #2: Start Your Engines

Boot a server
Boot a localhost server via the GUI, or by code:


Interpreter variables
s is just an interpreter variable, which is pre-assigned the value from Server.local:


Interpreter variables (a - z) are pre-declared when you start up SC, and have global scope.

Environment variables
You can make your own variables that act like interpreter variables - you don't have to declare them and they have global scope (but for the same reason they are not efficient):

  ~sources = //whatever

(They are introduced on the Groups page)

Local vs. internal
The local server is the localhost, communicated with over the network, but residing on the same machine as the client. Using the local server is no different to using any networked sever.

The internal server runs as a process within the client app; basically a program within a program. The main advantage is that it allows the two applications to share memory, which allows for things like realtime scoping of audio. The disadvantage is that the two are then interdependent, so if the client crashes, so does the server.

[back to top]Tutorial #3: Functions and Other Functionality

Functions are objects
Functions can be assigned and treated as objects:

  f = { "Function evaluated".postln; };

(The method .value just says 'evaluate this method now')

Functions can have arguments:

  f = { arg a, b; a - b; };
  f.value(5, 3);

Equivalent syntax
Declare arguments within pipes:

  f = { |a, b| a - b; };

SuperCollider supports polymorphism:

  f = { arg a; a.value + 3 };
  f.value(3);               // Send an int
  f.value({ 3.0.rand; });   //Send a function
          //...either way .value works just fine

Named parameters
You can use named parameters:

  f = { arg a, b; a / b; };
  f.value(b: 2, a: 10);

(You can mix regular and named parameters, but regular must come first)

Default arguments
You can set defaults:

  f = { arg a, b = 2; a + b; };
  f.value(2);    // 2 + 2

Method variables
Internal method variables can be declared, but must be directly after args:

  f = {
    arg a, b;
    var myVar1, myVar2;
    //rest of method

Block variables
Internal block variables must be declared at the start of the block:

    var myFunc;
    myFunc = { |input| input.postln; };
    myFunc.value("bar"); //etc

Operator precedence
There isn't any. Use brackets:

  1 + 2 * 3; //9
  1 + (2 * 3); //7

[back to top]Tutorial #4: Functions and Sound

Instantiation methods
Various static methods are designed to help you instantiate objects with certain properties:

  x = //equiv to x = SomeObject(0.5)
  x =, 0, 0.2) //audio rate
  x =, 0, 0.2) //control rate

Unit generators
SinOsc is a type of UGen. The ar and kr methods accept common arguments:, phase, mul)
  //frequency is in Hertz
  //phase is in radians (between 0 and 2*pi)
  //mul is multiplier (aka amplitude)

(Read more on phase)

The 'add' argument
UGens often also come with an optional 'add', as well as mul. These are useful to create kr signals, i.e. if you want to generate a smooth volume envelope:, 1.5pi, 0.5, 0.5);
  //frequency = once every 2 seconds
  //phase = start with volume at 0
  //mul = reduce from (-1 to 1) to (-.5 to .5)
  //add = shift from (-.5 to .5) to (0 to 1)

Use the new kr UGen to control an ar UGen
Use the UGen as a volume envelope on a SinOsc:

  { var ampOsc;
    ampOsc =, 1.5pi, 0.5, 0.5);, 0, ampOsc);

[back to top]Tutorial #5: Stereo

Arrays = multi-channel
Arrays are used to implement multi-channel audio. If your function returns an array of UGens, the .play method will assign each to available channels:

  { [, 0, 0.2),, 0, 0.2)] }.play;

Multi-channel expansion
If you pass an Array argument to a UGen, you get an Array of that UGen:

  { [, 0, 0.2),, 0, 0.2)] }.play;
  {[440, 442], 0, 0.2) }.play; //equivalent to above

Use the UGen 'Pan2' (demoed here with PinkNoise):

  {, -0.3) }.play; //fixed at -0.3
  {, }.play; //moving

(More on SuperCollider Collections)

[back to top]Tutorial #6: Mixing

Addition = mixing
Use +, and a low number for mul, to mix UGen outputs together:

  { +, 0.2) }.play;

The 'Mix' class
You can use Mix to mix an array of UGens into a single channel:

    [, 0, 0.2),, 0.2)]
  ).postln }.play;

...or to mix an array of arrays, i.e. an array of stereo channels, into a single stereo channel:

    var a, b;
    a = [, 0, 0.2),, 0.2)];
    b = [, 0, 0.2),, 0.2)];
    Mix([a, b]).postln;

Note that Mix() is equivalent to

Mixing on a loop
Mix.fill allows you to mix the same UGen multiple times with parameters:

    var n = 8;
        { + 500.0.rand, 0, 1 / n) }

Mixing on a loop with an index parameter
As above, but taking advantage of the index argument, which increments with each call:

    var n = 8;
          arg index;
          var freq;
          freq = 440 + index;
 , 0, 1 / n);

The index parameter is a special argument which is filled in for you by convention. See the list at the bottom of this post.

[back to top]Tutorial #7: Scoping and Plotting

Make a graph of the signal produced by the output of the Function:

  { +, 0.2) }.plot; //default 0.01
  { +, 0.2) }.plot(1); // 1 sec

(Internal server only - make sure it is booted)
Show an oscilloscope of the signal produced by the output of the Function:

  { +, 0.2) }.scope;

Scoping with zoom
Just add the named parameter:

  { +, 0.2) }.scope(zoom: 10);

Scoping any time
Scope the internal server anytime:

    [, 0, 0.2),, 0, 0.2)]
  Server.internal.scope; //or s.scope if internal is default

Frequency scope
A nice one (not mentioned in the tutorial) is the frequency analyzer:

  { +, 0.2) }.freqscope;

[back to top]Tutorial #8: Help

Syntax shortcuts
Common syntax shortcuts are listed here. There are a range of shortcuts, particularly good for dealing with collections.

Finding help
The tutorial help page is here, an extended help reference is here: More on Getting Help

Snooping around SC
SuperCollider has class browsers and other built-in approaches to snooping on source code - find out about them here.

Programmatically navigating the API
Objects have methods for finding definitions (this is introduced on the Groups page).

  Group.superclass; //this will return 'Node'
  Group.findRespondingMethodFor('set'); //Node-set
  Group.findRespondingMethodFor('postln'); //Object-postln
  Group.helpFileForMethod('postln'); //opens Object help file

[back to top]Tutorial #9: SynthDefs

Functions create SynthDefs
If you play a function, behind the scenes it creates a SynthDef:

  //these two are equivalent
  {, 0, 0.2) }.play;"tutorial-SinOsc",
    {,, 0, 0.2)) }

(The first argument to identifies the SynthDef, the second is a function known as a 'UGen Graph Function', since it tells the synth how to connect various UGens together to make a synth)

Manipulate a SynthDef returns a Synth, which you can manipulate / free:

  x = {, 0, 0.2) }.play;
  y ="myDef",
      {,, 0, 0.2)) }).play;; // free just x; // free just y

Send and load
Methods for sending a SynthDef to a server without causing playback. Allow you to create additional synths directly on the server without having to parse the code again:"myDef",
      {, }).send(s);
  x ="myDef");
  y ="myDef");

(send just sends, load saves to disk and the server reads from disk)

Objects evaluate only on the client
Compare the two examples - the first creates a new frequency each time, the second creates a new frequency once and that frequency is fixed with all new instantiations:

  f = { + 200.rand, 0, 0.2) };
  x =;
  y =;
  z =;;;;

      {, + 200.rand, 0, 0.2)) }).send(s);
  x = Synth("myDef");
  y = Synth("myDef");
  z = Synth("myDef");;;;

Use arguments to create variety
You could use the 'Rand' UGen to get round this, but more common to use args:

  SynthDef("myDef", { arg freq = 440, out = 0;,, 0, 0.2));
  x = Synth("myDef");
  y = Synth("myDef", ["freq", 660]);
  z = Synth("myDef", ["freq", 880, "out", 1]);

Change values after instantiation
Synth understands some methods which allow you to change the values of args after a synth has been created, one example is set:"myDef", { arg freq = 440, out = 0;,, 0, 0.2));
  x ="myDef");
  x.set("freq", 660);
  x.set("freq", 880, "out", 1);

Use symbols not strings
Symbols are more 'typesafe':

  "a String" === "a String"; //false
  \aSymbol === 'aSymbol';    //true
  "this" === \this;          //false

[back to top]Tutorial #10: Busses

Bus indices
Busses are zero-indexed, in the order: out, in, private:

  2 outs, 2 ins       4 outs, 2 ins
  0: Output 1         0: Output 1
  1: Output 2         1: Output 2
  2: Input 1          2: Output 3
  3: Input 2          3: Output 4
  4: Private 1        4: Input 1
  5: Private 2        5: Input 2
  etc.                6: Private 1
                      7: Private 2

(See ServerOptions for information on how to set the number of input and output channels, and busses)

Read and write to bus indices
Use bus indices directly (first arg is 'base' index, second argument is number of channels, counting up from that):,, 0, 1));, 1); //returns an OutputProxy, 4); //returns an Array of 4 x OutputProxy

Use Bus objects to avoid index-handling
Get a two channel control Bus, and a one channel private audio Bus (one is the default):

  b = Bus.control(s, 2);
  c =;

Free up busses after use
The indices from Bus can then be reallocated:

  b = Bus.control(s, 2);;

Busses support downsampling but not upsampling
The first is legal but the second is not:


(However most UGens support upsampling and some interpolate to create smooth waves)

Multiple synths on the same bus are summed
In other words, mixed:

  SynthDef("myDef", { arg freq = 440, out = 0;,, 0, 0.2));
  // both write to bus 1, and their output is mixed
  x = Synth("myDef", ["out", 1, "freq", 660]);
  y = Synth("myDef", ["out", 1, "freq", 770]);

Set the (constant) value of a kr bus
Use .set to send a fixed value:

  b = Bus.control(s, 1); b.set(880);
  c = Bus.control(s, 1); c.set(884);

Get the value of a bus (delegate)
.get takes a delegate function as an argument, because of the latency involved in requesting the sample from the server. The interpreter will go ahead and execute the next line of the main thread:

  f = nil;
  b = Bus.control(s, 1); b.set(880);
  b.get({ arg val; val.postln; f = val; });
  f.postln; //this will most likely be nil as it will be             //executed before .get has had a response from             //the server and executed the delegate

Map a bus to a Synth argument
Continuously evaluate a busses value in a Synth:

  b = Bus.control(s, 1); b.set(880);
  c = Bus.control(s, 1); c.set(884);
  x = SynthDef("myDef", { arg freq1 = 440, freq2 = 440;,[freq1, freq2], 0, 0.1));
  }).play(s);\freq1, b, \freq2, c);

Order of execution
Within each cycle, the server runs through all synths in order. You have to maintain a good order so that synths that write samples to a bus are calculated before the synths that read the samples from that bus:

  //.after and .before
  x ="xDef", [\bus, b]);
  y = Synth.before(x, "yDef", [\bus, b]);
  z = Synth.after(x, "zDef", [\bus, b]);

  //equivalent to
  x ="xDef", [\bus, b]);
  y ="yDef", [\bus, b], x, \addBefore);
  z ="zDef", [\bus, b], x, \addAfter);

Above, x is the target, [\addBefore, \addAfter, \attToHead, \addToTail, \addReplace] is the addAction.

There are also methods: [Synth.head, Synth.tail, Synth.replace].

See more on Order of Execution, including info on groups.

Useful examples using busses
There are some really useful example code listings using busses - see Busses in Action and More Fun with Control Busses.

[back to top]Tutorial #11: Groups

Group and Synth both derive from Node
A Synth and Group are both types of Node:

    Synth  Group

Groups for bulk ordering
Groups are useful for controlling order:

  ~sources =;
  ~effects = Group.after(~sources); //whole ~effects group after

  x = Synth(\anEffect, ~effects);
  y = Synth(\aSource, ~sources);
  z = Synth(\aSource, ~sources);

(See an example with actual SynthDefs)

Groups for bulk messaging
Groups allow you to easily group together Nodes and send them messages all at once:

  g =;{ { arg amp = 0.1;; }.play(g); });
  g.set(\amp, 0.005); // turn them all down

Groups can contains Groups and Synths
Each Group can contain a mixture of Nodes, i.e. a combination of Synths and more Groups, i.e:


Query all nodes
Find out what's happening on the server using s.queryAllNodes:

  nodes on localhost:
  a Server
  Group(0)          //RootNode
      Group(1)        //DefaultNode
          Group(1000)    //User-defined Groups and Synths
                  Synth 1002

Root node and Default node
- RootNode is a top-level for everything to hang off
- DefaultNode is where all your new nodes should go

It's so that methods such as Server.scope and Server.record (which create nodes which must come after everything else) can function without running into order of execution problems.

[back to top]Tutorial #12: Buffers

Arrays on the server
Buffers are just in-memory arrays of floats on the server:

  [0.1, 0.2, 0.3, 0.4, 0.5]   [0.5, 0.4, 0.3, 0.2, 0.1]

(They are designed to handle sound but could really be any values)

Number of buffers available
Like busses, the number of buffers is set before you boot a server (using ServerOptions).

Buffers are zero-indexed
Buffers are zero-indexed, but as with Busses there is a handy Buffer class.

Allocate a 2-channel buffer
Use the Buffer class:

  b = Buffer.alloc(s, 100, 2); // 2 channels, 100 frames; // free the memory when done

(Actual number of values stored is numChannels * numFrames, in this case there will be 200 floats)

Allocate in seconds rather than frames
Multiply by the server's sample rate:

  b = Buffer.alloc(s, s.sampleRate * 8.0, 2); // 8 second stereo;

Read a file into a buffer
Read a file into a buffer:

  b =, "sounds/any.wav");

Record sound into a buffer
Record sound into a buffer:

  x = {!2, b)}.play;;

Playback from a buffer
Playback from a buffer:

  x = SynthDef("myDef",{ arg out = 0, buf; out,
        //Args: numChannels, buffer, playbackSpeed, buf,
  }).play(s,[\buf, b]);

(BufRateScale scales the speed, in case the wavefile has a different sample rate to the server)

Play a file straight off the disk
Load it outside the synth so it can be reused. Note - no rate control:

  SynthDef("myDef",{ arg out=0, buf;, 1, buf )

  b = Buffer.cueSoundFile(s,"sounds/mySound.aiff", 0, 1);
  y ="myDef", [\buf,b], s);

Get info from a buffer
Use it's properties:

  b =, "sounds/mySound.wav");

...but make sure the file is loaded into the buffer first:

  b =, "sounds/mySound.wav", action: { arg buffer;       //read properties here   });

Get and set data values
Remember multichannel buffers interleave their data, so for a two channel buffer index 0 = frame1-chan1, index 1 = frame1-chan2, index 2 = frame2-chan1, and so on:

  b = Buffer.alloc(s, 8, 1);
  b.set(7, 0.5); //index, value
  b.get(7, {|msg| msg.postln});

Read / write multiple values
Note the upper limit on the number of values you can get or set is usually 1633, due to packet size:

  b.setn(0, Array.fill(b.numFrames, {1.0.rand}));
  b.getn(0, b.numFrames, {|msg| msg.postln});

Read / write > 1633 values
Use b.loadCollection and b.loadToFloatArray:

  v = FloatArray.fill(44100, {1.0.rand2}); //white noise
  b = Buffer.alloc(s, 44100);
  // load the FloatArray into b, then play it
  b.loadCollection(v, action: {|buf|
      x = {, buf,,
        loop: 1) * 0.2;

  // Get the FloatArray back, compare it to v
  // 0 = from beginning, -1 = load whole buffer
  b.loadToFloatArray(0, -1, {|floatArray|
      (floatArray == v).postln });;

Plot and play
Note play's argument - loop. If false (default) the resulting synth is freed automatically:

  //see the waveform

  //play the contents; //frees itself
  x =; //loops so doesn't free

Buffers for waveshaping
The method 'cheby' fills the buffer with a series of chebyshev polynomials. The 'Shaper' UGen then uses the dataset stored in the buffer to shape a SinOsc:

  b = Buffer.alloc(s, 512, 1);
  x = play({
      b,, 0,,1,6)),

[back to top]Tutorial #13: Scheduling Events

Three types of clock
Note that while there is only one SystemClock, there can be many TempoClocks all running at different speeds, if need be.

  • TempoClock - Musical sequencing, can change tempo and is aware of meter changes
  • SystemClock - Actual time, in seconds
  • AppClock - Also runs in seconds but has a lower system priority (better for graphic updates and other non-timecritical activities)

Schedule relative to current time
Say 'hello' in 5 seconds:

  SystemClock.sched(5, { "hello".postln });

Schedule for an absolute time
Provide a time at which to say 'hello':

  var timeNow =;
  TempoClock.default.schedAbs(timeNow + 5,
      { "hello".post; nil });

Change the tempo
Change the tempo:

  TempoClock.default.tempo = 2; // 2 beats/sec, or 120 BPM

Get a handle to the clock from inside a function
Use thisThread.clock. Once you know the clock, you can find out what time it is using beats:;;;;

Fire a function many times
If you schedule a function that returns a number, the clock will treat that number as the amount of time before running the function again:

  TempoClock.default.sched(1, { rrand(1, 3).postln; });

(Stop it with Cmd - .)

Fire a function once
Return Nil:

  TempoClock.default.sched(1, { rrand(1, 3).postln; nil });

Don't return zero
You'll get an infinite loop.

[back to top]Tutorial #14: Scheduling with Routines and Tasks

It's good to read about Routines and Tasks as taking this step-by-step approach to your understanding pay dividends when you learn Patterns. However the examples given below can be more elegantly expressed - when you do this for real - using Patterns. See Tutorial #15 for more when you are ready.

(See the note on timing and latency at the bottom if you do decide to go ahead with this approach, or read more about Server Timing)

Routines yield values
The values are arbitrary. Execution is controlled by a pointer.

When .next is called on an instance of Routine, execution begins at the beginning of the specified function. When execution reaches a .yield command on a value, execution halts, the pointer is held in memory, and the value is returned.

When .next is called on the instance again, the pointer allows execution to continue from the current position, yielding the next yielded value, and so on.

When there are no more values available, the Routine instance will return nil.

  r = Routine({

Successive calls to yield the following:


You can schedule execution to begin again by yielding numeric values
Instead of using, use TempoClock as illustrated below, or the shorthand As before, execution picks up where it left off.

  r = Routine({

  TempoClock.default.sched(0, r); //instead of; //shorthand for the use of TempoClock

This code posts 1, then waits a second, posts 2, then waits two seconds, and finally posts 1 and waits one more second.

Just keep yielding
You can keep yielding and waiting indefinitely, using loop.

  r = Routine({
    var delta;
    loop {
      delta = rrand(1, 3) * 0.5;
      "Will wait ".post; delta.postln;
      delta.yield; //yield and return this value, which                    schedules the next execution.

  TempoClock.default.sched(0, r);;

Using .stop resets the pointer
So that if you stop mid-way through a Routine, and then start again, the pointer will go back to the beginning of the function and the first value will be yielded again.;

Schedule a Task instead
That's where Task steps in. Task is the same as Routine, except when you stop and restart a Task, the pointer position is retained and execution picks up again from there.

  t = Task({
    loop {
      [60, 62, 64, 65, 67, 69, 71, 72].do({ |midi|
        Synth(\someSynth, [freq: midi.midicps]);

  t.stop; // probably stops in the middle of the scale; // should pick up with the next note

Synchronise Tasks
.play takes several arguments to control its behavior:, quant), doReset, quant)

- clock (both): an instance of the clock you omitted by using the shorthand
- doReset (Task only): If true, reset the sequence to the beginning before playing; if false (default), resume
- quant (both): a quantizer. It's easier just to demonstrate: 4); //start on next 4-beat boundary [4, 0.5]); //next 4-beat boundary + half-beat

Use multiple datasets in a Task (with Routines)
By splitting out data declaration from looping. Here using Routines to store the datasets:

  var midi = Routine({
    [60, 72, 71, 67, 69, 71, 72, 60, 69, 67]
        .do({ |midi| midi.yield });
  var dur = Routine({
    [2, 2, 1, 0.5, 0.5, 1, 1, 2, 2, 3]
        .do({ |dur| dur.yield });

  //looping (in this case, once)
  r = Task({
    var delta;
    while {
      delta =;
    } {
      Synth(\smooth, [freq:, sustain: delta]);
  }).play(quant: + 1.0);

(Note that the examples given here can be more elegantly expressed using Patterns, see Tutorial #15)

(See the note on timing and latency at the bottom if you use this approach, or read more about Server Timing)

[back to top]Tutorial #15: Scheduling with Patterns

Use multiple datasets in a Task (with Patterns)
Data declaration still split out from looping, but here using Patterns to store the datasets:

(Note that the example given here can be more elegantly expressed using a Pattern-only approach, see below)

  var midi = Pseq([60, 72, 71, 67, 69, 71, 72, 60, 69, 67], 1)
  var dur = Pseq([2, 2, 1, 0.5, 0.5, 1, 1, 2, 2, 3], 1)

  //looping (in this case, once)
  r = Task({
    var delta;
    while {
      delta =;
    } {
      Synth(\smooth, [freq:, sustain: delta]);
  }).play(quant: + 1.0);

(PSeq means just spit out the values in declared order, as many times as the second argument - in this case, once)

(See the note on timing and latency at the bottom if you use this approach, or read more about Server Timing)

Use multiple datasets (Patterns-only approach)
Finally, the most elegant solution, using only Patterns:

  SynthDef(\smooth, { |freq = 440, sustain = 1, amp = 0.5|
    var sig;
    sig =, 0, amp) *, sustain, 0.1), doneAction: 2);, sig ! 2)

  p = Pbind(
      // the name of the SynthDef to use for each note
    \instrument, \smooth,
      // MIDI note numbers -- converted automatically to Hz
    \midinote, Pseq([60, 72, 71, 67, 69, 71, 72, 60, 69, 67], 1),
      // rhythmic values
    \dur, Pseq([2, 2, 1, 0.5, 0.5, 1, 1, 2, 2, 3], 1)

Here, PBind does the same job as the Task does in the previous codeblock. However, in a sense it uses convention over configuration to give concise access to a common scenario. Only the necessary values are passed, using given argument names which correspond to the same actions as defined in the Task in the codeblock above.

(Note that the syntax is now right down to the bone - no programming constructs, almost just data. For completeness, this time I have included the example SynthDef (\smooth))

Sample Pattern types: ordering
Many patterns take lists of values and return them in some order:

Return the list's values in order:

  Pseq(list, repeats, offset)

Scramble the list into random order:

  Pshuf(list, repeats)

Choose from the list's values randomly:

  Prand(list, repeats)

Choose randomly, but never return the same list item twice in a row:

  Pxrand(list, repeats)

Like Prand, but chooses values according to a list of probabilities/weights:

  Pwrand(list, weights, repeats)

Sample Pattern types: generate based on parameters
In addition to these basic patterns, there is a whole set of random number generators that produce specific distributions, and also chaotic functions:

Arithmetic series, e.g., 1, 2, 3, 4, 5:

  Pseries(start, step, length)

Geometric series, e.g., 1, 2, 4, 8, 16:

  Pgeom(start, grow, length)

Random number generator, uses rrand(lo, hi) -- equal distribution:

  Pwhite(lo, hi, length)

Random number generator, uses exprand(lo, hi) -- exponential distribution:

  Pwhite(lo, hi, length)

Sample Pattern types: modify the output of other Patterns
Other patterns modify the output of value patterns. These are called FilterPatterns:

Repeat the pattern as many times as repeats indicates:

  Pn(pattern, repeats)

Repeat individual values from a pattern n times. n may be a numeric pattern itself:

  Pstutter(n, pattern)

Sample Pattern types: Patterns inside other Patterns
Other patterns modify the output of value patterns. These are called FilterPatterns:

Random numbers over a gradually increasing range (the upper bound on the random number generator is a stream that starts at 0.01, then proceeds to 0.02, 0.03 and so on, as the plot shows clearly):

  p = Pwhite(0.0, Pseries(0.01, 0.01, inf), 100).asStream;
    // .all pulls from the stream until it returns nil
    // obviously you don't want to do this for an 'inf'
    // length stream!

Order a set of numbers randomly so that all numbers come out before a new order is chosen, use Pn to repeat a Pshuf:

  p = Pn(Pshuf([1, 2, 3, 4, 5], 1), inf).asStream;
  p.nextN(15); // get 15 values from the pattern's stream

Patterns: further reading
This is just an intro - see more documentation to really understand it:

End of tutorial!

[back to top]Quick references
Here is a quick summary of methods and keyboard shortcuts found in the tutorial, plus a couple of helpful extras:

Commonly-used methods

.new Create new object(s) from a static method.
Note that e.g. is equiv to Mix(x)
.post Post the object to the console as a string
.postln As above with newline
.value Return the object's value
(evaluate if it's a function, or just return the object itself)
.play To functions, 'play' means evaluate yourself and play the result on a server
.choose To arrays, means pick any element. The element could be another array (i.e. stereo) or a single value. Arrays can be mixed i.e.
!2 Quickly make mono into stereo

Commonly-used keyboard shortcuts

Cmd - \ Bring the console window to the front
Cmd-SHIFT-C Clear the console
Cmd - . Stop all playback
Cmd - D Open the helpfile for whatever is currently selected
Cmd - J Open the definition file for whatever is currently selected
Cmd - Y (On a method) Show a list of classes which implement this method (polymorphism)

Special arguments

index Injects the current iterator into a loop, e.g.
//Prints 1 2 3
midinote / freq The argument midinote gets converted into a frequency value, and passed as the argument freq, e.g.
 SynthDef(\myInst, { |freq|, *
    Env.linen(0.1, 0.8, 0.1), doneAction: 2)
  ! 2)

 p = Pbind(
  \instrument, \myInst,
  \midinote, Pseq([60, 72], inf)

See also Tutorial #15: Scheduling with Patterns
dur Duration - see Tutorial #15: Scheduling with Patterns
instrument See Tutorial #15: Scheduling with Patterns

All posts

March 2014

February 2014

January 2014

December 2013

November 2013

October 2013

September 2013

August 2013

July 2013

June 2013

May 2013

October 2012

September 2012

August 2012

July 2012

June 2012

May 2012

April 2012

January 2012

December 2011

October 2011

September 2011

August 2011

June 2011

May 2011

April 2011

March 2011

January 2011

November 2010

October 2010

September 2010