home/ atoms/ sc-writing-classes

SuperCollider classes encapsulate reusable synthesis behaviour and extend the language

SuperCollider is an object-oriented language where you can define your own classes in .sc files placed in the Extensions folder. A class definition specifies instance variables, class variables, and methods. After saving a .sc file and recompiling (Ctrl+Shift+L), the class is available throughout SC. Writing classes allows factoring reusable synthesis algorithms or performance tools out of one-off scripts into maintainable, nameable objects. The tutorial provides NastySynth.sc and SuperMario.sc as worked examples. Key practice: identify reusable patterns in existing scripts and extract them into class methods with clear arguments. Classes also enable building domain-specific languages on top of SuperCollider.

Examples

// Example class skeleton
MyInstrument {
  var freq, amp;
  *new {|f=440, a=0.1| ^super.new.init(f,a) }
  init {|f,a| freq=f; amp=a; this.play }
  play { {SinOsc.ar(freq,0,amp)}.play }
}

Assessment

Take any SynthDef-based patch you have written and refactor it into a class: the class should expose play, stop, and at least one parameter-setter method. Verify the class behaves identically to the original script.

“Convert one of your existing programs into a class and client code; how does this neaten and clarify your work?”
corpus · nick-collins-supercollider-tutorial-12-week-course · chunk 2