«Pspawner demo» byBruno Ruviaro

on 11 Nov'16 20:23 in

A short classroom demonstration of sequencing patterns with Pspawner

```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```
```// ===================================
// SynthDefs here
// ===================================

(

) // end of SynthDefs

// ===================================
// Define a bunch of "score snippets"
// ===================================

(

~beat = Pbind(
\degree, [0, 7],
\ctranspose, 24,
\dur, 0.2,
\legato, 0.1,
\amp, Pseq([0.2, 0.12, 0.16, 0.12], inf)
); // forever pattern

~up = Pbind(
\scale, Scale.major,
\degree, Pseq([0, 1, 2, 3, 4, 5, 6, 7], 1), // finite pattern
\dur, 0.2
);

~down = Pbind(
\scale, Scale.minor,
\degree, Pseq([7, 6, 5, 4, 3, 2, 1, 0], 1), // finite pattern
\dur, 0.1,
);

~trill = Pbind(
\degree, Pseq([8, 9], 4), // finite Pattern
\dur, 0.1
);

~thick = Pbind(
\degree, Pseq([0, 1, 2, 3, 4, 5, 6, 7], 1), // finite Pattern
\dur, 0.2,
\mtranspose, [0, 2, 4, 6, 8, 10, 12, 14]
);

) // end of Pbind definitions

// ============
// Quick test
// ============

~beat.play;
~up.play;
~down.play;
~trill.play;
~thick.play;

// =====================
// Sequencing & playing
// using Pspawner
// =====================

// The advantage is that the spawner *knows* when a pattern has finished.
// (... as opposed to sequencing patterns inside a {}.fork)

// It's like a fork (things happen in order top to bottom), but
// you always use the spawner argument (in this case, "maestro" -- arbitrary name)
// in order to request a new pattern.

// Notice you should NOT put any .play inside the Pspawner. The only .play is at the very end of the Pspawner.

// When you write "maestro.seq(somePattern)", you are saying:
// "maestro, please play this pattern and only move on in the sequence AFTER said pattern is finished".

// When you write "maestro.par(somePattern)", you are saying:
// "maestro, please start playing this pattern and MOVE ON RIGHT AWAY to the next line."

// Patterns that self-terminate will do so as expected.
// Patterns that do not self-terminate (inf) will keep going forever until told to stop.

// TIP 1: Notice that if you write maestro.seq(someInfPattern) you are setting yourself up for failture. If you request maestro to play an *infinite* pattern and only move on when it's finished, maestro will never move on.

// TIP 2: In order to control start and stop of specific patterns, you should declare a new variable to name it (as you learned before). See ~player1 example below.

(
Pspawner({ arg maestro;

"Scales in sequence, one right after the other".postln;
maestro.seq(~up);
"Down...".postln;
maestro.seq(~down);

"With a little pause in between".postln;
maestro.wait(2.5);
maestro.seq(~up);
maestro.wait(1);
maestro.seq(~down);
maestro.wait(1);

"Now two of them in paralell".postln;
maestro.seq(Ppar([~up, ~down]));

maestro.wait(4);

"Now the never-ending beat".postln;
// Saving into a variable so I can stop it later
~player1 = maestro.par(~beat);
maestro.wait(4);

"Up again...".postln;
maestro.seq(~up);
maestro.wait(1);

"Stop player1 beta".postln;
maestro.suspend(~player1); // stop that one
maestro.wait(1);

"Play the thick pattern".postln;
maestro.seq(~thick);

"Bye!".postln;
maestro.suspendAll;

}).play
)```
raw 3398 chars (focus & ctrl+a+c to copy)
reception