Hints for getting started with SuperCollider

Here are some tips that took me a long time to find out about or where not self evident. They will might save you some time when your starting out with SC.

.ar and .kr

Most UGens have 2 creation functions .ar and .kr

.ar
Audio rate. Much more accurate/high-bandwidth signal but bigger CPU cost
.kr
Control rate. Useful for control signals but less dense signal and hence less CPU usage.

Both can be used to make sound but if your using a UGen to modulate the inputs to another (apart from signal in) you want .kr although you can use both.

Debugging

Language side

.post
.postln
print out the value to the post window
.postcs
post the compileString which shows you the classes of the object you post

Server side

.poll

Adding .poll to a UGen will send back a stream of values to the post window.

{ SinOsc.ar(SinOsc.kr(1, 220, 1440)).poll }.play

should give you a print out in your post window like so:

Synth("temp__1" : 1001)
UGen(SinOsc): 0
UGen(SinOsc): -0.56705
UGen(SinOsc): 0.914946
UGen(SinOsc): -0.902219
UGen(SinOsc): -0.975925
UGen(SinOsc): 0.817525
UGen(SinOsc): 0.258627
UGen(SinOsc): 0.875621
UGen(SinOsc): -0.203138
UGen(SinOsc): -0.799577
UGen(SinOsc): -5.84231e-05

Short errors and long errors

If its a short error message then its usually a syntax error and your missing a semi-colin ';' somewhere before where the error messages says its occurring or you haven't declared a variable as in this case:

• ERROR: Variable 'myUndefinedVariableForTheExample' not defined.
  in file 'selected text'
  line 1 char 32:

  myUndefinedVariableForTheExample.postln 

-----------------------------------
nil

How to read the big nasty error messages is important. Sadly there is no line number or even a print out of the offending line (like most other programming languages). Here my code was:

f.put(a)

and I have not defined the variable f so this is why the RECEIVER is "nil" which is the give away here.

ERROR: Message 'put' not understood.
RECEIVER:
   nil
ARGS:
Instance of Event {    (0x11ca52d08, gc=C4, fmt=00, flg=00, set=03)
  instance variables [5]
    array : instance of Array (0x1188ebb68, size=12, set=4)
    size : Integer 3
    proto : nil
    parent : nil
    know : true
}
CALL STACK:
    DoesNotUnderstandError:reportError   0x124352318
        arg this = <instance of DoesNotUnderstandError>
    Nil:handleError   0x11c776f58
        arg this = nil
        arg error = <instance of DoesNotUnderstandError>
    Thread:handleError   0x118931ea8
        arg this = <instance of Thread>
        arg error = <instance of DoesNotUnderstandError>
    Object:throw   0x123f0ff98
        arg this = <instance of DoesNotUnderstandError>
    Object:doesNotUnderstand   0x124464f98
        arg this = nil
        arg selector = 'put'
        arg args = [*1]
    Interpreter:interpretPrintCmdLine   0x12647d5f8
        arg this = <instance of Interpreter>
        var res = nil
        var func = <instance of Function>
        var code = "f.put(b)"
        var doc = <instance of CocoaDocument>
    Process:interpretPrintCmdLine   0x122f201f8
        arg this = <instance of Main>
For advice: [http://supercollider.sf.net/wiki/index.php/DoesNotUnderstandError#put]

To read the CALL STACK you have to start at the bottom and read upwards. You get the object that was called and the variables it knows about. You can see here under the Interpreter:interpretPrintCmdLine you can see the line of code that when wrong var code = "f.put(b)", and then the next object up when it tried to run this line, Object:doesNotUnderstand, this is supposed to be f but is nil and i try and call put on it. You'll find the rest of the call stack after :doesNotUnderstand usually doesn't convey useful information.

Handy shortcuts

Cmd + Shift + c
Clear the post window
Cmd + \
Bring post window forward
Cmd + d
General help
[highlight word] + Cmd + d
Look up that word directly in the help
[highlight word] + Cmd + y
Open the code for that UGen/function or a list of objects that implement it.