File: SC_website_example.scd

package info (click to toggle)
supercollider 1%3A3.10.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,496 kB
  • sloc: cpp: 283,513; lisp: 74,040; ansic: 72,252; sh: 23,016; python: 7,175; makefile: 1,087; perl: 766; java: 677; yacc: 314; lex: 175; ruby: 136; objc: 65; xml: 15
file content (58 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
// the old sc website example
This example comes from supercollider.sourceforge.net as of 2003. It uses a loop to generate 40 different variations on a SynthDef, and then a process to play them.
*/
(
40.do({ arg i;
	SynthDef(
	"rperc" ++ i.asString,
	{ arg i_bus = 0, amp = 0.1, rate = 1;
		var n = 12;
		var exc, out;
		exc = // exitation signal
			  // .ar or .kr means it's a unit generator
			WhiteNoise.ar *
			Decay.kr(
			  Impulse.kr(0,0,amp*0.1),
			  rrand(0.2,1.0)
			);
	  out = Klank.ar(`[   // resonator
		{exprand(100.0, 10000.0)}.dup(n),
		{ rrand(0.1,1.0) }.dup(n),
		{exprand(0.05,1.0)}.dup(n)
	  ], exc, rate);
	  DetectSilence.ar(out, 0.0001, 0.1, 2);
	  Out.ar( // output to bus number i_bus
		i_bus,
		Pan2.ar( out, rrand(-1.0,1.0))
	  );
  }).add;
});
)

// a process to use them.

(
var s;
s = Server.local;
Task({
  var dur=0.2, inst = \rperc0, amp = 0.05;
  inf.do({	// do forever
	  // 30% chance of picking new synth
	if (0.3.coin, {
	  inst = "rperc" ++ 40.rand.asString;
	  amp = exprand(0.02,0.2) * 0.5;
	});
	// allocate new synth on server
	s.sendBundle(0.2, [
	  \s_new, inst, -1, 0, 0,
	  \amp, amp,
	  \rate, exprand(0.5,2)
	]);
	if (dur.coin, {
		dur = 0.1 + 1.9.rand
	});
	dur.wait;
  }); // inf.do
}).play(TempoClock.default);
)