supernova: fix for small audio vector sizes
[supercollider.git] / examples / pieces / spacelab.scd
blob8a0453dc126b00e52c50f48355a4d68d5089c384
1 /*******************************************************************************
2 "Spacelab" -- Kraftwerk
3 old school exercise -- jy
4 *******************************************************************************/
6 s = Server.default;
7 s.boot;
10 // SynthDefs //
12         SynthDef(\bd, { | out=0 |
13                 var osc, env;
14                 osc = FSinOsc.ar(40);
15                 env = EnvGen.kr(Env.perc(0, 0.05), doneAction: 2);
16                 Out.ar(out, Pan2.ar(osc, 0, env));
17         }).add;
19         SynthDef(\sd, { | out=0 |
20                 var osc1, osc2, env;
21                 osc1 = WhiteNoise.ar;
22                 osc2 = FSinOsc.ar(200);
23                 env = EnvGen.kr(Env.perc(0, 0.05), doneAction: 2);
24                 Out.ar(out, Pan2.ar(LPF.ar(Mix([osc1, osc2]), 12000), 0, env));
25         }).add;
27         SynthDef(\hat, { | out=0 |
28                 var osc1, env;
29                 osc1 = WhiteNoise.ar;
30                 env = EnvGen.kr(Env.perc(0, 0.01), doneAction: 2);
31                 Out.ar(out, Pan2.ar(osc1, 0, env));
32         }).add;
34         SynthDef(\res, { | out=0 gate=1 freq fltBus |
35                 var aEnv, osc, flt;
36                 aEnv = EnvGen.kr(Env.perc(0, 0.7), gate, doneAction: 2);
37                 osc = Mix([Saw.ar(freq), Pulse.ar(freq / 2, 0.5)]);
38                 flt = RLPF.ar(osc, In.kr(fltBus, 1), 0.1, aEnv);
39                 Out.ar(out, Pan2.ar(flt, 0));
40         }).add;
42         SynthDef(\resControl, { | fltBus |
43                 ReplaceOut.kr(fltBus, LFNoise1.kr(0.3, 1000, 1500));
44         }).add;
46         SynthDef(\poly, { | out=0 gate=1 freq |
47                 var aEnv, fEnv, osc1, osc2, flt;
48                 aEnv = EnvGen.kr(Env.asr(0.2, 1, 0.1), gate, doneAction: 2);
49                 fEnv = EnvGen.kr(Env.asr(7, 1, 0.2), levelScale: 12000);
50                 osc1 = Pulse.ar(freq * [1, 1.007], LFCub.kr(2, 0, 0.3, 0.5));
51                 osc2 = Pulse.ar(freq / 2, 0.3);
52                 flt = RLPF.ar(osc1 + osc2, fEnv, 0.9, aEnv);
53                 Out.ar(out, flt);
54         }).add;
56         SynthDef(\solo, { | out=0 gate freq |
57                 var aEnv, fEnv, osc, flt;
58                 aEnv = EnvGen.kr(Env.asr(0.2, 1, 2), gate);
59                 fEnv = EnvGen.kr(Env.adsr(0.4, 1.2, 0.7, 2), gate, 800);
60                 osc = Saw.ar(Lag.kr(freq, 0.1) * [1, 1.005]);
61                 flt = LPF.ar(osc, fEnv + 600, aEnv);
62                 Out.ar(out, flt);
63         }).add;
65         SynthDef(\soloControl, { | gateBus freqBus gate=1 freq |
66                 ReplaceOut.kr(gateBus, gate);
67                 ReplaceOut.kr(freqBus, freq);
68                 EnvGen.kr(Env.asr(0,1,0), gate, doneAction: 2); 
69         }).add;
71         SynthDef(\string, { | out=0 gate=1 freq=1000 |
72                 var aEnv, osc, flt;
73                 aEnv = EnvGen.kr(Env.asr(0.2, 1, 0.5), gate, doneAction: 2);
74                 osc = Saw.ar([LFCub.kr(0.3, Rand(0, 1), freq * 0.003, freq), freq, LFCub.kr(0.7, Rand(0, 1), freq * 0.001, freq)]);
75                 flt = LPF.ar(osc, 1500, aEnv);
76                 Out.ar(out, flt);
77         }).add;
79         SynthDef(\bass, { | out=0 gate=1 freq |
80                 var aEnv, fEnv, osc, flt;
81                 aEnv = EnvGen.kr(Env.asr(0, 1, 1), gate, doneAction: 2);
82                 fEnv = EnvGen.kr(Env.perc(0, 3), levelScale: 6000);
83                 osc = Mix([Saw.ar(freq * [1, 1.005]), Pulse.ar(freq / 2, 0.5)]);
84                 flt = LPF.ar(osc, fEnv + 100, aEnv);
85                 Out.ar(out, flt);
86         }).add;
88         SynthDef(\intro, { | out=0 |
89                 var trig, div, freq, oct, reps, env, osc, flt;
90                 oct = [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3];
91                 trig = Impulse.kr(EnvGen.kr(Env([1.75, 120], [30], 6.5)));
92                 div = PulseDivider.kr(trig, 16, 16);
93                 reps = PulseCount.kr(div);
94                 env = EnvGen.kr(Env.perc(0, 3), trig, 0.5);
95                 freq = (Stepper.kr(trig, div, 42, 74, 2, 42) + (12 * Select.kr(reps, oct))).midicps;
96                 osc = Saw.ar(freq * [1, 1.01], env);
97                 flt = RLPF.ar(osc, freq * 2, 0.7);
98                 Out.ar(out, flt);
99         }).add;
101         SynthDef(\delay, { | bus in mix |
102                 var sig, delay;
103                 sig = In.ar(bus, 2);
104                 delay = CombL.ar(sig, 0.25, [0.25, 0.24], 2);
105                 ReplaceOut.ar(bus, XFade2.ar(sig, delay, mix));
106         }).add;
108         SynthDef(\fader, { | out=0 in mute=1 amp=1 |
109                 Out.ar(out, In.ar(in, 2) * mute * amp)
110         }).add;
112         SynthDef(\line, { | bus val time |
113                 ReplaceOut.kr(bus, Line.kr(In.kr(bus), val, time, doneAction: 2))
114         }).add;
116         SynthDef(\sinenv, { | bus val time |
117                 ReplaceOut.kr(bus, EnvGen.kr(Env([In.kr(bus), val], [time], \sin), doneAction: 2))
118         }).add;
122 // Busses //
124         ~numChannels = 9;
126         ~master = Bus.audio(s, 2);
127         ~masterAmp = Bus.control(s, 1);
129         ~numChannels.do { | i |
130                 ("ch" ++ i).asSymbol.envirPut(Bus.audio(s, 2));
131                 ("chAmp" ++ i).asSymbol.envirPut(Bus.control(s, 1));
132         };
134         ~resFlt = Bus.control(s, 1);
135         ~soloGate = Bus.control(s, 1);
136         ~soloFreq = Bus.control(s, 1);
140 // Nodes //
142         ~mixGroup = Group.new;
143         ~fxGroup = Group.new;
144         ~synthGroup = Group.new;
146         ~masterFader = Synth(\fader, [\out, 0, \in, ~master], ~mixGroup);
147         ~numChannels.do { | i |
148                 ("fader" ++ i).asSymbol.envirPut(Synth(\fader, [\out, ~master, \in, ("ch" ++ i).asSymbol.envirGet], ~mixGroup));
149         };
151         ~ch3ins01 = Synth(\delay, [\bus, ~ch3, \mix, -0.8], ~fxGroup);
152         ~ch4ins01 = Synth(\delay, [\bus, ~ch4, \mix, -0.9], ~fxGroup);
153         ~ch5ins01 = Synth(\delay, [\bus, ~ch5, \mix, -0.6], ~fxGroup);
154         ~ch6ins01 = Synth(\delay, [\bus, ~ch6, \mix,  0.0], ~fxGroup);
155         ~ch7ins01 = Synth(\delay, [\bus, ~ch7, \mix, -0.8], ~fxGroup);
156         ~ch8ins01 = Synth(\delay, [\bus, ~ch8, \mix, -0.5], ~fxGroup);
158         ~masterFader.map(\amp, ~masterAmp);
159         ~numChannels.do { | i | ("fader" ++ i).asSymbol.envirGet.map(\amp, ("chAmp" ++ i).asSymbol.envirGet) };
161         ~masterAmp.value = 1;
162         ~chAmp0.value = 0.7;
163         ~chAmp1.value = 0.3;
164         ~chAmp2.value = 0.15;
165         ~chAmp3.value = 0.04;
166         ~chAmp4.value = 0.02;
167         ~chAmp5.value = 0.1;
168         ~chAmp6.value = 0.07;
169         ~chAmp7.value = 0.03;
170         ~chAmp8.value = 0.075;
172         ~soloGate.value = 0;
173         ~soloFreq.value = 1000;
174         ~soloSynth = Synth(\solo, [\out, ~ch5], ~synthGroup);
175         ~soloSynth.map(\gate, ~soloGate, \freq, ~soloFreq);
176         ~resControlSynth = Synth(\resControl, [\fltBus, ~resFlt], ~synthGroup);
180 // Patterns //
182         ~bd_intro = Pbind(
183                 \instrument, \bd,
184                 \out, ~ch0,
185                 \dur, Pseq([1], 16),
186                 \group, ~synthGroup.nodeID
187         );
189         ~bd = Pbind(
190                 \instrument, \bd,
191                 \out, ~ch0,
192                 \dur, Pseq([1], 32),
193                 \group, ~synthGroup.nodeID
194         );
196         ~sd_intro = Pbind(
197                 \instrument, \sd,
198                 \out, ~ch1,
199                 [\freq, \dur], Pseq([
200                         Pseq([[\, 1], [1, 1]], 6),
201                         Pseq([[\, 1], [1, 1], [\, 1], [1, 0.5], [1, 0.25], [1, 0.25]])
202                 ]),
203                 \group, ~synthGroup.nodeID
204         );
206         ~sd = Pbind(
207                 \instrument, \sd,
208                 \out, ~ch1,
209                 [\freq, \dur], Pseq([
210                         Pseq([[\, 1], [0, 1]], 15),
211                         Prand([
212                                 Pseq([[\, 1], [0, 0.5], [0, 0.25], [0, 0.25]]),
213                                 Pseq([[\, 0.5], [0, 0.25], [0, 0.25], [0, 0.5], [0, 0.25], [0, 0.25]]),
214                                 Pseq([[\, 0.5], [0, 0.5], [0, 0.5], [0, 0.5]]),
215                                 Pseq([[0, 0.25], [0, 0.25], [0, 0.5], [0, 0.25], [0, 0.25], [0, 0.5]])
216                         ])
217                 ]),
218                 \group, ~synthGroup.nodeID
219         );
221         ~hat_intro = Pbind(
222                 \instrument, \hat,
223                 \out, ~ch2,
224                 \dur, Pseq([0.25], 64),
225                 \group, ~synthGroup.nodeID
226         );
228         ~hat = Pbind(
229                 \instrument, \hat,
230                 \out, ~ch2,
231                 \dur, Pseq([0.25], 128),
232                 \group, ~synthGroup.nodeID
233         );
235         ~res_intro = Pbind(
236                 \instrument, \res,
237                 \out, ~ch3,
238                 \fltBus, ~resFlt,
239                 \scale, [0, 2, 3, 5, 7, 8, 10],
240                 \degree, Pseq([Pseq([2], 16), Pseq([0], 16)], 2),
241                 \octave, Pseq([4, 5], inf),
242                 \dur, 0.25,
243                 \group, ~synthGroup.nodeID
244         );
246         ~res_chorus = Pbind(
247                 \instrument, \res,
248                 \out, ~ch3,
249                 \fltBus, ~resFlt,
250                 \scale, [0, 2, 3, 5, 7, 8, 10],
251                 \degree, Pseq([Pseq([2], 16), Pseq([0], 16)], 4),
252                 \octave, Pseq([4, 5], inf),
253                 \dur, 0.25,
254                 \group, ~synthGroup.nodeID
255         );
257         ~res_verse = Pbind(
258                 \instrument, \res,
259                 \out, ~ch3,
260                 \fltBus, ~resFlt,
261                 \scale, [0, 2, 3, 5, 7, 8, 10],
262                 \degree, Pseq([Pseq([0], 32), Pseq([3], 14), Pseq([6], 2), Pseq([0], 16)], 2),
263                 \octave, Pseq([4, 5], inf),
264                 \dur, 0.25,
265                 \group, ~synthGroup.nodeID
266         );
268         ~res_break = Pbind(
269                 \instrument, \res,
270                 \out, ~ch3,
271                 \fltBus, ~resFlt,
272                 \scale, [0, 2, 3, 5, 7, 8, 10],
273                 \degree, Pseq([Pseq([2], 32), Pseq([0], 32)]),
274                 \octave, Pseq([4, 5], inf),
275                 \dur, 0.25,
276                 \group, ~synthGroup.nodeID
277         );
279         ~poly_intro = Pbind(
280                 \instrument, \poly,
281                 \out, ~ch4,
282                 \scale, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
283                 \degree, Pseq([[3, 8, 12, 15], [0, 5, 9, 12], [8, 12, 15], [5, 9, 12]]),
284                 \octave, 5,
285                 \dur, 4,
286                 \legato, 0.5,
287                 \group, ~synthGroup.nodeID
288         );
290         ~poly_chorus = Pbind(
291                 \instrument, \poly,
292                 \out, ~ch4,
293                 \scale, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
294                 \degree, Pseq([[8, 12, 15], [5, 9, 12]], 4),
295                 \octave, 5,
296                 \dur, 4,
297                 \legato, 0.5,
298                 \group, ~synthGroup.nodeID
299         );
301         ~solo_intro = Pbind(
302                 \instrument, \soloControl,
303                 \gateBus, ~soloGate,
304                 \freqBus, ~soloFreq,
305                 \scale, [0, 2, 3, 5, 7, 8, 10],
306                 \degree, Pseq([\, 2, 3, 0]),
307                 \octave, 6,
308                 \dur, Pseq([8, 3.5, 0.5, 4]),
309                 \legato, 1,
310                 \group, ~synthGroup.nodeID
311         );
313         ~solo_chorus = Pbind(
314                 \instrument, \soloControl,
315                 \gateBus, ~soloGate,
316                 \freqBus, ~soloFreq,
317                 \scale, [0, 2, 3, 5, 7, 8, 10],
318                 \degree, Pseq([\, 2, 3, 0, \, 2, 3, 7]),
319                 \octave, 6,
320                 \dur, Pseq([8, 3.5, 0.5, 4], inf),
321                 \legato, 1,
322                 \group, ~synthGroup.nodeID
323         );
325         ~solo_verse = Pbind(
326                 \instrument, \soloControl,
327                 \gateBus, ~soloGate,
328                 \freqBus, ~soloFreq,
329                 \scale, [0, 2, 3, 5, 7, 8, 10],
330                 \degree, Pseq([
331                         5, 6, 7, 6, 5, 4, 5, 6, 3, 4, 5, 4, 3, 2, 3, 4,
332                         5, 6, 7, 6, 5, 4, 5, 6, 3, 4, 5, 4, 3, 2, -1, 0
333                 ]),
334                 \octave, 6,
335                 \dur, Pseq([1, 0.5, 1.5, 0.5, 0.5, 1, 0.5, 2.5], inf),
336                 \legato, 1,
337                 \group, ~synthGroup.nodeID
338         );
340         ~solo_break1 = Pbind(
341                 \instrument, \soloControl,
342                 \gateBus, ~soloGate,
343                 \freqBus, ~soloFreq,
344                 \scale, [0, 2, 3, 5, 7, 8, 10],
345                 \degree, Pseq([2, 3, 0]),
346                 \octave, 6,
347                 \dur, Pseq([7, 1, 8], inf),
348                 \legato, 1,
349                 \group, ~synthGroup.nodeID
350         );
352         ~solo_break2 = Pbind(
353                 \instrument, \soloControl,
354                 \gateBus, ~soloGate,
355                 \freqBus, ~soloFreq,
356                 \scale, [0, 2, 3, 5, 7, 8, 10],
357                 \degree, Pseq([2, 3, 7]),
358                 \octave, 6,
359                 \dur, Pseq([7, 1, 8], inf),
360                 \legato, 1,
361                 \group, ~synthGroup.nodeID
362         );
364         ~solo_vamp1 = Pbind(
365                 \instrument, \soloControl,
366                 \gateBus, ~soloGate,
367                 \freqBus, ~soloFreq,
368                 \scale, [0, 2, 3, 5, 7, 8, 10],
369                 \degree, Pseq([
370                         5, 6, 7, 8, 9, 4, 5, 6, 3, 4, 5, 4, 3, 2, 3, 4
371                 ], 2),
372                 \octave, 5,
373                 \dur, Pseq([1, 0.5, 1.5, 0.5, 0.5, 1, 0.5, 2.5], inf),
374                 \legato, 1,
375                 \group, ~synthGroup.nodeID
376         );
378         ~solo_vamp2 = Pbind(
379                 \instrument, \soloControl,
380                 \gateBus, ~soloGate,
381                 \freqBus, ~soloFreq,
382                 \scale, [0, 2, 3, 5, 7, 8, 10],
383                 \degree, Pseq([
384                         5, 6, 7, 8, 9, 4, 5, 6, 3, 4, 5, 4, 3, 2, 3, 4
385                 ], 2),
386                 \octave, 6,
387                 \dur, Pseq([1, 0.5, 1.5, 0.5, 0.5, 1, 0.5, 2.5], inf),
388                 \legato, 1,
389                 \group, ~synthGroup.nodeID
390         );
392         ~string_intro = Pbind(
393                 \instrument, \string, 
394                 \out, ~ch6,
395                 \scale, [0, 2, 3, 5, 7, 8, 10],
396                 \degree, Pseq([7]),
397                 \octave, 7,
398                 \dur, 16,
399                 \legato, 1,
400                 \group, ~synthGroup.nodeID
401         );
403         ~string_chorus = Pbind(
404                 \instrument, \string, 
405                 \out, ~ch6,
406                 \scale, [0, 2, 3, 5, 7, 8, 10],
407                 \degree, Pseq([7]),
408                 \octave, 7,
409                 \dur, 32,
410                 \legato, 1,
411                 \group, ~synthGroup.nodeID
412         );
414         ~string_verse = Pbind(
415                 \instrument, \string, 
416                 \out, ~ch6,
417                 \scale, [0, 2, 3, 5, 7, 8, 10],
418                 \degree, Pseq([7, 6, 5, 4], 2),
419                 \octave, Prand([Pseq([7], 4), Pseq([6], 4)], inf),
420                 \dur, 4,
421                 \legato, 1,
422                 \group, ~synthGroup.nodeID
423         );
425         ~string_break = Pbind(
426                 \instrument, \string, 
427                 \out, ~ch6,
428                 \scale, [0, 2, 3, 5, 7, 8, 10],
429                 \degree, Pseq([7], 16),
430                 \octave, Pseq([6, 7], inf),
431                 \dur, 1,
432                 \legato, 1,
433                 \group, ~synthGroup.nodeID
434         );
436         ~string_vamp1 = Pbind(
437                 \instrument, \string,
438                 \out, ~ch6,
439                 \scale, [0, 2, 3, 5, 7, 8, 10],
440                 \degree, Pseq([Prand([0, 7]), 2, 3, 0, 2, 3, 7], 2),
441                 \octave, 5,
442                 \dur, Pseq([4, 1, 0.5, 6.5, 1, 0.5, 2.5], inf),
443                 \legato, 1,
444                 \group, ~synthGroup.nodeID
445         );
447         ~string_vamp2 = Pbind(
448                 \instrument, \string,
449                 \out, ~ch6,
450                 \scale, [0, 2, 3, 5, 7, 8, 10],
451                 \degree, Pseq([Prand([0, 7]), 2, 3, 0, 2, 3, 7], 2),
452                 \octave, 6,
453                 \dur, Pseq([4, 1, 0.5, 6.5, 1, 0.5, 2.5], inf),
454                 \legato, 1,
455                 \group, ~synthGroup.nodeID
456         );
458         ~bass_verse = Pbind(
459                 \instrument, \bass,
460                 \out, ~ch7,
461                 \scale, [0, 2, 3, 5, 7, 8, 10],
462                 \degree, Pseq([0, 0, 3, 6, 7], 2),
463                 \octave, 3,
464                 \dur, Pseq([7.5, 0.5, 3.5, 0.5, 4], inf),
465                 \group, ~synthGroup.nodeID
466         );
468         ~bass_break = Pbind(
469                 \instrument, \bass,
470                 \out, ~ch7,
471                 \scale, [0, 2, 3, 5, 7, 8, 10],
472                 \degree, Pseq([2, 0]),
473                 \octave, 3,
474                 \dur, 8,
475                 \group, ~synthGroup.nodeID
476         );
478         // Song sections //
479         ~intro1 = Ppar([~poly_intro, ~solo_intro]);
480         ~intro2 = Ppar([~hat_intro, ~res_intro]);
481         ~intro3 = Ppar([~bd_intro, ~sd_intro, ~hat_intro, ~res_intro, ~string_intro ]);
482         ~chorus = Ppar([~bd, ~sd, ~hat, ~res_chorus,  ~poly_chorus, ~solo_chorus, ~string_chorus]);
483         ~verse = Ppar([~bd, ~sd, ~hat, ~res_verse, ~solo_verse, ~string_verse, ~bass_verse]);
484         ~break1 = Ppar([~string_break, ~bass_break]);
485         ~break2 = Ppar([~solo_break1, ~string_break, ~bass_break]);
486         ~break3 = Ppar([~hat_intro, ~res_break, ~string_break]);
487         ~break4 = Ppar([~bd_intro, ~sd_intro, ~hat_intro, ~res_break, ~solo_break2, ~string_break]);
488         ~vamp1 = Ppar([~bd, ~sd, ~hat, ~res_verse, ~solo_vamp1, ~string_vamp1]);
489         ~vamp2 = Ppar([~bd, ~sd, ~hat, ~res_verse, ~solo_vamp2, ~string_vamp2, ~bass_verse]);
491         // Mixer patterns //
492         ~fader8auto = Pbind(
493                 \instrument, \sinenv,
494                 \bus, ~chAmp8,
495                 [\freq, \dur, \val, \time], Pseq([[\, 12, 0, 0], [0, 530, 0, 16], [0, 1, 0.05, 8]]),
496                 \group, ~mixGroup.nodeID
497         );
499         ~masterFaderAuto = Pbind(
500                 \instrument, \sinenv,
501                 \bus, ~masterAmp,
502                 [\freq, \dur, \val, \time], Pseq([[\, 560, 0, 0], [0, 1, 0, 16]]),
503                 \group, ~mixGroup.nodeID
504         );
508 // Play it! //
510         ~tc = TempoClock.default;
511         ~introSynth = Synth(\intro, [\out, ~ch8], ~synthGroup);
512         SystemClock.sched(30, {
513                 ~tc.tempo = 98 / 60;
514                 //~beat = 0; ~tc.schedAbs(~tc.beats.ceil, { ~beat = ~beat + 1; ~beat.postln; 1 });
515                 ~tc.sched(16, { ~tc.tempo = 118 / 60 });
516                 Ppar([
517                         Pseq([
518                                 ~intro1,
519                                 ~intro2,
520                                 ~intro3,
521                                 ~chorus,
522                                 ~chorus,
523                                 ~verse,
524                                 ~chorus,
525                                 ~verse,
526                                 ~break1,
527                                 ~break2,
528                                 ~break3,
529                                 ~break4,
530                                 ~verse,
531                                 ~chorus,
532                                 ~verse,
533                                 ~chorus,
534                                 ~vamp1,
535                                 ~vamp1,
536                                 ~vamp2,
537                                 ~vamp2,
538                                 ~vamp2,
539                                 ~vamp2
540                         ]),
541                         Ppar([~fader8auto, ~masterFaderAuto])
542                 ]).play;
543         });
546 ~masterFader.set(\mute, 0);
547 ~masterFader.set(\mute, 1);
550 // Clean up //
551 s.freeAll;