Planet CCRMA

3. The first four beeps

Go ahead and copy and paste the following SuperCollider code fragment to the "SuperCollider Workspace" buffer:

s = Server.local.boot;

// statements enclosed in ( ) on separate lines should be executed
// together, either by double clicking on the first parenthesis and
// evaluating the region, or by pressing C-M-x inside the expression.

(
// create a new SynthDef and send it to the server
SynthDef("tutorial-sine", { arg out=0, amp=1.0, freq=440, i_dur=1.0;
	var env, sine;
	// i_* arguments are fixed at instantiation time and cannot be modulated
	// doneAction 2 means free the synth node when the envelope has finished
	env = Line.kr(1, 0, i_dur, doneAction: 2, mul: amp);
	// the mul ugen input is usually more efficient than *
	sine = SinOsc.ar(freq, mul: env);
	// output two channels on bus 0
	Out.ar(0, [sine, sine]);
}).send(s);
)

(
// node object style
Task({
	var freq, dur; 
	freq = 440;
	dur = 1.0;
	4.do { arg i;
		// use Synth.grain rather than Synth.new because the
		// Synth deallocates itself, so we don't need a node id
		Synth.grain(
			// see C-c C-h Synth
			"tutorial-sine",
			["amp", 0.2, "freq", freq, "i_dur", dur],
			s
		);
		dur.wait;
	}
}).play
)
[Important]Important

Supercollider will use Jack for its audio input/output, so make sure the Jack server is already running.

It is time to get things started, position your cursor anywhere in the first line:

s = Server.local.boot;

Go to the "SCLang" drop down menu and click on "Evaluate Line" (or use the Ctrl-c Ctrl-c keyboard shortcut). The Supercollider server should start up and create eight input and output ports in the Jack server (if you are using Qjackctl to run the Jack server you could go to the "Connections" window and verify that the inputs and outputs were created). In the *SCLang* buffer you should have seen something similar to this:

booting 57110
a Server
Using Altivec: no
SC_JackDriver: jack name is SuperCollider
reading map file
SC_JackDriver: connected  alsa_pcm:capture_1 to SuperCollider:in_1
SC_JackDriver: connected  alsa_pcm:capture_2 to SuperCollider:in_2
SC_JackDriver: max output latency 0.005333
SC_JackDriver: connected  SuperCollider:out_1 to alsa_pcm:playback_1
SC_JackDriver: connected  SuperCollider:out_2 to alsa_pcm:playback_2
SuperCollider 3 server ready..
Zeroconf: publishing service _osc._udp. on port 5855 succeeded
notification is on

Now evaluate the two remaining blocks of code (the SynthDef block and the Task block). First highlight the SynthDef block by double clicking on its opening parenthesis and then go to the SCLang menu and click on "Evaluate Region" (or use the Ctrl-c Ctrl-x keyboard shortcut). This will send the SynthDef to the SuperCollider server. The *SCLang* buffer will report:

a SynthDef

Do the same with the Task block (this is what actually uses the SynthDef we just defined to make sound). The *SCLang* buffer will report:

a Task

After this you should hear four 440 Hz sine tones spaced 1 second apart with a decaying envelope. So we're done, SuperCollider went "beep beep beep beep"!