View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide

live coding with SuperCollider

how to do interactive programming, see also live coding



This is a very basic example, simply to show how the syntax of a little interactive
programming session could look like. For more, see for example here

Some live coding exercitiae

// boot the server

s.boot;

// a synth definition, this can be edited on-the-fly, just select and hit enter

(
SynthDef(\noiseGrain, 
	{ arg out = 0, freq=800, sustain=0.001, amp=0.5, pan = 0; // this are the arguments of the synth function
		var window;
		window = Env.perc(0.002, sustain, amp); // exponential decay envelope
		Out.ar(out, // write to output bus
			Pan2.ar( // panning
				Ringz.ar(PinkNoise.ar(0.1), freq, 2.6), // filtered noise
				pan
			) * EnvGen.ar(window, doneAction:2) // multiplied by envelope
		)
	}
).store;
)


Tdef(\geoff).play; // play a lazy task (it's a routine)

(
Tdef(\geoff, { 
	loop { // do forever (well, until we replace the definition..)
		Synth(\noiseGrain, [\freq, exprand(300, 5000)]); // start random grain on the server
		0.2.wait; // wait a little
	}
})
)


// this can be changed while playing at any time:

(
Tdef(\geoff, { 
	loop {
		20.do {
			Synth(\noiseGrain, [\freq, exprand(300, 5000)]); // start a grain on the server
			0.2.wait; // wait a little
		};
		5.do { |i|
			Synth(\noiseGrain, [\freq, 400 * i + 500, \sustain, 0.01]); // a little sweeplet
			0.1.wait;
		}
	}
})
)

// also subroutines can be forked off:

// define another task
(
Tdef(\lisa, { 
		5.do { |i|
			Synth(\noiseGrain, [\freq, 400 * i + 500, \sustain, 0.01]); // a little sweeplet
			0.1.wait;
		}
});
)

(
Tdef(\geoff, { 
	loop {
		Synth(\noiseGrain, [\freq, exprand(300, 5000)]); // start a grain on the server
		0.2.wait; // wait a little
		Tdef(\lisa).fork; // fork a therad
	}
})
)



Links to this Page