Removing an old, cherished, yet pointless caveat "This documentation is
[supercollider.git] / examples / pieces / acid_otophilia.scd
blobfad470b6279e3548029aab164f8ec041c40f8494
1 // 08091500Acid309 by_otophilia
3 // try evaluating any of those ~dseqs below
5 ~dseq = [[1,0,0,0, 0,0,0,0, 1,0,0,1, 0,0,1,0], [0,0,0,0, 0,0,0,2, 0,2,1,0, 4,3,3,3], [0,0,0,0, 4,0,0,0, 0,0,0,0, 4,0,0,0], [1,2,4,0, 1,0,4,0, 1,2,4,2, 1,0,4,2], [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0]].flop;
7 ~dseq = [[0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0], [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0], [0,0,0,0, 4,0,0,0, 0,0,0,0, 4,0,0,0], [1,2,4,0, 1,0,4,0, 1,2,4,2, 1,0,4,2], [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0]].flop;
9 ~dseq = [[1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0], [0,0,0,0, 0,0,0,2, 0,0,0,0, 0,0,0,0], [0,0,0,0, 4,0,0,0, 0,0,0,0, 4,0,0,0], [1,2,4,0, 1,0,4,0, 1,2,4,2, 1,0,4,2], [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0]].flop;
11 ~dseq = [[1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0], [0,0,0,0, 4,0,0,2, 0,0,0,0, 4,0,0,0], [0,0,0,0, 0,0,0,0, 0,0,0,0, 4,0,0,0], [1,2,4,0, 1,0,4,0, 1,2,4,2, 1,0,4,2], [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0]].flop;
15 Server.default = Server.internal; s = Server.default;
16 Routine.run {var c; c = Condition.new; s.freeAll; TempoClock.all.do{|x|x.clear}; s.bootSync(c);
18 ( // **** SynthDefs ****
19         
20         SynthDef("kick", {      
21                 arg outBus=0;
22                 var env0, env1, env1m, out;
23                 
24                 env0 =  EnvGen.ar(Env.new([0.5, 1, 0.5, 0], [0.005, 0.06, 0.26], [-4, -2, -4]), doneAction:2);
25                 env1 = EnvGen.ar(Env.new([110, 59, 29], [0.005, 0.29], [-4, -5]));
26                 env1m = env1.midicps;
27                 
28                 out = LFPulse.ar(env1m, 0, 0.5, 1, -0.5);
29                 out = out + WhiteNoise.ar(1);
30                 out = LPF.ar(out, env1m*1.5, env0);
31                 out = out + SinOsc.ar(env1m, 0.5, env0);
32                 
33                 out = out * 1.2;
34                 out = out.clip2(1);
35                 
36                 Out.ar(outBus, out.dup);
37         }).send(s);
38         
39         SynthDef("snare", {     
40                 arg outBus=0, amp=0.8;
41                 var env0, env1, env2, env1m, oscs, noise, out;
42                 
43                 env0 = EnvGen.ar(Env.new([0.5, 1, 0.5, 0], [0.005, 0.03, 0.10], [-4, -2, -4]));
44                 env1 = EnvGen.ar(Env.new([110, 60, 49], [0.005, 0.1], [-4, -5]));
45                 env1m = env1.midicps;
46                 env2 = EnvGen.ar(Env.new([1, 0.4, 0], [0.05, 0.13], [-2, -2]), doneAction:2);
47                 
48                 oscs = LFPulse.ar(env1m, 0, 0.5, 1, -0.5) + LFPulse.ar(env1m * 1.6, 0, 0.5, 0.5, -0.25);
49                 oscs = LPF.ar(oscs, env1m*1.2, env0);
50                 oscs = oscs + SinOsc.ar(env1m, 0.8, env0);
51                 
52                 noise = WhiteNoise.ar(0.2);
53                 noise = HPF.ar(noise, 200, 2);
54                 noise = BPF.ar(noise, 6900, 0.6, 3) + noise;
55                 noise = noise * env2;
56                 
57                 out = oscs + noise;
58                 out = out.clip2(1) * amp;
59                         
60                 Out.ar(outBus, out.dup);
61         }).send(s);
62         
63         SynthDef("clap", {      
64                 arg outBus=0, amp = 0.5;
65                 var env1, env2, out, noise1, noise2;
66                 
67                 env1 = EnvGen.ar(Env.new([0, 1, 0, 1, 0, 1, 0, 1, 0], [0.001, 0.013, 0, 0.01, 0, 0.01, 0, 0.03], [0, -3, 0, -3, 0, -3, 0, -4]));
68                 env2 = EnvGen.ar(Env.new([0, 1, 0], [0.02, 0.3], [0, -4]), doneAction:2);
69                 
70                 noise1 = WhiteNoise.ar(env1);
71                 noise1 = HPF.ar(noise1, 600);
72                 noise1 = BPF.ar(noise1, 2000, 3);
73                 
74                 noise2 = WhiteNoise.ar(env2);
75                 noise2 = HPF.ar(noise2, 1000);
76                 noise2 = BPF.ar(noise2, 1200, 0.7, 0.7);
77                 
78                 out = noise1 + noise2;
79                 out = out * 2;
80                 out = out.softclip * amp;
81                 
82                 Out.ar(outBus, out.dup);
83         }).send(s);
84         
85         SynthDef("hat", {       
86                 arg outBus=0, amp=0.3;
87                 var env1, env2, out, oscs1, noise, n, n2;
88                 
89                 n = 5;
90                 thisThread.randSeed = 4;
91                 
92                 env1 = EnvGen.ar(Env.new([0, 1.0, 0], [0.001, 0.2], [0, -12]));
93                 env2 = EnvGen.ar(Env.new([0, 1.0, 0.05, 0], [0.002, 0.05, 0.03], [0, -4, -4]), doneAction:2);
94                 
95                 oscs1 = Mix.fill(n, {|i|
96                         SinOsc.ar(
97                                 ( i.linlin(0, n-1, 42, 74) + rand2(4.0) ).midicps,
98                                 SinOsc.ar( (i.linlin(0, n-1, 78, 80) + rand2(4.0) ).midicps, 0.0, 12),
99                                 1/n
100                         )
101                 });
102                 
103                 oscs1 = BHiPass.ar(oscs1, 1000, 2, env1);
104                 n2 = 8;
105                 noise = WhiteNoise.ar;
106                 noise = Mix.fill(n2, {|i|
107                         var freq;
108                         freq = (i.linlin(0, n-1, 40, 50) + rand2(4.0) ).midicps.reciprocal;
109                         CombN.ar(noise, 0.04, freq, 0.1)
110                 }) * (1/n) + noise;
111                 noise = BPF.ar(noise, 6000, 0.9, 0.5, noise);
112                 noise = BLowShelf.ar(noise, 3000, 0.5, -6);
113                 noise = BHiPass.ar(noise, 1000, 1.5, env2);
114                 
115                 out = noise + oscs1;
116                 out = out.softclip;
117                 out = out * amp;
118                 
119                 Out.ar(outBus, out.dup);
120         }).send(s);
121         
122         SynthDef("acid", {      
123                 arg outBus=0, gate=1, pitch=50, amp=0.1;
124                 var env1, env2, out;
125                 pitch = Lag.kr(pitch, 0.12 * (1-Trig.kr(gate, 0.001)) * gate);
126                 env1 = EnvGen.ar(Env.new([0, 1.0, 0, 0], [0.001, 2.0, 0.04], [0, -4, -4], 2), gate, amp);
127                 env2 = EnvGen.ar(Env.adsr(0.001, 0.8, 0, 0.8, 70, -4), gate);
128                 out = LFPulse.ar(pitch.midicps, 0.0, 0.51, 2, -1);
129         
130                 out = RLPF.ar(out, (pitch + env2).midicps, 0.3);
131                 out = out * env1;
132                 
133                 Out.ar(outBus, out.dup);
134         }).send(s);
135         
136         SynthDef("fx", {        
137                 arg outBus=0, gate=0;
138                 var out;
139                 
140                 out = In.ar(outBus, 2);
141                 out = FreeVerb2.ar( BPF.ar(out[0], 3500, 1.5), BPF.ar(out[1], 3500, 1.5), 1.0, 0.95, 0.15) * EnvGen.kr(Env.new([0.02, 0.3, 0.02], [0.4, 0.01], [3, -4], 1), 1-Trig.kr(gate, 0.01)) + out;
142                 out = HPF.ar(out * 1.2, 40);
143                 out = Limiter.ar(out, 1.0, 0.02);
144                 
145                 ReplaceOut.ar(outBus, out);
146         }).send(s);
149 s.sync(c);
151 ( // **** Sequence ****
152         
153         ~dseq = [
154                 [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0],
155                 [0,0,0,0, 4,0,0,2, 0,0,0,0, 4,0,0,0],
156                 [0,0,0,0, 0,0,0,0, 0,0,0,0, 4,0,0,0],
157                 [1,2,4,0, 1,0,4,0, 1,2,4,2, 1,0,4,2],
158                 [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0]
159                 ].flop;
160         
161         ~bseq = [
162                 [1,1,1,1, 1,1,1,1, 0,1,0,1, 1,1,1,0],
163                 [1,1,0,2, 1,1,0,0, 2,0,2,0, 1,2,0,4],
164                 [-24,-12,0,-12, 0,-12,10,12, 0,7,-7,0, -11,1,13,15] + 38
165                 ].flop;
166         
167         ~pnt = 0;
168         ~shf = 0.16;
169         ~bpm = 130;
170         
171         ~clock = TempoClock(~bpm/60);
172         
173         ~clock.sched(0.0, {
174                 var delta, bass;
175                 delta = if(~pnt%2 == 0){1/4 * (1+~shf)}{1/4 * (1-~shf)};
176                 
177                 s.bind{ 
178                         if(~pnt == 0){
179                                 ~group = Group.new;
180                                 ~acid = Synth.head(~group, "acid", [\gate, 0]);
181                                 ~fx = Synth.after(~group, "fx");
182                         };
183                         
184                         ~dseq.wrapAt(~pnt).do{|x, i|
185                                 switch(i,
186                                         0, { if( x>0 ){ Synth.head(~group, "kick") } },
187                                         1, { if( x>0 ){ Synth.head(~group, "snare", [\amp, (x/4).squared*0.7]) } },
188                                         2, { if( x>0 ){ Synth.head(~group, "clap", [\amp, (x/4).squared*0.5]) } },
189                                         3, { if( x>0 ){ Synth.head(~group, "hat", [\amp, (x/4).squared*0.32]) } },
190                                         4, { ~fx.set(\gate, (x>0).binaryValue) }
191                                 );
192                         };      
193                         
194                         bass = ~bseq.wrapAt(~pnt);
195                         ~acid.set(\pitch, bass[2]);
196                         if(bass[0]==1){ ~acid.set(\gate, 1) };
197                 };
198                 if(bass[1]>0){ ~clock.sched(delta * bass[1]/4 * 0.99, { s.bind{ ~acid.set(\gate, 0) } }) };
199                 
200                 ~pnt = ~pnt+1;
201                 delta;
202         });