-
Notifications
You must be signed in to change notification settings - Fork 2
Quick Tips and Shortcuts Reference
-
s: the default server, running on localhost. By default this is reserved as an alias forServer.local
Shift + Enter: Execute a line of SuperCollider code. If the cursor is enclosed by parenthesis, the entire
block is executed. Enclose code in parenthesis if you want to run multiple lines.
s.boot; // Pressing Shift + Enter here executes one line
( // Pressing Shift + Enter here executes both lines
s.boot; // Pressing Shift + Enter here executes both lines
3.cubed; // Pressing Shift + Enter here executes both lines
) // Pressing Shift + Enter here executes both lines
You can also highlight the code you want to execute, then press Shift + Enter to execute the highlighted code.
Command + D: Look up documentation the a class or method that you cursor is currently located at.
Shift + Command + D: Look up documentation for a class or method by bringing up a search bar.
Command + .: Stop all sound.
Local variables must be declared before they are used. They must begin with a lowercase letter. Local variables do not persist between executions.
(
var num;
num = 3.cubed; // Outputs 27
)
var num;
num = 3.cubed; // Executing each line individually does NOT work, since
// local variables do not persist between executions.
Global variables (a.k.a. environment variables) do persist between executions and are not declared with a var statement. Declare a global variable by prepending a tilde (~)
var ~num; // Syntax Error: unexpected '~'
~num = 3.cubed; // Outputs 27 and stores it to ~num
~num.cubed; // Outputs 19683
Lowercase letters a through z are reserved for use as global variables.
The dup command takes an object and turns it into an array with all of the elements being that object.
Use the exclamation point as shorthand
"hello".dup(3) // outputs ["hello", "hello", "hello"]
"hello ! 3 // syntactical shortcut
In classes, instance variables can be given a getter and setter using a syntactical shortcut
where < represents a getter and > represents a setter.
BaseMix : Object {
var <>maxClients; // Allows us to use BaseMixInstance.maxClients
var <>masterVolume = 1.0; // Allows us to use BaseMixInstance.masterVolume
// ... class definition
}
At the start of a function definition, arguments can be defined using a pair of vertical bars
{ arg x = 1; .... } // Function with default argument x = 1
{ |x = 1| ... } // Same thing, but a syntactical shortcut
The SinOsc UGen .ar method takes the following function parameters as shown in its documentation:
ar (freq: 440, phase: 0, mul: 1, add: 0)
Default parameters are included in the documentation, if they exist. The following are all equivalent;
x = { SinOsc.ar(700, 0, 1, 0) }.play;
x = { SinOsc.ar(700) }.play;
x = { SinOsc.ar(700, phase:0, mul:1, add:0) }.play;
x = { SinOsc.ar(700, add:0, mul:1, phase:0) }.play;
When writing a function, declare arguments first (along with possible default values), then variables, then the rest of the code. These must happen in this order:
(
z = {
arg freq=440, amp=1;
var sig;
sig = SinOsc.ar(freq) * amp;
}.play;
)
For synths, you can use the set function to modify an argument as the code is generating audio:
z.set(\freq, 880); // When this line is run, the audio output goes from 440hz to 880hz
// without stopping the execution.
Single-line comments use to slashes
// Single Line Comment
Comments can also be multi-line
/*
Multi
Line
Comment
*/
Note that all operations are evaluated left-to right:
3.cubed + 100 / 2; // Outputs 63.5
3.cubed + (100 / 2); // Outputs 77
Run s.meter to see the exact audio levels for each channel. This is helpful when debugging
where audio signals are flowing internally.
Run s.plotTree to see a visual representation of the execution nodes on the server.
Run s.options.numAudioBusChannels to see the fixed number of audio busses available (defaults to 128)
Run s.options.numOutputBusChannels to see the number of output audio busses (defaults to 8, #0 - #7)
Run s.options.numInputBusChannels to see the number of output audio busses (defaults to 8, #8 - #15)