SuperCollider - Tutorial Notes
Notas que voy tomando para cada lección del curso de SuperCollider.
Gracias Eli Fieldsteel
Este curso comienza desde cero y consta de 19 lecciones.
Espero actualizar al menos 1 lección por semana.
El post irá creciendo a medida que avance.
SuperCollider is an environment and programming language for real-time audio synthesis and algorithmic composition.
It runs on Mac, Windows and Linux and best of all it's completely free and open-source.
You can download a copy of super collider at supercollider.sourceforge.net (http://supercollider.github.io/download)
This series will target musicians with little or no programming experience who are interested in making electronic music and manipulating sound.
Because of this choice I'll jump right into audio generation and processing while keeping discussions about language and syntax to a minimum, and besides you'll surely pick up on the particulars of language and syntax once you start experimenting.
I also won't spend too much time talking about the theoretical side of digital audio since it's a very broad topic that's probably beyond the scope of this series here I'm talking about things like sample rate, bit depth at the Nyquist frequency and so on.
So instead I'll address theoretical concepts on an ad-hoc basis.
01 Navigating the Environment
When you first open SuperCollider this is what you’ll see.
On your left is the workspace, where you’ll type and evaluate code.
This is what is written to a file when you save your work.
On the lower right is the post window, where SuperCollider communicates with the user by posting either the results of evaluated code or an error message in response to invalid code.
On the top right is the Help documentation.
The post window and help documentation can both be moved and repositioned by clicking and dragging their top bar.
Their can be undocked or detached by clicking the icon at the upper left of each component.
If you choose to detach a component then it becomes a standard window with can move between the foreground or background.
If you close the component it can be reopened by clicking on the view menu and selecting Docklets.
Unlike some previous of SuperCollider there is now a Preferences dialogue under the SuperCollider menu.
Here you can modify the appearance and behaviour of the text editor, customize keyboard shortcuts as well as a few other things.
Let’s take a look at the post window where you can see the there’s been some activity.
Specifically on Startup, SuperCollider will try to compile the class library and load the hep file.
Here you can see the library has been successfully compiled and that the help documents have been successfully indexed.
Here and in many other situations you’ll find it very useful to be able to clear the post window.
To do this right-click on the post window and you’ll see an option to clear.
You’ll probably also see a keyboard shortcut next to the word clear. I suggest memorizing keyboard shortcuts because you’ll probably be using it a lot.
Let's now move on to the workspace to start writing and evaluating code.
The supercollider language is home to a library of classes which represent different types of data, inputs outputs, computation and other types of data anipulation are conceived
as messages that are passed to objects.
When an object receives a message it is said to be the receiver of that message.
The most commonly used syntax for this receiver message paradigm is
Messages are sometimes called methods and these two words are used interchangeably.
In the following example
3 is the receiver of the message cubed
In order to execute this statement we simply place the mouse cursor anywhere on this line and press shift return.
The results of this evaluation is printed in the post window.
To demonstrate error messages let's suppose we've misspelled cubed
If we try to evaluate the post window it displays an error message.
It looks complicated but if we scroll to the top we can see that supercollider was unable to understand the message cudeb.
Let's clear the post window and imagine a slightly different flavor of misspelling like typing a comma instead of a period.
In this case supercollider reports syntax error.
There are several different types of error messages some of which takes some time to decipher and debug but in most cases it'll be simple misspelling an extra character or forgotten parentheses.
Let's clear the post window and discuss the use of variables.
A variable is a named container that used to store a value, not necessarily a number so that it can be referred to and used later.
For instance we can store the value of 3 cubed in the variable X
x = 3.cubed
Like so evaluate this line
and X now holds a value of 27
We can now continue to do operations with X
If we so choose for instance
let's change our variable name from X to number
number = 3.cubed
And if we evaluate we get an error message saying that the variable number is not defined.
This brings up an important concept.
In supercollider there is a distinction made between local variables and global variables.
Local variables must be declared before they are used using a var statement like so
number = 3.cubed;
Local variables must begin with a lowercase alphabetic character but after the first character you're free to use
uppercase letters, numbers, hyphens, underscores, etc
Notice that now we're dealing with multiple statements of code so each statement must end with a semicolon.
There are several ways to evaluate multiple statements simultaneously.
You can highlight everything and press shift return, or easier still you can enclose your code in parentheses
number = 3.cubed;
place the mouse cursor anywhere between them and press command return.
Notice that even though this code has compiled with no errors the variable number is now lost since it was a local variable.
Notice also that we can't run these statements one at a time.
Local variables must be declared and used within the same code execution.
Global variables on the other hand persist after code evaluation.
Lowercase a through Z are reserved for use as global variables or you can proceed a local variable name
with a tilde ~ in order to turn it into a global variable
~number = 3.cubed;
so we could set tilde number equal to three cubed and we'd have no errors technically speaking
Global variables are actually environment variables which means they are specific to a particular environment, but for the beginner it's fine to conceive environment variables as being
When dealing with many statements of code you might often see a single variable being continually overwritten as a piece of data is continually manipulated like so
var foo ;
foo = 3 ;
foo = foo.cubed ;
foo = foo + 100 ;
foo = foo / 2 ;
Here we declare a variable called foo set it equal to three cubed add 100 and divide by two
For the last line we simply output foo´s value
In each statement we set foo equal to the result of the newly manipulated data
We see in the post window that the result is 63.5
If we were to remove these over writings like so
var foo ;
foo = 3 ;
foo + 100 ;
foo / 2 ;
We'd still be computing values but foo would not keep track of these computations, hence when we evaluate this
clump we see Foos original value of 3 which has not changed.
Notice that the original clump can be mathematically rewritten like so
3.cubed + 100 / 2 ;
Demonstrating that methods and operations can be strung together on a single line always evaluated from left to right
Notice that there is no mathematical operator precedence that is to say the addition is done before the division.
Although this is syntactically legal I would argue that the multi-line approach is more clear.
As your code gets longer and longer I strongly advise that you include comments.
A comment is a piece of text that's invisible to SuperCollider that's used to clarify your code in human terms so that for instance someone you're collaborating with can understand what your code is attempting to do.
Comments are also useful if you return to a complicated piece of code you've written several years ago and need to remind yourself what it's all about.
A single line comment is always preceded
with two forward slashes like so
//single line comment
And a multi-line comment is preceded by slash asterisk and appended with asterisk slash
By default comments are read in supercollider.
To close out this tutorial I'll talk just a bit more about the help documentation.
To get help place the cursor on the text you'd like to look up
Click on the help menu at the top and choose Look Up Documentation for Cursor
The keyboard shortcut for this is command D
Again I'd recommend memorizing this since it's very useful.
In this case supercollider searches it's help documents for the word cubed and it comes up with a method called cubed which it tells you is defined for several different classes like sequence above collection and simple number.
You can also bring up a search bar by selecting lookup documentation in the help menu and type whatever you like.
The shortcut for this is shift command D
In this case I've typed oscillator and supercollider returns all the help files that contain the word oscillator you can do a find for text within the current help documentation using the search bar in the upper right corner and you can navigate forward and back through the help documentation just like you would on a web browser.
That's it for this tutorial. In the next we'll start making some sound.