supernova: c++11 compile fixes
[supercollider.git] / Help / Streams-Patterns-Events / Streams-Patterns-Events3.html
blobd354dc1c78f2302785dafe52476e054af303d477
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="1038.29">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica; min-height: 19.0px}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #9d1c12}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
22 p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0026b4}
23 p.p14 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000ee}
24 span.s1 {color: #0026b4}
25 span.s2 {color: #000000}
26 span.s3 {color: #9d1c12}
27 span.s4 {color: #0000bf}
28 span.s5 {color: #007300}
29 span.s6 {text-decoration: underline}
30 span.Apple-tab-span {white-space:pre}
31 </style>
32 </head>
33 <body>
34 <p class="p1"><br></p>
35 <p class="p2"><b>Understanding Streams, Patterns and Events - Part 3</b></p>
36 <p class="p3"><br></p>
37 <p class="p4"><b>ListPatterns</b></p>
38 <p class="p3"><br></p>
39 <p class="p4">ListPatterns are Patterns that iterate over arrays of objects in some fashion. All ListPatterns have in common the instance variables list and repeats. The list variable is some Array to be iterated over. The repeats variable is</p>
40 <p class="p4">some measure of the number of times to do something, whose meaning varies from subclass to subclass. The default value for repeats is 1.</p>
41 <p class="p3"><br></p>
42 <p class="p4">Pseq is a Pattern that cycles over a list of values. The repeats variable gives the number of times to repeat the entire list.<span class="Apple-converted-space"> </span></p>
43 <p class="p3"><br></p>
44 <p class="p3"><br></p>
45 <p class="p5">//////////////////////////////////////////////////////////////</p>
46 <p class="p5">// Note: This SynthDef used throughout this document</p>
47 <p class="p6">(</p>
48 <p class="p6">s = <span class="s1">Server</span>.local;</p>
49 <p class="p7"><span class="s1">SynthDef</span><span class="s2">( </span>\help_SPE3_SimpleSine<span class="s2">, {</span></p>
50 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">arg</span> freq, sustain=1.0;</p>
51 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">var</span> osc;</p>
52 <p class="p6"><span class="Apple-tab-span"> </span>osc = <span class="s1">SinOsc</span>.ar( [freq,freq+0.05.rand] ) * <span class="s1">EnvGen</span>.ar(<span class="Apple-converted-space"> </span></p>
53 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Env</span>.perc, doneAction: 2, levelScale: 0.3, timeScale: sustain</p>
54 <p class="p6"><span class="Apple-tab-span"> </span>);</p>
55 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(0,osc);</p>
56 <p class="p6">}).add;</p>
57 <p class="p6">)</p>
58 <p class="p5">//////////////////////////////////////////////////////////////</p>
59 <p class="p8"><br></p>
60 <p class="p6">(</p>
61 <p class="p6"><span class="s1">var</span> a, b;</p>
62 <p class="p6">a = <span class="s1">Pseq</span>.new(#[1, 2, 3], 2);<span class="Apple-tab-span"> </span><span class="s3">// repeat twice</span></p>
63 <p class="p6">b = a.asStream;</p>
64 <p class="p6">7.do({ b.next.postln; });</p>
65 <p class="p6">)</p>
66 <p class="p3"><br></p>
67 <p class="p4">Pseq also has an offset argument which gives a starting offset into the list.</p>
68 <p class="p3"><br></p>
69 <p class="p6">(</p>
70 <p class="p6"><span class="s1">var</span> a, b;</p>
71 <p class="p6">a = <span class="s1">Pseq</span>.new(#[1, 2, 3, 4], 3, 2); <span class="s3">// repeat 3, offset 2</span></p>
72 <p class="p6">b = a.asStream;</p>
73 <p class="p6">13.do({ b.next.postln; });</p>
74 <p class="p6">)</p>
75 <p class="p3"><br></p>
76 <p class="p4">You can pass a function for the repeats variable that gets evaluated when the stream is created.</p>
77 <p class="p3"><br></p>
78 <p class="p6">(</p>
79 <p class="p6"><span class="s1">var</span> a, b;</p>
80 <p class="p6">a = <span class="s1">Pseq</span>.new(#[1, 2], { rrand(1, 3) });<span class="Apple-tab-span"> </span><span class="s3">// repeat 1,2, or 3 times</span></p>
81 <p class="p6">b = a.asStream;</p>
82 <p class="p6">7.do({ b.next.postln; });</p>
83 <p class="p6">)</p>
84 <p class="p3"><br></p>
85 <p class="p4">If you specify the value inf for the repeats variable, then it will repeat indefinitely.</p>
86 <p class="p3"><br></p>
87 <p class="p6">(</p>
88 <p class="p6"><span class="s1">var</span> a, b;</p>
89 <p class="p6">a = <span class="s1">Pseq</span>.new(#[1, 2, 3], <span class="s1">inf</span>);<span class="Apple-tab-span"> </span><span class="s3">// infinite repeat</span></p>
90 <p class="p6">b = a.asStream;</p>
91 <p class="p6">10.do({ b.next.postln; });</p>
92 <p class="p6">)</p>
93 <p class="p3"><br></p>
94 <p class="p4"><b>Pseq used as a sequence of pitches</b></p>
95 <p class="p3"><br></p>
96 <p class="p4">Remember that math operations like midicps can be used on streams.</p>
97 <p class="p3"><br></p>
98 <p class="p4">The alternative Pseq(...).midicps.asStream is also possible because both pattern and stream inherit from AbstractFunction for which midicps is a method. ( midicps converts a midi value to cycles per second or Hz )</p>
99 <p class="p3"><br></p>
100 <p class="p6">(</p>
101 <p class="p6"><span class="s4">var</span> a, d;</p>
102 <p class="p6">a = <span class="s4">Pseq</span>(#[60, 61, 63, 65, 67, 63], <span class="s4">inf</span> ).asStream.midicps;</p>
103 <p class="p6">d = 0.3;</p>
104 <p class="p9">Task<span class="s2">({</span></p>
105 <p class="p6"><span class="Apple-tab-span"> </span>12.do({</p>
106 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_SimpleSine<span class="s2">, [ </span>\freq<span class="s2">, a.next, </span>\sustain<span class="s2">, d ]);</span></p>
107 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>d.wait;</p>
108 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
109 <p class="p6">}).play</p>
110 <p class="p6">)</p>
111 <p class="p3"><br></p>
112 <p class="p4">Pser is like Pseq, however the repeats variable gives the number of items returned instead of the number of complete cycles.<span class="Apple-converted-space"> </span></p>
113 <p class="p3"><br></p>
114 <p class="p6">(</p>
115 <p class="p6"><span class="s1">var</span> a, b;</p>
116 <p class="p6">a = <span class="s1">Pser</span>.new(#[1, 2, 3], 5);<span class="Apple-tab-span"> </span><span class="s3">// return 5 items</span></p>
117 <p class="p6">b = a.asStream;</p>
118 <p class="p6">6.do({ b.next.postln; });</p>
119 <p class="p6">)</p>
120 <p class="p3"><br></p>
121 <p class="p4">Prand returns one item from the list at random for each repeat.<span class="Apple-converted-space"> </span></p>
122 <p class="p3"><br></p>
123 <p class="p6">(</p>
124 <p class="p6"><span class="s1">var</span> a, b;</p>
125 <p class="p6">a = <span class="s1">Prand</span>.new(#[1, 2, 3, 4, 5], 6);<span class="Apple-tab-span"> </span><span class="s3">// return 6 items</span></p>
126 <p class="p6">b = a.asStream;</p>
127 <p class="p6">7.do({ b.next.postln; });</p>
128 <p class="p6">)</p>
129 <p class="p3"><br></p>
130 <p class="p4">Prand used as a sequence of pitches:</p>
131 <p class="p3"><br></p>
132 <p class="p6">(</p>
133 <p class="p6"><span class="s4">var</span> a, d;</p>
134 <p class="p6">a = <span class="s4">Prand</span>(#[60, 61, 63, 65], <span class="s4">inf</span>).midicps.asStream;</p>
135 <p class="p6">d = 0.3;</p>
136 <p class="p9">Task<span class="s2">({</span></p>
137 <p class="p6"><span class="Apple-tab-span"> </span>12.do({</p>
138 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_SimpleSine<span class="s2">,[</span>\freq<span class="s2">, a.next]);</span></p>
139 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>d.wait;</p>
140 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
141 <p class="p6">}).play;</p>
142 <p class="p6">)</p>
143 <p class="p3"><br></p>
144 <p class="p4">Pxrand, like Prand, returns one item from the list at random for each repeat, but Pxrand never repeats the same element twice in a row.<span class="Apple-converted-space"> </span></p>
145 <p class="p3"><br></p>
146 <p class="p6">(</p>
147 <p class="p6"><span class="s1">var</span> a, b;</p>
148 <p class="p6">a = <span class="s1">Pxrand</span>.new(#[1, 2, 3], 10);<span class="Apple-tab-span"> </span><span class="s3">// return 10 items</span></p>
149 <p class="p6">b = a.asStream;</p>
150 <p class="p6">11.do({ b.next.postln; });</p>
151 <p class="p6">)</p>
152 <p class="p3"><br></p>
153 <p class="p4">Pxrand used as a sequence of pitches:</p>
154 <p class="p11"><br></p>
155 <p class="p6">(</p>
156 <p class="p6"><span class="s4">var</span> a;</p>
157 <p class="p6">a = <span class="s4">Pxrand</span>(#[60, 61, 63, 65], <span class="s4">inf</span>).midicps.asStream;</p>
158 <p class="p9">Task<span class="s2">({</span></p>
159 <p class="p6"><span class="Apple-tab-span"> </span>12.do({</p>
160 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_SimpleSine<span class="s2">, [</span>\freq<span class="s2">, a.next]);</span></p>
161 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.8.wait;</p>
162 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
163 <p class="p6">}).play;</p>
164 <p class="p6">)</p>
165 <p class="p3"><br></p>
166 <p class="p4">Pshuf iterates over the list in scrambled order. The entire scrambled list is repeated in the same order the number of times given by the repeats variable.</p>
167 <p class="p11"><br></p>
168 <p class="p6">(</p>
169 <p class="p6"><span class="s1">var</span> a, b;</p>
170 <p class="p6">a = <span class="s1">Pshuf</span>.new(#[1, 2, 3, 4], 3);</p>
171 <p class="p6">b = a.asStream;</p>
172 <p class="p6">13.do({ b.next.postln; });</p>
173 <p class="p6">)</p>
174 <p class="p3"><br></p>
175 <p class="p4">Pshuf used as a sequence of pitches:</p>
176 <p class="p11"><br></p>
177 <p class="p6">(</p>
178 <p class="p6"><span class="s4">var</span> a, b;</p>
179 <p class="p6">a = <span class="s4">Pshuf</span>(#[60, 61, 65, 67], <span class="s4">inf</span>).midicps.asStream;</p>
180 <p class="p9">Task<span class="s2">({</span></p>
181 <p class="p6"><span class="Apple-tab-span"> </span>12.do({</p>
182 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_SimpleSine<span class="s2">,[</span>\freq<span class="s2">, a.next]);</span></p>
183 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.5.wait;</p>
184 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
185 <p class="p6">}).play;</p>
186 <p class="p6">)</p>
187 <p class="p3"><br></p>
188 <p class="p4"><b>Nesting Patterns</b></p>
189 <p class="p3"><br></p>
190 <p class="p4">If a Pattern encounters another Pattern in its list, it embeds that pattern in its output. That is, it creates a stream on that pattern and iterates that pattern until it ends before moving on.</p>
191 <p class="p3"><br></p>
192 <p class="p4">For example here is one pattern nested in another.</p>
193 <p class="p3"><br></p>
194 <p class="p6">(</p>
195 <p class="p6"><span class="s1">var</span> a, b;</p>
196 <p class="p6">a = <span class="s1">Pseq</span>.new([1, <span class="s1">Pseq</span>.new([100,200], 2), 3], 3);<span class="Apple-tab-span"> </span></p>
197 <p class="p6">b = a.asStream;</p>
198 <p class="p6">19.do({ b.next.postln; });</p>
199 <p class="p6">)</p>
200 <p class="p11"><br></p>
201 <p class="p4">Pseqs nested in a Prand:</p>
202 <p class="p11"><br></p>
203 <p class="p6">(</p>
204 <p class="p6"><span class="s1">var</span> a, b;</p>
205 <p class="p6">a = <span class="s1">Prand</span>.new([</p>
206 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>.new([1, 2], 2),<span class="Apple-converted-space"> </span></p>
207 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>.new([3, 4], 2),<span class="Apple-converted-space"> </span></p>
208 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>.new([5, 6], 2)</p>
209 <p class="p6"><span class="Apple-tab-span"> </span>], 3);<span class="Apple-tab-span"> </span></p>
210 <p class="p6">b = a.asStream;</p>
211 <p class="p6">13.do({ b.next.postln; });</p>
212 <p class="p6">)</p>
213 <p class="p3"><br></p>
214 <p class="p4">Nested sequences of pitches:</p>
215 <p class="p3"><br></p>
216 <p class="p6">(</p>
217 <p class="p6"><span class="s4">var</span> a;</p>
218 <p class="p6">a = <span class="s4">Prand</span>([</p>
219 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Pseq</span>(#[60, 61, 63, 65, 67, 63]),</p>
220 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Prand</span>(#[72, 73, 75, 77, 79], 6),</p>
221 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Pshuf</span>(#[48, 53, 55, 58], 2)</p>
222 <p class="p6"><span class="Apple-tab-span"> </span>], <span class="s4">inf</span><span class="Apple-converted-space"> </span></p>
223 <p class="p6">).midicps.asStream;</p>
224 <p class="p9">Task<span class="s2">({</span></p>
225 <p class="p6"><span class="Apple-tab-span"> </span>loop({</p>
226 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">( </span>\help_SPE3_SimpleSine<span class="s2">, [</span>\freq<span class="s2">, a.next] );</span></p>
227 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.3.wait;</p>
228 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
229 <p class="p6">}).play;</p>
230 <p class="p6">)</p>
231 <p class="p3"><br></p>
232 <p class="p4"><b>Math operations on ListPatterns</b></p>
233 <p class="p3"><br></p>
234 <p class="p4">Pattern b plays pattern a once normally, once transposed up a fifth and once transposed up a fourth.</p>
235 <p class="p3"><br></p>
236 <p class="p6">(</p>
237 <p class="p6"><span class="s4">var</span> a, b;</p>
238 <p class="p6">a = <span class="s4">Pseq</span>(#[60, 62, 63, 65, 67, 63]);</p>
239 <p class="p6">b = <span class="s4">Pseq</span>([ a, a + 7, a + 5], <span class="s4">inf</span>).asStream;</p>
240 <p class="p9">Task<span class="s2">({</span></p>
241 <p class="p6"><span class="Apple-tab-span"> </span>24.do({</p>
242 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Synth</span>(<span class="s5">\help_SPE3_SimpleSine</span>, [ <span class="s5">\freq</span>, b.next.midicps ]);</p>
243 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.3.wait;</p>
244 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
245 <p class="p6">}).play;</p>
246 <p class="p6">)</p>
247 <p class="p3"><br></p>
248 <p class="p4">Adding two patterns together. The second pattern transposes each fifth note of the first pattern down an octave.</p>
249 <p class="p3"><br></p>
250 <p class="p6">(</p>
251 <p class="p6"><span class="s4">var</span> a;</p>
252 <p class="p6">a = <span class="s4">Pseq</span>(#[60, 62, 63, 65, 67, 63], <span class="s4">inf</span>) + <span class="s4">Pseq</span>(#[0, 0, 0, 0, -12], <span class="s4">inf</span>);</p>
253 <p class="p6">a = a.asStream.midicps;</p>
254 <p class="p9">Task<span class="s2">({</span></p>
255 <p class="p6"><span class="Apple-tab-span"> </span>25.do({</p>
256 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_SimpleSine<span class="s2">,[</span>\freq<span class="s2">, a.next]);</span></p>
257 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.3.wait;</p>
258 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
259 <p class="p6">}).play;</p>
260 <p class="p6">)</p>
261 <p class="p3"><br></p>
262 <p class="p4"><b>Making Music with ListPatterns</b></p>
263 <p class="p3"><br></p>
264 <p class="p4">Here is the same example given in part 2 rewritten to use ListPatterns. It uses nested patterns and results in much more concise code. SuperCollider allows you to write SomeClass.new(params) as SomeClass(params)</p>
265 <p class="p4">eliminating the ".new" .<span class="Apple-converted-space">  </span>This can make code like the pattern examples below, which create a lot of objects, more readable.</p>
266 <p class="p11"><br></p>
267 <p class="p6">(</p>
268 <p class="p10"><span class="s4">SynthDef</span><span class="s2">( </span>\help_SPE3_Allpass6<span class="s2">, { </span><span class="s4">arg</span><span class="s2"> freq;</span></p>
269 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">var</span> out, env;</p>
270 <p class="p6"><span class="Apple-tab-span"> </span>out = <span class="s4">RLPF</span>.ar(</p>
271 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">LFSaw</span>.ar( freq, mul: <span class="s4">EnvGen</span>.kr( <span class="s4">Env</span>.perc, levelScale: 0.3, doneAction: 2 ) ),</p>
272 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">LFNoise1</span>.kr(1, 36, 110).midicps,</p>
273 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.1</p>
274 <p class="p6"><span class="Apple-tab-span"> </span>);</p>
275 <p class="p6"><span class="Apple-tab-span"> </span>6.do({ out = <span class="s4">AllpassN</span>.ar(out, 0.05, [0.05.rand, 0.05.rand], 4) });</p>
276 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Out</span>.ar( 0, out<span class="Apple-converted-space">  </span>);</p>
277 <p class="p6">}).add</p>
278 <p class="p6">)</p>
279 <p class="p8"><br></p>
280 <p class="p6">(</p>
281 <p class="p8"><br></p>
282 <p class="p6"><span class="s4">var</span> freqStream;</p>
283 <p class="p8"><br></p>
284 <p class="p6">freqStream = <span class="s4">Pseq</span>([</p>
285 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span></span>Prand<span class="s2">([</span></p>
286 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">nil</span><span class="s2">,<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// a nil item reached in a pattern causes it to end</p>
287 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Pseq</span>(#[24, 31, 36, 43, 48, 55]);</p>
288 <p class="p6"><span class="Apple-tab-span"> </span>]),</p>
289 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Pseq</span>([ 60, <span class="s4">Prand</span>(#[63, 65]), 67, <span class="s4">Prand</span>(#[70, 72, 74]) ], { rrand(2, 5) }),</p>
290 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Prand</span>(#[74, 75, 77, 79, 81], { rrand(3, 9) })</p>
291 <p class="p6">], <span class="s4">inf</span>).asStream.midicps;</p>
292 <p class="p8"><br></p>
293 <p class="p9">Task<span class="s2">({</span></p>
294 <p class="p6"><span class="Apple-tab-span"> </span>loop({</p>
295 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Synth</span>( <span class="s5">\help_SPE3_Allpass6</span>, [<span class="s5">\freq</span>, freqStream.next ]);</p>
296 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.13.wait;</p>
297 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
298 <p class="p6">}).play;<span class="Apple-tab-span"> </span></p>
299 <p class="p8"><br></p>
300 <p class="p6">)</p>
301 <p class="p3"><br></p>
302 <p class="p3"><br></p>
303 <p class="p3"><br></p>
304 <p class="p4">Here is an example that uses a Pattern to create a rhythmic solo. The values in the pattern specify the amplitudes of impulses fed to the Decay2 generator.</p>
305 <p class="p11"><br></p>
306 <p class="p6">(</p>
307 <p class="p10"><span class="s4">SynthDef</span><span class="s2">( </span>\help_SPE3_Mridangam<span class="s2">, { </span><span class="s4">arg</span><span class="s2"> t_amp;</span></p>
308 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">var</span> out;</p>
309 <p class="p8"><br></p>
310 <p class="p6"><span class="Apple-tab-span"> </span>out = <span class="s4">Resonz</span>.ar(<span class="Apple-converted-space"> </span></p>
311 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">WhiteNoise</span>.ar(70) * <span class="s4">Decay2</span>.kr( t_amp, 0.002, 0.1 ),</p>
312 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>60.midicps,<span class="Apple-converted-space"> </span></p>
313 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.02,</p>
314 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>4</p>
315 <p class="p6"><span class="Apple-tab-span"> </span>).distort * 0.4;</p>
316 <p class="p8"><span class="Apple-tab-span"> </span></p>
317 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Out</span>.ar( 0, out<span class="Apple-converted-space">  </span>);</p>
318 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">DetectSilence</span>.ar( out,<span class="Apple-converted-space">  </span>doneAction: 2 );</p>
319 <p class="p6">}).add;</p>
320 <p class="p8"><br></p>
321 <p class="p10"><span class="s4">SynthDef</span><span class="s2">( </span>\help_SPE3_Drone<span class="s2">, {</span></p>
322 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">var</span> out;</p>
323 <p class="p6"><span class="Apple-tab-span"> </span>out = <span class="s4">LPF</span>.ar(</p>
324 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Saw</span>.ar([60, 60.04].midicps)<span class="Apple-converted-space"> </span></p>
325 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>+<span class="Apple-converted-space"> </span></p>
326 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Saw</span>.ar([67, 67.04].midicps),<span class="Apple-converted-space"> </span></p>
327 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>108.midicps,<span class="Apple-converted-space"> </span></p>
328 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.007</p>
329 <p class="p6"><span class="Apple-tab-span"> </span>);</p>
330 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Out</span>.ar( 0, out<span class="Apple-converted-space">  </span>);</p>
331 <p class="p6">}).add;</p>
332 <p class="p6">)</p>
333 <p class="p8"><br></p>
334 <p class="p6">(</p>
335 <p class="p5">// percussion solo in 10/8</p>
336 <p class="p8"><br></p>
337 <p class="p6"><span class="s1">var</span> stream, pat, amp;</p>
338 <p class="p8"><br></p>
339 <p class="p6">pat = <span class="s1">Pseq</span>([</p>
340 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.0], 10),</p>
341 <p class="p8"><br></p>
342 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// intro</p>
343 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2),</p>
344 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0], 2),</p>
345 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.2, 0.0, 0.2, 0.0, 0.2, 0.0, 0.0], 2),</p>
346 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, 0.2, 0.0, 0.2], 2),</p>
347 <p class="p8"><span class="Apple-tab-span"> </span></p>
348 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// solo</p>
349 <p class="p13"><span class="s2"><span class="Apple-tab-span"> </span></span>Prand<span class="s2">([</span></p>
350 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.7, 0.0, 0.2, 0.0, 0.7, 0.0, 0.0]),</p>
351 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.2, 0.0, 0.7, 0.0, 0.2, 0.0, 0.7, 0.0, 0.0]),</p>
352 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.7, 0.0, 0.2, 0.0, 0.7, 0.0, 0.2]),</p>
353 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.7, 0.2, 0.2, 0.0, 0.7, 0.0, 0.0]),</p>
354 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.7, 0.0, 0.2, 0.2, 0.7, 0.2, 0.0]),</p>
355 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.2, 0.2, 0.7, 0.2, 0.2, 0.2, 0.7, 0.2, 0.2]),</p>
356 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.2, 0.2, 0.7, 0.2, 0.2, 0.2, 0.7, 0.0, 0.0]),</p>
357 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.7, 0.2, 0.2, 0.2, 0.7, 0.0, 0.0]),</p>
358 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0]),</p>
359 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.4, 0.0, 0.0, 0.4, 0.2, 0.4, 0.2]),</p>
360 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.2, 0.7, 0.0, 0.2, 0.0, 0.7, 0.0, 0.0]),</p>
361 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.7, 0.0, 0.0, 0.0, 0.7, 0.0, 0.0]),</p>
362 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.7, 0.7, 0.0, 0.0, 0.2, 0.2, 0.2, 0.0, 0.0]),</p>
363 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])</p>
364 <p class="p6"><span class="Apple-tab-span"> </span>], 30),</p>
365 <p class="p8"><span class="Apple-tab-span"> </span></p>
366 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// tehai : 7 beat motif 3 times sharing 1st beat with next 7x3<span class="Apple-converted-space"> </span></p>
367 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// and again the third time:</p>
368 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// <span class="Apple-converted-space">  </span>123456712345671234567 <span class="Apple-converted-space">                  </span>123456712345671234567</p>
369 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// <span class="Apple-converted-space">                      </span>123456712345671234567</p>
370 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// <span class="Apple-converted-space">  </span>! <span class="Apple-converted-space">                  </span>! <span class="Apple-converted-space">                  </span>! <span class="Apple-converted-space">                  </span>!</p>
371 <p class="p5"><span class="s2"><span class="Apple-tab-span"> </span></span>// <span class="Apple-converted-space">  </span>1234567890123456789012345678901234567890123456789012345678901</p>
372 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[2.0, 0.0, 0.2, 0.5, 0.0, 0.2, 0.9,<span class="Apple-converted-space"> </span></p>
373 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>1.5, 0.0, 0.2, 0.5, 0.0, 0.2, 0.9,<span class="Apple-converted-space"> </span></p>
374 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>1.5, 0.0, 0.2, 0.5, 0.0, 0.2], 3),<span class="Apple-converted-space"> </span></p>
375 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[5], 1), <span class="s3">// sam</span></p>
376 <p class="p8"><span class="Apple-tab-span"> </span></p>
377 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pseq</span>(#[0.0], <span class="s1">inf</span>)</p>
378 <p class="p6">]);</p>
379 <p class="p8"><span class="Apple-tab-span"> </span></p>
380 <p class="p6">stream = pat.asStream;</p>
381 <p class="p8"><br></p>
382 <p class="p9">Task<span class="s2">({</span></p>
383 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span></span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_Drone<span class="s2">);</span></p>
384 <p class="p6"><span class="Apple-tab-span"> </span>loop({</p>
385 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>if( ( amp = stream.next ) &gt; 0,</p>
386 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{ </span><span class="s4">Synth</span><span class="s2">(</span>\help_SPE3_Mridangam<span class="s2">, [ </span>\t_amp<span class="s2">, amp ]) }</span></p>
387 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>);</p>
388 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(1/8).wait;</p>
389 <p class="p6"><span class="Apple-tab-span"> </span>})</p>
390 <p class="p6">}).play</p>
391 <p class="p8"><br></p>
392 <p class="p6">)</p>
393 <p class="p3"><br></p>
394 <p class="p4">To go to the next file:</p>
395 <p class="p14"><span class="s6"><a href="Streams-Patterns-Events4.html">Streams-Patterns-Events4</a></span></p>
396 <p class="p3"><br></p>
397 <p class="p3"><br></p>
398 </body>
399 </html>