-
Notifications
You must be signed in to change notification settings - Fork 9
/
Patterns_Tutorial.scd
executable file
·561 lines (424 loc) · 11.5 KB
/
Patterns_Tutorial.scd
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
//////////////
// PATTERNS //
//////////////
// QUICK INTRO TO PATTERNS
// The goal is to start making sound right away as you learn to use Patterns.
// Don't worry about every single detail of what is happening under the hood.
// Later on, you can learn a lot more about Patterns by reading the
// excellent "Pattern Guide" (by James Harkins) in the Documentation.
// A Pattern is like a blueprint for a building, or a recipe.
// The Pattern below specifies the following recipe: "take the list provided and read through it twice".
Pseq([1, 2, 3, 4, 5], 2);
// If you evaluate the line above, you see no actual result: it's just a recipe.
// In order to quickly see the results of the recipe, we do this:
Pseq([1, 2, 3, 4, 5], 2).asStream.all;
// This is just to understand what the Pattern will do when 'streamed' in time.
// Supose we want to play a simple scale: C minor, ascending, each note lasting 0.3 seconds:
(
Pbind(
\midinote, Pseq([60, 62, 63, 65, 67, 68, 71, 72], 2),
\dur, 0.3,
).play;
)
// Pbind is the structure that 'binds it all together'. It's a collection of key/value pairs.
// Inside, you can specify sequences of values for pitches, durations, amplitude, etc.
// Normally you will use Patterns to define these sequences of values.
// IMPORTANT: Pbind will use default values for parameteres you do not explicitly specify.
// If you omit "dur", for example, it will use a default 1-second duration for each note:
(
Pbind(
\midinote, Pseq([60, 62, 63, 65, 67, 68, 71, 72]),
).play;
)
// Here's another example using Pseq for notes, durations, and amplitudes:
(
Pbind(
\midinote, Pseq([60, 67, 78, 71, 40], 2),
\dur, Pseq([0.1, 0.1, 0.5, 0.4, 1], inf),
\amp, Pseq([0.1, 0.2, 0.3, 0.2, 0.2], inf);
).play;
)
// The examples below will use that C minor scale a lot, so let's store it into a variable:
h = [60, 62, 63, 65, 67, 68, 71, 72];
h
// We'll now go through a bunch of different Patterns.
// Like when we learn to speak a new language, this is the moment
// of learning new words to expand our vocabulary.
// If you can't figure out what the Pattern is doing,
// put your cursor on the Pattern name and type ctrl + D (help file)
// Pseq
(
Pbind(
\midinote, Pseq(list: h, repeats: 4),
\dur, 0.15;
).play;
)
// Pser
(
Pbind(
\midinote, Pser(list: h, repeats: 15),
\dur, 0.15;
).play;
)
// Pslide
(
Pbind(
\midinote, Pslide(list: h, repeats: 7, len: 3, step: -1),
\dur, 0.15;
).play;
)
// Prand
(
p = Pbind(
\midinote, Prand(h, inf),
\dur, 0.2;
).play;
)
// Pxrand
(
p = Pbind(
\midinote, Pxrand(h, inf),
\dur, 0.2;
).play;
)
// Pwhite
(
p = Pbind(
\midinote, Pseq(h, 3),
\dur, Pwhite(0.1, 0.3);
).play;
)
// Pshuf
(
p = Pbind(
\midinote, Pshuf(h, 6),
\dur, Prand([0.1, 0.2], inf);
).play;
)
// Define some chords
c = [[60, 63, 67], [62, 65, 68], [63, 67, 70], [65, 68, 72]];
// Chords with Pseq
(
Pbind(
\midinote, Pseq(list: c, repeats: 3),
\dur, 0.15;
).play;
)
// Place
(
Pbind(
\midinote, Place(list: c, repeats: 3),
\dur, 0.15;
).play;
)
// Check it out what Place does:
Place(c, 3).asStream.all;
// Now let's create new series of numbers from scratch
// (no use of pre-defined sets of numbers like h and c above)
// Pseries
(
p = Pbind(
\midinote, Pseries(start: 90, step: -2, length: 21),
\dur, 0.1;
).trace.play;
)
// Pgeom
(
p = Pbind(
\midinote, Pseries(start: 90, step: -2, length: 21),
\dur, Pgeom(start: 0.1, grow: 1.1);
).trace.play;
)
// Ppatlace
(
p = Pbind(
\midinote, Ppatlace([
Pseries(60, 2, 8), // first, third etc. notes
Pseries(72, 2, 8) // second, fourth etc. notes
], inf),
\dur, 0.25
).play;
)
// Check it out what it does:
Ppatlace([Pseries(60, 2, 8), Pseries(72, 2, 8)], inf).asStream.all
// You can use freq instead of midinote
(
Pbind(
\freq, Pseries(220, 220, 8), // first 8 partials of 220Hz
\dur, 0.25;
).play;
)
// Another option: degree (as in scale degree)
(
Pbind(
\note, Pseq([0, 1, 2, 3, 4, 5, 6, 7], 1),
\dur, 0.25;
).play;
)
// Major scale is default for degrees. How to change scales:
(
Pbind(
\scale, Scale.zamzam, // try minor, chromatic, dorian, etc
\degree, Pseq([0, 1, 2, 3, 4, 5, 6, 7], 1),
\dur, 0.25;
).play;
)
// Ptuple
(
Pbind(
\scale, Scale.phrygian,
\degree, Ptuple([
Prand([5, 6, 5, 6, 8, 7, 6, 7], inf),
Prand([3, 4, 3, 5, 5, 5, 5, 4], inf),
Pseq([0, 0, 0, 2, 3, 4, 3, 1], inf)], inf),
\dur, Pseq([0.15, 0.15, 0.25, 0.25, 0.15, 0.15, 0.25], inf),
\legato, 0.1;
).play;
)
/* See more at
"http://doc.sccode.org/Tutorials/A-Practical-Guide/PG_02_Basic_Vocabulary.html"
*/
// "Flock of seagulls" example by James Harkins
(
Pbind(
\degree, Pslide((-6, -4 .. 12), 8, 3, 1, 0),
\dur, Pseq([0.1, 0.1, 0.2], inf),
\legato, 0.7
).play;
)
// So far we have been using the "default" instrument. Let's load a few more interesting ones.
// "PMCrotale"
// "blips"
// "noisy"
// "hihat"
// "snare"
// "kick"
// "kick2"
/*
From this point on we need the file SynthDefs_2013.scd to be evaluated, so that these new synths are loaded into memory. If you have copied the entire folder of tutorials from https://github.com/brunoruviaro/SuperCollider_Tutorials, you should already have this file. In this case you can simply run the following line to evaluate it:
*/
"SynthDefs_2013.scd".loadRelative;
// Now try a Pbind with a different instrument:
(
Pbind(
\instrument, "PMCrotale",
\midinote, Pseq([60, 67, 78, 71, 40], 4),
\dur, Pseq([0.1, 0.1, 0.5, 0.4, 1], inf),
\art, 1,
\amp, 0.2,
\awesome, 10
).play;
)
// How about the Ptuple example again with crotales?
(
Pbind(
\instrument, "PMCrotale",
\scale, Scale.phrygian,
\degree, Ptuple([
Pseq([5, 6, 5, 6, 8, 7, 6, 7], inf),
Pseq([3, 4, 3, 5, 5, 5, 5, 4], inf),
Pseq([0, 0, 0, 2, 3, 4, 3, 1], inf)], inf),
\dur, Pseq([0.15, 0.15, 0.25, 0.25, 0.15, 0.15, 0.25], inf),
\art, 0.5,
\amp, 0.3;
).play;
)
// "PMCrotale" instrument has a specific "art" (Attack and Release Time) parameter. Try changing it.
// Each instrument will have its own specific parameters. Some (like dur) are very common.
// We will see later how to create your own instruments.
// For now, just use the ones provided to practice writing Pbinds and Patterns.
// Write a Pattern for the \art parameter. Suggestion: try Prand or Pwhite.
(
Pbind(
\instrument, "PMCrotale",
\scale, Scale.phrygian,
\degree, Ptuple([
Pseq([5, 6, 5, 6, 8, 7, 6, 7], inf),
Pseq([3, 4, 3, 5, 5, 5, 5, 4], inf),
Pseq([0, 0, 0, 2, 3, 4, 3, 1], inf)], inf),
\dur, Pseq([0.15, 0.15, 0.25, 0.25, 0.15, 0.15, 0.25], inf),
\art, // WRITE A PATTERN HERE (don't forget the comma at the end)
\amp, 0.3;
).play;
)
// Keep going: for every example below, change existing Patterns, create new ones, etc.
// "blips" instrument example. Relevant parameters: freq, dur, numharm, release, amp.
(
Pbind(
\instrument, "blips",
\freq, Pseq([20, 27, 38, 21, 30], inf) * 3, // try other multipliers
\dur, Pseq([1, 1, 0.5, 0.4, 1], inf),
\numharm, Pwhite(10, 50),
\rel, 1,
\amp, Pwhite(0.1, 1);
).play;
)
// "noisy" instrument example. Relevant parameters: freq, dur, amp.
(
Pbind(
\instrument, "noisy",
\freq, Pseries(110, 10, 20),
\dur, Pseq([1/4, 1/4, 1/8], inf),
\amp, Pwhite(0.1, 0.4);
).play;
)
// "hihat" instrument example. Relevant parameters: duration, filter frequency, release.
(
Pbind(
\instrument, "hihat",
\dur, Pseq([1/2, 1/2, 1/2, 1/4, 1/4] * 0.35, inf), // + Prand([0, 0.001],inf),
\ffreq, 9000, // Prand([15000, 9000, 8000], inf),
\rel, 0.1; // Prand( (0.01, 0.02 .. 0.1), inf)
).play;
)
// "snare" instrument example.
(
Pbind(
\instrument, "snare",
\dur, Pseq([Pseq([1, 1/3, 1/3, 1/3], 3), 1, 1], 4) * 0.3,
\sinfreq, Pwhite(100,110,inf),
\amp, 0.05;
).play;
)
// "kick" instrument example.
(
Pbind(
\instrument, "kick",
\dur, Pseq([1, Rest, 1, Rest], inf) * 1/4,
\amp, Pseq([0.5, Rest, 1, Rest], inf),
\rel, 0.5, // Pwhite(0.5, 0.7, inf),
\glissf, 0.2; // Pwhite(0.1, 0.9, inf)
).play;
)
// "kick3" instrument example
(
p = Pbind(
\instrument, "kick3",
\punch, Pseq([
Pseq([0.01], 4),
Pseq([0.1], 4),
Pseq([1], 4),
Pseq([10], 4),
Pseq([100], 4),
Pseq([1000], 4)], inf),
\amp, 0.1, // careful: can be loud!
\dur, 0.5,
).play;
)
// A shorter way of writing the above:
(
p = Pbind(
\instrument, "kick3",
\punch, Place([0.01, 0.1, 1, 10, 100, 1000]!4, inf),
\amp, 0.1, // careful: can be loud!
\dur, 0.5,
).play;
)
Place([0.01, 0.1, 1, 10, 100, 1000]!4, 40).asStream.all;
// Chords (note the "tone" parameter)
(
Pbind(
\instrument, "PMCrotale",
\midinote, Pseq([[57,60,64]-3, [57,60,64]-6], inf)-Prand([0,1,3],inf),
\dur, Prand([1/2, 1/2, 1/4, 1/3, 1/3, 1/5], inf),
\art, Prand([1.5, 1.75, 2], inf),
\tone, Pwhite(2, 3),
\amp, Prand([0.2, 0.3, 0.1],inf),
).play;
)
// **********************************
// Remember, you can always use .asStream.all to quickly check what the ouput of a pattern will look like.
Pseq([1, 2, 3], 4).asStream.all; // 12 items = 4 repeats * 3 items
Pser([1, 2, 3, 4, 5, 6, 7], 5).asStream.all; // 5 items only
Pwhite(0, 7, 10).asStream.all; // 10 random numbers between 0 and 7 (including 7)
Pslide([1, 2, 3, 4, 5, 6, 7, 8], 10, 3, 1, 0, false).asStream.all;
// Another way of writing the same thing (declaring arguments explicitly may be helpful):
(
Pslide(
list: [1, 2, 3, 4, 5, 6, 7, 8],
repeats: 10, // number of segments
len: 3, // length of each segment
step: 1, // step between segments
start: 0, // what index to start at
wrapAtEnd: false // do not wrap around
).asStream.all.clump(3) // clump -- easier to see the groupings
)
// Dirty trick to generate an Array:
(-5, -4 .. 12);
// So this is what we get:
Pslide((-5, -4 .. 12), 20, 3, 1, 0, false).asStream.all.clump(3);
// ------------------------------------------------ //
// DIFFERENCE BETWEEN PBIND AND EVENT STREAM PLAYER
// ------------------------------------------------ //
// The Pbind is like the actual "SCORE". It is not the "PLAYER"
// When you call "play" on a Pbind, it returns a
// Event Stream Player. THAT is the actual "player" of the score.
a = Pbind(\degree, Pwhite(10, 14), \dur, 1/2);
b = Pbind(\note, Pseq([[0, 4, 9], [-1, 3, 8]], inf), \dur, 1);
~player1 = a.play;
~player2 = b.play;
// NOW you can ask the PLAYERS to stop:
~player1.stop;
~player2.stop;
// Notice that it doesn't make sense to ask the "score" to stop
Pbind( /* blah blah blah */).stop; // wrong
// ----------- //
// SEQUENCING
// ----------- //
// Simple way (not very flexible):
(
{
~player1 = a.play;
1.wait;
~player2 = b.play;
5.wait;
~player1.stop;
5.wait;
~player2.stop;
}.fork;
)
// For more sophisticated control, look up Pspawner
// --------------- //
// CHANGING TEMPO
// --------------- //
(
t = TempoClock.new(72/60);
Pbind(
\degree, Pseq([7, 8, 9, 10], inf),
\legato, 0.1
).play(t);
)
// change it as it plays
t.tempo = 120/60;
// --------- //
// QUANTIZE
// --------- //
a.play(quant: 1);
b.play(quant: 1);
// -------------- //
// NEED SOME REST?
// -------------- //
(
Pbind(
\note, Pseq([0, 1, 2, 3, 4, 5], inf),
\dur, Pseq([0.1, 1, 0.4, Rest(0.1), 1), //
).play;
)
/*
EXERCISE: use Pseries and Pgeom to write a simple Pbind achieving the following musical goals:
a) Create a three-octave descending scale using Pseries;
b) Create a decreasing series of durations (accel) using Pgeom. First note played should have a duration of 1 second, and each successive note should have a shorter duration.
c) Make every third note accented -- something like mf, p, p, mf, p, p, ... etc.
*/
// Scroll down for solution
Pgeom(1, 0.9, 22).asStream.all;
// One solution for the exercise above
(
p = Pbind(
\degree, Pseries(7, -1, 22),
\dur, Pgeom(1, 0.9, inf),
\amp, Pser([0.3, 0.1, 0.1], inf),
\legato, 0.3)
)
p;
p.play;