To follow this tutorial you should read
and
SuperCollider consists of three separate components: The sound synthesiser (audio server), the programming language (and language interpreter) and the code editor (integrated development environment, or shortly, IDE).
The server can run either inside the language application ("internal server"), as a separate program on the same machine ("local server"), or run on a different computer across a network connection. The language application sends command messages to the server using a subset of the Open Sound Control protocol.
In order to run sound we need to start a server running. The easiest way to start a server is to click on "Boot Server" in the pull-up menu you get by clicking on the server stats field on the bottom of the IDE's editor window. Or by clicking on the "Start Server" button in the respective server window. This you get with s.makeWindow (for instance for the default server) for any server object you created (see below). Sometimes though it is useful to start a server programmatically. To do this we need to get or create a server object and tell it to "boot". Two servers, internal and local, are predefined.
The internal server runs in the same process as the SuperCollider application. It is internal to the program itself.
VERY IMPORTANT : This line must be executed for the variable 'i' to be set. The mechanics are different depending on your platform. The macOS standard is to place the cursor anywhere on this line and press the "Enter" key on the numeric keypad. Pressing the main return key does not execute code! This allows you to write code fragments of multiple lines. To execute a multi-line block of code, select the block and press "Enter." For convenience, a code block can be enclosed in parentheses, and the entire block selected by double-clicking just inside either parenthesis. For instructions in other editors (e.g. on Linux or Windows), consult the documentation specific to that platform. See also the helpfile Keyboard Shortcuts for key commands in other editors. If you don't have an enter key, then you can use Ctrl-Return, Ctrl-C, Fn-Return (on some Macs), or Shift-Return.
The local server runs on the same machine as the SuperCollider application, but is a separate program, 'scsynth' (or 'supernova').
s
is set to the local server at startup. For further information see the Server helpfile.To boot the server you send it the boot message.
To quit the server send it the quit message.
We can also create a server to run. To create a server object we need to provide the IP address or the server and a port number. Port numbers are somewhat arbitrary but they should not conflict with common protocols like telnet, ftp http, etc. The IP address 127.0.0.1 is defined to mean the local host. This is the IP address to use for running a server on your own machine.
It is not possible to boot a server on a remote machine, but if you have one running already or you know of one running, you can send messages to it. You create the server object using the IP address of the machine running the server and the port it is using.
(note: This tutorial uses raw OSC commands as described in Server Command Reference, rather than the classes Synth and Group. See those helpfiles also for some simpler ways of working with Synths. This tutorial explains the basic underlying design of Synths and SynthDefs).
Now lets make some audio.
Boot the server:
Create a SynthDef. A SynthDef is a description of a processing module that you want to run on the server. It can read audio from the server's audio buses, read control from the control buses and write control or audio back to buses. Here we will create a sine oscillator and send it to audio bus zero.
Send the SynthDef to the server.
Start the sound. The /s_new
command creates a new Synth which is an instance of the "sine" SynthDef. Each synth running on the server needs to have a unique ID. The simplest and safest way to do this is to get an ID from the server's NodeIDAllocator. This will automatically allow IDs to be reused, and will prevent conflicts both with your own nodes, and with nodes created automatically for purposes such as visual scoping and recording. Each synth needs to be installed in a Group. We install it in group one which is the default group. There is a group zero, called the RootNode, which contains the default group, but it is generally best not to use it as doing so can result in order of execution issues with automatically created nodes such as those mentioned above. (For more detail see the Default Group, RootNode, and Order of execution helpfiles.)
Stop the sound.
Stop the server.
SynthDef has three methods which send the def automatically, load which writes it to disk, and send which sends it without writing it to disk. The latter can be useful to avoid clutter on your drive, but is limited to SynthDefs up to a certain complexity.
Most generally useful and recommended is to use the method add, which sends or writes to disk only if it can't send, and it sends to all servers listed in the SynthDefLib (A server can be added by SynthDescLib.global.addServer(server)).
It is useful to be able to specify parameters of a synth when it is created. Here a frequency argument is added to the sine SynthDef so that we can create it
Play a 900 Hz sine wave.
Play a 1000 Hz sine wave.
Playing three voices at once
Playing three voices at once using bundles. Bundles allow you to send multiple messages with a time stamp. The messages in the bundle will be scheduled to be performed together. The time argument to sendBundle is an offset into the future from the current thread's logical time.
You can send messages to update the values of a Synth's arguments.
Play a 900 Hz sine wave.
Change the frequency using the /n_set command. You send the node ID, the parameter name and the value.
You can dynamically add and remove an effect to process another synth. In order to do this, the effect has to be added after the node to be processed.
This works because we added the effect after the other node. Sometimes you will need to use groups or /n_after
to insure that an effect gets added after what it is supposed to process.
Play a 900 Hz sine wave.
Put a frequency value on the control bus.
Map the node's freq argument to read from control bus #10.
Change the value on the control bus.
Start a control process that writes to bus #10. The EnvGen doneAction will free this node automatically when it finishes.
Free the node.