polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Libraries / JITLib / tutorials / proxyspace_examples.html
blob9d64a87548a91476b61e28aab500e631a7974103
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.25">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Helvetica; min-height: 18.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Futura}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Futura}
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: #ad140d}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Futura; min-height: 15.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 8.0px Monaco; color: #001bb9}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica; min-height: 19.0px}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica; min-height: 16.0px}
22 p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #2c7014}
23 p.p14 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #001bb9}
24 p.p15 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
25 span.s1 {color: #001bb9}
26 span.s2 {color: #2c7014}
27 span.s3 {color: #ad140d}
28 span.s4 {color: #000000}
29 span.s5 {font: 9.0px Monaco}
30 span.s6 {font: 12.0px Helvetica; color: #001bb9}
31 span.s7 {color: #606060}
32 span.Apple-tab-span {white-space:pre}
33 </style>
34 </head>
35 <body>
36 <p class="p1"><b>proxy space examples</b></p>
37 <p class="p2"><br></p>
38 <p class="p3">Overview: <a href="../JITLib.html"><span class="s1">JITLib</span></a></p>
39 <p class="p3">see also: <a href="../environments/ProxySpace.html"><span class="s1">ProxySpace</span></a></p>
40 <p class="p2"><br></p>
41 <p class="p2"><br></p>
42 <p class="p4"><br></p>
43 <p class="p5">preparing the environment</p>
44 <p class="p4"><br></p>
45 <p class="p6">(</p>
46 <p class="p6">s.boot;</p>
47 <p class="p6">p = <span class="s1">ProxySpace</span>.push(s);</p>
48 <p class="p6">)</p>
49 <p class="p4"><br></p>
50 <p class="p5">playing and monitoring</p>
51 <p class="p4"><br></p>
52 <p class="p7">// play some output to the hardware busses, this could be any audio rate key.</p>
53 <p class="p6">~out.play;</p>
54 <p class="p4"><br></p>
55 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar([400, 408] * 0.8, 0, 0.2) };</p>
56 <p class="p4"><br></p>
57 <p class="p4"><br></p>
58 <p class="p7">// replacing the node. the crossfade envelope is created internally.</p>
59 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar([443, 600 - <span class="s1">Rand</span>(0,200)], 0, 0.2) };</p>
60 <p class="p6">~out = { <span class="s1">Resonz</span>.ar(<span class="s1">Saw</span>.ar(40 + [0,0.2], 1), [1200, 1600], 0.1) + <span class="s1">SinOsc</span>.ar(60 * [1,1.1],0,0.2) };</p>
61 <p class="p6">~out = { <span class="s1">Pan2</span>.ar(<span class="s1">PinkNoise</span>.ar(0.1), <span class="s1">LFClipNoise</span>.kr(2)) };</p>
62 <p class="p4"><br></p>
63 <p class="p5">setting the node controls</p>
64 <p class="p4"><br></p>
65 <p class="p6">~out = { <span class="s1">arg</span> rate = 2; <span class="s1">Pan2</span>.ar(<span class="s1">PinkNoise</span>.ar(0.1), <span class="s1">LFClipNoise</span>.kr(rate)) };</p>
66 <p class="p6">~out.set(<span class="s2">\rate</span>, 30);</p>
67 <p class="p6">~out = { <span class="s1">arg</span> rate = 2; <span class="s1">Pan2</span>.ar(<span class="s1">Dust</span>.ar(2000, 0.2), <span class="s1">LFClipNoise</span>.kr(rate)) };</p>
68 <p class="p6">~out.set(<span class="s2">\rate</span>, 2);</p>
69 <p class="p4"><br></p>
70 <p class="p5">referencing between proxies</p>
71 <p class="p4"><br></p>
72 <p class="p6">~lfo = { <span class="s1">LFNoise2</span>.kr(30, 300, 500) };</p>
73 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(~lfo.kr, 0, 0.15)<span class="Apple-converted-space">  </span>};</p>
74 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(~lfo.kr * [1, 1.2], 0, 0.1) * <span class="s1">Pulse</span>.ar(~lfo.kr * [0.1, 0.125], 0.5) };</p>
75 <p class="p6">~lfo = { <span class="s1">LFNoise1</span>.kr(30, 40) + <span class="s1">SinOsc</span>.kr(0.1, 0, 200, 500) };</p>
76 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(~lfo.kr * [1, 1.2], 0, 0.1)<span class="Apple-converted-space">  </span>};</p>
77 <p class="p6">~lfo = 410;</p>
78 <p class="p4"><br></p>
79 <p class="p8"><br></p>
80 <p class="p5">math</p>
81 <p class="p4"><br></p>
82 <p class="p7">// unary operators</p>
83 <p class="p6">~lfo2 = { <span class="s1">SinOsc</span>.kr(0.5, 0, 600, 100)<span class="Apple-converted-space">  </span>};</p>
84 <p class="p6">~lfo = ~lfo2.abs;</p>
85 <p class="p6">~lfo2 = { <span class="s1">SinOsc</span>.kr(1.3, 0, 600, 100)<span class="Apple-converted-space">  </span>};</p>
86 <p class="p4"><br></p>
87 <p class="p4"><br></p>
88 <p class="p7">// binary operators</p>
89 <p class="p6">~lfo3 = { <span class="s1">LFTri</span>.kr(0.5, 0, 80, 300) };</p>
90 <p class="p6">~lfo = ~lfo2 + ~lfo3;</p>
91 <p class="p6">~lfo = ~lfo3;</p>
92 <p class="p6">~lfo = (~lfo3 / 50).sin * 200 + 500 * { <span class="s1">LFTri</span>.kr(~lfo.kr * 0.0015, 0, 0.1 * ~lfo3.kr / 90, 1) };</p>
93 <p class="p6">~lfo3 = { <span class="s1">Mix</span>(~lfo2.kr * [1, 1.2]) };</p>
94 <p class="p4"><br></p>
95 <p class="p6">currentEnvironment.free; <span class="s3">// free all node proxies</span></p>
96 <p class="p7"><span class="s4">~out.stop; </span>// free the playback synth.</p>
97 <p class="p4"><br></p>
98 <p class="p4"><br></p>
99 <p class="p5">waking up a network of proxies</p>
100 <p class="p4"><br></p>
101 <p class="p7">// hit cmd-. to stop all nodes</p>
102 <p class="p7">// start again</p>
103 <p class="p6">~out.play;<span class="Apple-converted-space"> </span></p>
104 <p class="p4"><br></p>
105 <p class="p5">feeding back (one buffer size delay)</p>
106 <p class="p4"><br></p>
107 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar([220, 330], ~out.ar(2).reverse * <span class="s1">LFNoise2</span>.kr(0.5, 4pi), 0.4) };</p>
108 <p class="p4"><br></p>
109 <p class="p7">// there is no immediacy: hear the buffer size cycle</p>
110 <p class="p6">~out = { <span class="s1">Impulse</span>.ar(1 ! 2) + (~out.ar(2) * 0.99) };<span class="Apple-converted-space"> </span></p>
111 <p class="p4"><br></p>
112 <p class="p4"><br></p>
113 <p class="p4"><br></p>
114 <p class="p7">// supercollider 'differential equations'</p>
115 <p class="p4"><br></p>
116 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(<span class="s1">Slope</span>.ar(~out.ar) * <span class="s1">MouseX</span>.kr(1000, 18000, 1)) * 0.1 + <span class="s1">SinOsc</span>.ar(100, 0, 0.1) };</p>
117 <p class="p4"><br></p>
118 <p class="p6">(</p>
119 <p class="p6">~out = { <span class="s1">var</span> z, zz;</p>
120 <p class="p6"><span class="Apple-tab-span"> </span>z = <span class="s1">Slope</span>.ar(~out.ar);</p>
121 <p class="p6"><span class="Apple-tab-span"> </span>zz = <span class="s1">Slope</span>.ar(z);</p>
122 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">SinOsc</span>.ar(<span class="s1">Rand</span>(300,410), z) *</p>
123 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">SinOsc</span>.ar(zz * 410)<span class="Apple-converted-space"> </span></p>
124 <p class="p6"><span class="Apple-tab-span"> </span>* 0.1 + <span class="s1">Decay2</span>.ar(<span class="s1">Pan2</span>.ar(<span class="s1">Dust</span>.ar(600), <span class="s1">MouseX</span>.kr(-1,1)), 0.01, 0.05);</p>
125 <p class="p6">}</p>
126 <p class="p6">)</p>
127 <p class="p4"><br></p>
128 <p class="p4"><br></p>
129 <p class="p5">multiple control</p>
130 <p class="p4"><br></p>
131 <p class="p6">(</p>
132 <p class="p6">~out = { <span class="s1">arg</span> freqOffest;</p>
133 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">var</span> ctl;</p>
134 <p class="p6"><span class="Apple-tab-span"> </span>ctl = <span class="s1">Control</span>.names(<span class="s2">\array</span>).kr(<span class="s1">Array</span>.rand(8, 400, 1000));</p>
135 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pan2</span>.ar(<span class="s1">Mix</span>(<span class="s1">SinOsc</span>.ar(ctl + freqOffest, 0, 0.1 / 8)), <span class="s1">LFNoise0</span>.kr(2))</p>
136 <p class="p6">};</p>
137 <p class="p6">)<span class="Apple-tab-span"> </span></p>
138 <p class="p4"><br></p>
139 <p class="p6">~out.setn(<span class="s2">\array</span>, <span class="s1">Array</span>.exprand(8, 400, 2000));</p>
140 <p class="p6">~out.set(<span class="s2">\freqOffest</span>, rrand(300,200));</p>
141 <p class="p6">~out.map(<span class="s2">\freqOffest</span>, ~lfo);</p>
142 <p class="p4"><br></p>
143 <p class="p7">// a simpler short form for this is:</p>
144 <p class="p6">(</p>
145 <p class="p6">~out = { <span class="s1">arg</span> freqOffest=0, array = #[ 997, 777, 506, 553, 731, 891, 925, 580 ];</p>
146 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pan2</span>.ar(<span class="s1">Mix</span>(<span class="s1">SinOsc</span>.ar(array + freqOffest, 0, 0.1 / 8)), <span class="s1">LFNoise0</span>.kr(2))</p>
147 <p class="p6">};</p>
148 <p class="p6">)</p>
149 <p class="p4"><br></p>
150 <p class="p4"><br></p>
151 <p class="p4"><br></p>
152 <p class="p5">mixing</p>
153 <p class="p4"><br></p>
154 <p class="p4"><br></p>
155 <p class="p6">~out1 = { <span class="s1">SinOsc</span>.ar(600, 0, 0.1) };</p>
156 <p class="p6">~out2 = { <span class="s1">SinOsc</span>.ar(500, 0, 0.1) };</p>
157 <p class="p6">~out3 = { <span class="s1">SinOsc</span>.ar(400, 0, 0.1) };</p>
158 <p class="p6">~out = ~out2 + ~out1 + ~out3;</p>
159 <p class="p4"><br></p>
160 <p class="p6">~out = ~out1 + ~out2;</p>
161 <p class="p6">~out = ~out1;</p>
162 <p class="p4"><br></p>
163 <p class="p7">// another way is:</p>
164 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(600, 0, 0.1) };</p>
165 <p class="p6">~out.add({ <span class="s1">SinOsc</span>.ar(500, 0, 0.1) });</p>
166 <p class="p6">~out.add({ <span class="s1">SinOsc</span>.ar(400, 0, 0.1) });</p>
167 <p class="p4"><br></p>
168 <p class="p7">// or with direct access:</p>
169 <p class="p6">~out[1] = { <span class="s1">SinOsc</span>.ar(500 * 1.2, 0, 0.1) };</p>
170 <p class="p6">~out[2] = { <span class="s1">SinOsc</span>.ar(400 * 1.2, 0, 0.1) };</p>
171 <p class="p4"><br></p>
172 <p class="p4"><br></p>
173 <p class="p4"><br></p>
174 <p class="p4"><br></p>
175 <p class="p5">restoring / erasing</p>
176 <p class="p4"><br></p>
177 <p class="p7"><span class="s4">~out.free; </span>// this frees the group, not the play synth x</p>
178 <p class="p7"><span class="s4">~out.send; </span>// resends all synths</p>
179 <p class="p6">~out.free;<span class="Apple-converted-space"> </span></p>
180 <p class="p7"><span class="s4">~out.send(</span><span class="s1">nil</span><span class="s4">, 1); </span>// this sends at index 1 only<span class="Apple-converted-space"> </span></p>
181 <p class="p6">~out.send;</p>
182 <p class="p4"><br></p>
183 <p class="p7">// removing:</p>
184 <p class="p6">~out.removeLast;</p>
185 <p class="p6">~out.removeAt(0);</p>
186 <p class="p4"><br></p>
187 <p class="p7">// cleaning up, freeing the bus:</p>
188 <p class="p7"><span class="s4">~out.clear; </span>// this neutralizes the proxy, and frees its bus</p>
189 <p class="p4"><br></p>
190 <p class="p4"><br></p>
191 <p class="p5">for more on the proxy slots see:<span class="s5"> <a href="jitlib_basic_concepts_03.html"><span class="s6">jitlib_basic_concepts_03</span></a><span class="Apple-converted-space"> </span></span></p>
192 <p class="p4"><br></p>
193 <p class="p4"><br></p>
194 <p class="p4"><br></p>
195 <p class="p5">garbage collecting</p>
196 <p class="p4"><br></p>
197 <p class="p7">// often there are proxies playing that are not used anymore - this is good,</p>
198 <p class="p7">// because they might be used again at any time.<span class="Apple-converted-space"> </span></p>
199 <p class="p7">// this shows how to free unused proxies, such as ~out1, ~out2. <span class="Apple-converted-space"> </span></p>
200 <p class="p4"><br></p>
201 <p class="p6">~out.play;</p>
202 <p class="p6">~out = { <span class="s1">Pan2</span>.ar(<span class="s1">SinOsc</span>.ar(~lfo.kr, 0, 0.2), sin(~lfo.kr / 10)) }; <span class="s3">// ~lfo is kept, as its parents.</span></p>
203 <p class="p6">~lfo = { <span class="s1">LFNoise2</span>.kr(3, 160, 400) };</p>
204 <p class="p4"><br></p>
205 <p class="p6">p.keysValuesDo { <span class="s1">arg</span> key, proxy; [key, proxy.isPlaying].postln };</p>
206 <p class="p7"><span class="s4">p.reduce; </span>// all monitoring proxies (in this case ~out) are kept running.</p>
207 <p class="p7">//<span class="Apple-converted-space">  </span>equivalent: p.reduce(to: [~out]);</p>
208 <p class="p6">p.keysValuesDo { <span class="s1">arg</span> key, proxy; [key, proxy.isPlaying].postln };</p>
209 <p class="p4"><br></p>
210 <p class="p7">// to remove everything else:</p>
211 <p class="p6">p.postln;</p>
212 <p class="p7"><span class="s4">p.clean; </span>// all monitoring proxies (in this case ~out) are kept.</p>
213 <p class="p6">p.postln;</p>
214 <p class="p4"><br></p>
215 <p class="p7">// after ~out is stopped, it is removed, too:</p>
216 <p class="p7"><span class="s4">~out.stop; </span>// stop monitor</p>
217 <p class="p6">p.clean;<span class="Apple-converted-space"> </span></p>
218 <p class="p7"><span class="s4">p.postln; </span>// empty space.</p>
219 <p class="p4"><br></p>
220 <p class="p4"><br></p>
221 <p class="p5">execution order</p>
222 <p class="p4"><br></p>
223 <p class="p4"><br></p>
224 <p class="p7">// you can .play .kr or .ar also a name that is not yet used.</p>
225 <p class="p7">// the rate is guessed as far as possible. on this topic see also: [the_lazy_proxy]</p>
226 <p class="p4"><br></p>
227 <p class="p7"><span class="s4">~myOut.play; </span>// play some key (audio rate is assumed)</p>
228 <p class="p4"><br></p>
229 <p class="p7">// the rate is determined from the first access:<span class="Apple-converted-space"> </span></p>
230 <p class="p7">// like this ~lfo becomes control rate</p>
231 <p class="p4"><br></p>
232 <p class="p6">~myOut = { <span class="s1">SinOsc</span>.ar(~freq.kr * 2, 0, 0.1) };<span class="Apple-converted-space"> </span></p>
233 <p class="p6">~freq = 900;</p>
234 <p class="p6">~freq = { <span class="s1">SinOsc</span>.kr(115, 0, 70, 220) }</p>
235 <p class="p4"><br></p>
236 <p class="p6">~myOut = { <span class="s1">SinOsc</span>.ar(~otherFreq.ar * 2, 0, 0.1) };</p>
237 <p class="p6">~otherFreq = { <span class="s1">SinOsc</span>.ar(115, 0, 70, 220) };</p>
238 <p class="p4"><br></p>
239 <p class="p7"><span class="s4">currentEnvironment.clear; </span>// clear every<span class="Apple-converted-space">  </span>proxy in this environment and remove them. (same: p.clear)</p>
240 <p class="p4"><br></p>
241 <p class="p4"><br></p>
242 <p class="p4"><br></p>
243 <p class="p4"><br></p>
244 <p class="p5">setting the xfade time</p>
245 <p class="p4"><br></p>
246 <p class="p6">~out.play;</p>
247 <p class="p4"><br></p>
248 <p class="p6">~out.fadeTime = 4;</p>
249 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(<span class="s1">Rand</span>(800, 300.0) * [1,1.1], 0, 0.1) };</p>
250 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(<span class="s1">Rand</span>(800, 300.0) * [1,1.1], 0, 0.1) };</p>
251 <p class="p6">~out.fadeTime = 0.01;</p>
252 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(<span class="s1">Rand</span>(800, 300.0) * [1,1.1], 0, 0.1) };</p>
253 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(<span class="s1">Rand</span>(800, 300.0) * [1,1.1], 0, 0.1) };</p>
254 <p class="p4"><br></p>
255 <p class="p7"><span class="s4">~out.free(3);<span class="Apple-converted-space">  </span></span>// release the synths and the group with a given fadeTime without changing proxy time</p>
256 <p class="p7"><span class="s4">~out.stop;<span class="Apple-tab-span"> </span></span>// stop monitor</p>
257 <p class="p4"><br></p>
258 <p class="p4"><br></p>
259 <p class="p4"><br></p>
260 <p class="p5">setting and mapping arguments</p>
261 <p class="p4"><br></p>
262 <p class="p4"><br></p>
263 <p class="p6">~out.play;</p>
264 <p class="p4"><br></p>
265 <p class="p6">~out = { <span class="s1">arg</span> freq=500, ffreq=120; <span class="s1">SinOsc</span>.ar(freq*[1,1.1], <span class="s1">SinOsc</span>.ar(ffreq, 0, pi), 0.2) };</p>
266 <p class="p6">~out.set(<span class="s2">\freq</span>, 400 + 100.rand2);</p>
267 <p class="p6">~out.set(<span class="s2">\freq</span>, 400 + 100.rand2);</p>
268 <p class="p6">~out.set(<span class="s2">\ffreq</span>, 30 + 20.rand2);</p>
269 <p class="p7"><span class="s4">~out.unset(</span><span class="s2">\freq</span><span class="s4">, </span><span class="s2">\ffreq</span><span class="s4">);<span class="Apple-converted-space">  </span></span>// remove the setting</p>
270 <p class="p6">~out.set(<span class="s2">\ffreq</span>, 30 + 10.rand2, <span class="s2">\freq</span>, 500 + 200.rand2);</p>
271 <p class="p4"><br></p>
272 <p class="p4"><br></p>
273 <p class="p7">// argument settings and mappings are applied to every new function</p>
274 <p class="p6">~out = { <span class="s1">arg</span> freq=100, ffreq=20; <span class="s1">SinOsc</span>.ar(freq, <span class="s1">SinOsc</span>.ar(<span class="s1">SinOsc</span>.ar(ffreq)*ffreq, 0, pi), 0.2) };</p>
275 <p class="p4"><br></p>
276 <p class="p7">// mapping to other proxies</p>
277 <p class="p6">~lfo = { <span class="s1">SinOsc</span>.kr(0.3, 0, 80, 100) };</p>
278 <p class="p6">~out.map(<span class="s2">\ffreq</span>, ~lfo);</p>
279 <p class="p4"><br></p>
280 <p class="p6">~out = { <span class="s1">arg</span> freq=300, ffreq=20; <span class="s1">Pulse</span>.ar(freq * [1, 1.1] + <span class="s1">SinOsc</span>.ar(ffreq, 0, freq), 0.3, 0.1) };</p>
281 <p class="p6">~out = { <span class="s1">arg</span> freq=300, ffreq=20; <span class="s1">BPF</span>.ar(<span class="s1">LFSaw</span>.ar(ffreq * [1, 1.1], 0, 1), freq, 0.2) };</p>
282 <p class="p4"><br></p>
283 <p class="p6">~lfo = { <span class="s1">FSinOsc</span>.kr(0.3, 0, 30, 200) + <span class="s1">FSinOsc</span>.kr(10, 0, 10) };</p>
284 <p class="p6">~out = { <span class="s1">arg</span> freq=300, ffreq=20; <span class="s1">SinOsc</span>.ar(freq*[1,1.1], <span class="s1">SinOsc</span>.ar(ffreq, 0, pi), 0.1) };</p>
285 <p class="p4"><br></p>
286 <p class="p4"><br></p>
287 <p class="p7">// crossfaded setting and mapping: fadeTime is used</p>
288 <p class="p6">~out.fadeTime = 2;</p>
289 <p class="p6">~out.xset(<span class="s2">\freq</span>, 9000);</p>
290 <p class="p6">~out.xset(<span class="s2">\freq</span>, rrand(400, 700));</p>
291 <p class="p4"><br></p>
292 <p class="p6">~lfo = { <span class="s1">FSinOsc</span>.kr(0.1, 0, 30, 100) };</p>
293 <p class="p6">~lfo2 = { <span class="s1">LFClipNoise</span>.kr(3, 100, 200) };</p>
294 <p class="p6">~lfo3 = <span class="s1">StreamKrDur</span>(<span class="s1">Pseq</span>([<span class="s1">Prand</span>([530, 600],1), 700, 400, 800, 500].scramble, <span class="s1">inf</span>) / 3, 0.2);</p>
295 <p class="p4"><br></p>
296 <p class="p6">~out.xmap(<span class="s2">\ffreq</span>, ~lfo2);</p>
297 <p class="p6">~out.xmap(<span class="s2">\ffreq</span>, ~lfo);</p>
298 <p class="p6">~out.xmap(<span class="s2">\ffreq</span>, ~lfo3);</p>
299 <p class="p4"><br></p>
300 <p class="p7">// argument rates: just like a synthdef has input 'rates' (like \ir or \tr), a nodeproxy control</p>
301 <p class="p7">// can be given a rate. this rate is used for each function passed into the proxy.</p>
302 <p class="p4"><br></p>
303 <p class="p7">// trigger inputs</p>
304 <p class="p6">~out = { <span class="s1">arg</span> trig, dt=1; <span class="s1">Decay2</span>.kr(trig, 0.01, dt) * <span class="s1">Mix</span>(<span class="s1">SinOsc</span>.ar(7000 * [1.2, 1.3, 0.2])) }</p>
305 <p class="p6">~out.setRates(<span class="s2">\trig</span>, <span class="s2">\tr</span>);</p>
306 <p class="p4"><br></p>
307 <p class="p7">// set the group, so the node proxy does not store the new value</p>
308 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 0.1);<span class="Apple-converted-space"> </span></p>
309 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.4, <span class="s2">\dt</span>, 0.31);</p>
310 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.13, <span class="s2">\dt</span>, 2);</p>
311 <p class="p4"><br></p>
312 <p class="p7">// lagging controls:</p>
313 <p class="p7"><span class="s4">~out.lag(</span><span class="s2">\xfreq</span><span class="s4">, 1); </span>// equivalent to ~out.setRates(\xfreq, 1);</p>
314 <p class="p6">(</p>
315 <p class="p6">~out = { <span class="s1">arg</span> trig, dt=1, xfreq=700;<span class="Apple-converted-space"> </span></p>
316 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Decay2</span>.kr(trig, 0.01, dt) * <span class="s1">Mix</span>(<span class="s1">SinOsc</span>.ar(xfreq * [1.2, 1.3, 0.2]))<span class="Apple-converted-space"> </span></p>
317 <p class="p6">};</p>
318 <p class="p6">)</p>
319 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 1, <span class="s2">\xfreq</span>, rrand(2000,9000));<span class="Apple-converted-space"> </span></p>
320 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 0.5, <span class="s2">\xfreq</span>, rrand(2000,9000));<span class="Apple-converted-space"> </span></p>
321 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 1, <span class="s2">\xfreq</span>, rrand(2000,9000));<span class="Apple-converted-space"> </span></p>
322 <p class="p4"><br></p>
323 <p class="p7">// changing the lag, the synth is reconstructed with the new lag:</p>
324 <p class="p4"><br></p>
325 <p class="p6">~out.lag(<span class="s2">\xfreq</span>, 0.01);</p>
326 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 1, <span class="s2">\xfreq</span>, rrand(2000,9000));<span class="Apple-converted-space"> </span></p>
327 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 1, <span class="s2">\xfreq</span>, rrand(2000,9000));<span class="Apple-converted-space"> </span></p>
328 <p class="p6">~out.group.set(<span class="s2">\trig</span>, 0.1, <span class="s2">\dt</span>, 1, <span class="s2">\xfreq</span>, rrand(2000,9000));<span class="Apple-converted-space"> </span></p>
329 <p class="p4"><br></p>
330 <p class="p7">// removing the trig rate:</p>
331 <p class="p6">~out.setRates(<span class="s2">\trig</span>, <span class="s1">nil</span>);</p>
332 <p class="p4"><br></p>
333 <p class="p7">// note that the same works with the i_ and the t_ arguments, just as it does in SynthDef</p>
334 <p class="p4"><br></p>
335 <p class="p4"><br></p>
336 <p class="p4"><br></p>
337 <p class="p4"><br></p>
338 <p class="p4"><br></p>
339 <p class="p4"><br></p>
340 <p class="p9"><span class="s4"><span class="Apple-converted-space">                          </span></span>_____________________________________________________________________________________________</p>
341 <p class="p10"><br></p>
342 <p class="p10"><br></p>
343 <p class="p10"><br></p>
344 <p class="p11">other possible inputs</p>
345 <p class="p12"><br></p>
346 <p class="p4"><br></p>
347 <p class="p5">using a synthdef as input</p>
348 <p class="p4"><br></p>
349 <p class="p4"><br></p>
350 <p class="p7">// for a more systematic overview see: [jitlib_fading]</p>
351 <p class="p4"><br></p>
352 <p class="p7">// you have the responsibility for the right number of channels and output rate</p>
353 <p class="p7">// you have to supply an 'out' argument so it can be mapped to the right channel.</p>
354 <p class="p4"><br></p>
355 <p class="p6">~out.play;</p>
356 <p class="p6">~out = <span class="s1">SynthDef</span>(<span class="s7">"w"</span>, { <span class="s1">arg</span> out=0; <span class="s1">Out</span>.ar(out,<span class="s1">SinOsc</span>.ar([<span class="s1">Rand</span>(430, 600), 600], 0, 0.2)) });</p>
357 <p class="p6">~out = <span class="s1">SynthDef</span>(<span class="s7">"w"</span>, { <span class="s1">arg</span> out=0; <span class="s1">Out</span>.ar(out,<span class="s1">SinOsc</span>.ar([<span class="s1">Rand</span>(430, 600), 500], 0, 0.2)) });</p>
358 <p class="p4"><br></p>
359 <p class="p4"><br></p>
360 <p class="p7">// if you supply a gate it fades in and out. evaluate this several times</p>
361 <p class="p6">(</p>
362 <p class="p6">~out = <span class="s1">SynthDef</span>(<span class="s7">"w"</span>, { <span class="s1">arg</span> out=0, gate=1.0;<span class="Apple-converted-space"> </span></p>
363 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out,</p>
364 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">SinOsc</span>.ar([<span class="s1">Rand</span>(430, 800), <span class="s1">Rand</span>(430, 800)], 0, 0.2)<span class="Apple-converted-space"> </span></p>
365 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>* <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>.asr(1,1,1), gate, doneAction:2)</p>
366 <p class="p6"><span class="Apple-tab-span"> </span>)<span class="Apple-converted-space"> </span></p>
367 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
368 <p class="p6">)</p>
369 <p class="p4"><br></p>
370 <p class="p7">// once the SynthDef is sent, it can be assigned by name.<span class="Apple-converted-space"> </span></p>
371 <p class="p7">// using this method, a gate argument should be<span class="Apple-converted-space"> </span></p>
372 <p class="p7">// provided that releases the synth. (doneAction:2)</p>
373 <p class="p7">// this is very efficient, as the def is on the server already.</p>
374 <p class="p4"><br></p>
375 <p class="p7">// if the synth def is in the synthdesc lib (.add) its gate is detected.</p>
376 <p class="p4"><br></p>
377 <p class="p6">(</p>
378 <p class="p6"><span class="s1">SynthDef</span>(<span class="s7">"staub"</span>, { <span class="s1">arg</span> out, gate=1;<span class="Apple-converted-space"> </span></p>
379 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out,<span class="Apple-converted-space"> </span></p>
380 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Ringz</span>.ar(<span class="s1">Dust</span>.ar(15), <span class="s1">Rand</span>(1, 3) * 3000*[1,1], 0.001)<span class="Apple-converted-space"> </span></p>
381 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>* <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>.asr, gate, doneAction:2)</p>
382 <p class="p6"><span class="Apple-tab-span"> </span>)<span class="Apple-converted-space"> </span></p>
383 <p class="p6">}).add;</p>
384 <p class="p6">)</p>
385 <p class="p4"><br></p>
386 <p class="p6">~out = <span class="s2">\staub</span>;</p>
387 <p class="p4"><br></p>
388 <p class="p4"><br></p>
389 <p class="p4"><br></p>
390 <p class="p7">// if you supply an envelope that frees itself, no bundle is sent to free it</p>
391 <p class="p6">(</p>
392 <p class="p6">~out = <span class="s1">SynthDef</span>(<span class="s7">"w"</span>, { <span class="s1">arg</span> out, lfo, f0=430;</p>
393 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out,</p>
394 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">SinOsc</span>.ar([<span class="s1">Rand</span>(f0, 800), <span class="s1">Rand</span>(f0, 800)]+lfo, 0, 0.2)<span class="Apple-converted-space"> </span></p>
395 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>* <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>.perc(0.01, 0.03), doneAction:2)</p>
396 <p class="p6"><span class="Apple-tab-span"> </span>)<span class="Apple-converted-space"> </span></p>
397 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
398 <p class="p6">)</p>
399 <p class="p4"><br></p>
400 <p class="p6">~out.spawn;</p>
401 <p class="p6">~out.spawn([<span class="s2">\f0</span>, 5000]);</p>
402 <p class="p6">fork { 5.do { ~out.spawn([<span class="s2">\f0</span>, 5000 + 1000.0.rand]); 0.1.wait; } }</p>
403 <p class="p4"><br></p>
404 <p class="p4"><br></p>
405 <p class="p7">// when the synth description in the SynthDescLib is found for the symbol,</p>
406 <p class="p7">// the proxy can determine whether to release or to free the synth.</p>
407 <p class="p7">// so if there is no 'gate' arg provided and the def has a desc, the synth is</p>
408 <p class="p7">// freed and not released.<span class="Apple-converted-space"> </span></p>
409 <p class="p4"><br></p>
410 <p class="p6">(</p>
411 <p class="p6"><span class="s1">SynthDef</span>(<span class="s7">"staub"</span>, { <span class="s1">arg</span> out;<span class="Apple-converted-space"> </span></p>
412 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out, <span class="s1">Ringz</span>.ar(<span class="s1">WhiteNoise</span>.ar(0.01), 1000 * [1,1], 0.001))<span class="Apple-converted-space"> </span></p>
413 <p class="p7"><span class="s4">}).add; </span>// store the synth def so it is added to the SynthDescLib</p>
414 <p class="p6">)</p>
415 <p class="p4"><br></p>
416 <p class="p4"><br></p>
417 <p class="p6">~out = <span class="s2">\staub</span>;</p>
418 <p class="p7"><span class="s4">~out = </span><span class="s2">\staub</span><span class="s4">; </span>// watching the synth count shows that the old synth is freed.</p>
419 <p class="p7"><span class="s4">~out = 0;<span class="Apple-converted-space">  <span class="Apple-tab-span"> </span></span></span>// now out plays continuous stream of zero.</p>
420 <p class="p7"><span class="s4">~out = </span><span class="s1">nil</span><span class="s4">;<span class="Apple-tab-span"> </span></span>// removes object and stops it.</p>
421 <p class="p8"><br></p>
422 <p class="p5">using patterns</p>
423 <p class="p4"><br></p>
424 <p class="p7">// example</p>
425 <p class="p4"><br></p>
426 <p class="p6">(</p>
427 <p class="p6"><span class="s1">SynthDef</span>(<span class="s2">\who</span>, { <span class="s1">arg</span> amp=0.1, freq=440, detune=0, gate=1, out=0, ffreq=800;</p>
428 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">var</span> env;</p>
429 <p class="p6"><span class="Apple-tab-span"> </span>env = <span class="s1">Env</span>.asr(0.01, amp, 0.5);</p>
430 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out, <span class="s1">Pan2</span>.ar(</p>
431 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Formant</span>.ar(freq + detune, ffreq, 30, <span class="s1">EnvGen</span>.kr(env, gate, doneAction:2)), <span class="s1">Rand</span>(-1.0, 1.0))</p>
432 <p class="p6"><span class="Apple-tab-span"> </span>)</p>
433 <p class="p6">}).add;</p>
434 <p class="p4"><br></p>
435 <p class="p6">)</p>
436 <p class="p4"><br></p>
437 <p class="p6">~out.play;</p>
438 <p class="p4"><br></p>
439 <p class="p4"><br></p>
440 <p class="p6">~out = <span class="s1">Pbind</span>(<span class="s2">\instrument</span>, <span class="s2">\who</span>, <span class="s2">\freq</span>, [600, 601], <span class="s2">\ffreq</span>, 800, <span class="s2">\legato</span>, 0.02);</p>
441 <p class="p4"><br></p>
442 <p class="p4"><br></p>
443 <p class="p4"><br></p>
444 <p class="p4"><br></p>
445 <p class="p7">// embed a control node proxy into an event pattern:</p>
446 <p class="p7">// this does not work for indirect assignment as \degree, \midinote, etc.,<span class="Apple-converted-space"> </span></p>
447 <p class="p7">// because there is calculations in the event! if needed, these can be done in the SynthDef.</p>
448 <p class="p4"><br></p>
449 <p class="p6">~lfo = { <span class="s1">SinOsc</span>.kr(2, 0, 400, 700) };</p>
450 <p class="p6">~out = <span class="s1">Pbind</span>(<span class="s2">\instrument</span>, <span class="s2">\who</span>, <span class="s2">\freq</span>, 500, <span class="s2">\ffreq</span>, ~lfo, <span class="s2">\legato</span>, 0.02);</p>
451 <p class="p4"><br></p>
452 <p class="p6">~lfo = { <span class="s1">SinOsc</span>.kr(<span class="s1">SinOsc</span>.kr(0.2, <span class="s1">Rand</span>(0,pi), 10, 10), 0, 400, 700) };</p>
453 <p class="p4"><br></p>
454 <p class="p6">~lfo = { <span class="s1">LFNoise1</span>.kr(5, 1300, 1500) };</p>
455 <p class="p6">~lfo = { <span class="s1">MouseX</span>.kr(100, 5500, 1) };</p>
456 <p class="p4"><br></p>
457 <p class="p6">(</p>
458 <p class="p6">~out = <span class="s1">Pbind</span>(</p>
459 <p class="p13"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>\instrument<span class="s4">, </span>\who<span class="s4">,</span></p>
460 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\freq</span>, <span class="s1">Pseq</span>([500, 380, 300],<span class="s1">inf</span>),</p>
461 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\legato</span>, 0.1,</p>
462 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\ffreq</span>, <span class="s1">Pseq</span>([~lfo, 100, ~lfo, 100, 300, 550], <span class="s1">inf</span>), <span class="s3">// use it in a pattern</span></p>
463 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\dur</span>, <span class="s1">Pseq</span>([1, 0.5, 0.75, 0.125]*0.4, <span class="s1">inf</span>)</p>
464 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>);</p>
465 <p class="p6">)</p>
466 <p class="p4"><br></p>
467 <p class="p7">// note that when you use a proxy within a non-event pattern it gets embedded as an object,</p>
468 <p class="p7">// so this functionality is still standard</p>
469 <p class="p4"><br></p>
470 <p class="p7">// works only with control rate proxies. multichannel control rate proxies cause</p>
471 <p class="p7">// multichannel expansion of the events:</p>
472 <p class="p4"><br></p>
473 <p class="p6">~lfoStereo = { <span class="s1">LFNoise1</span>.kr([1, 1], 1300, 1500) }; <span class="s3">// 2 channel control rate proxy</span></p>
474 <p class="p6">~out = <span class="s1">Pbind</span>(<span class="s2">\instrument</span>, <span class="s2">\who</span>, <span class="s2">\ffreq</span>, ~lfoStereo, <span class="s2">\legato</span>, 0.02).trace;</p>
475 <p class="p6">~lfoStereo = { [<span class="s1">MouseX</span>.kr(100, 15500, 1), <span class="s1">SinOsc</span>.kr(<span class="s1">SinOsc</span>.kr(0.2, 0, 10, 10), 0, 400, 700)] }</p>
476 <p class="p4"><br></p>
477 <p class="p7">// btw: setting the clock will cause the pattern to sync:</p>
478 <p class="p6">p.clock = <span class="s1">TempoClock</span>.default;</p>
479 <p class="p6">p.clock.tempo = 2.0;</p>
480 <p class="p6">p.clock.tempo = 1.0</p>
481 <p class="p4"><br></p>
482 <p class="p4"><br></p>
483 <p class="p7">// patterns also crossfade, if an \amp arg is defined in the synthdef:</p>
484 <p class="p7">// (evaluate a couple of times)</p>
485 <p class="p6">~out.fadeTime = 3.0;</p>
486 <p class="p6">(</p>
487 <p class="p6">~out = <span class="s1">Pbind</span>(</p>
488 <p class="p13"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>\instrument<span class="s4">, </span>\who<span class="s4">,</span></p>
489 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\freq</span>, <span class="s1">Pshuf</span>([500, 380, 200, 510, 390, 300, 300],<span class="s1">inf</span>) * rrand(1.0, 2.0),</p>
490 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\legato</span>, 0.1,</p>
491 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\ffreq</span>, <span class="s1">Pshuf</span>([~lfo, 100, ~lfo, 100, 300, 550], <span class="s1">inf</span>),</p>
492 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\dur</span>, 0.125 * [1, 2, 3, 2/3].choose</p>
493 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>);</p>
494 <p class="p6">)</p>
495 <p class="p4"><br></p>
496 <p class="p4"><br></p>
497 <p class="p5">using instruments and players</p>
498 <p class="p4"><br></p>
499 <p class="p7">// pause and resume do not work yet.</p>
500 <p class="p4"><br></p>
501 <p class="p4"><br></p>
502 <p class="p7">// store an instrument</p>
503 <p class="p6">(</p>
504 <p class="p14">Instr<span class="s4">(</span><span class="s2">\test</span><span class="s4">,<span class="Apple-converted-space"> </span></span></p>
505 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{ <span class="s1">arg</span> dens=520, ffreq=7000; <span class="s1">Ringz</span>.ar(<span class="s1">Dust</span>.ar(dens, [1,1] * 0.1), ffreq, 0.02) }</p>
506 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>);</p>
507 <p class="p6">)</p>
508 <p class="p4"><br></p>
509 <p class="p6">~out = <span class="s1">Patch</span>(<span class="s2">\test</span>, [10, rrand(5000, 8000)]);</p>
510 <p class="p6">~out.fadeTime = 3;</p>
511 <p class="p4"><br></p>
512 <p class="p4"><br></p>
513 <p class="p6">(</p>
514 <p class="p6">~out = <span class="s1">InstrSpawner</span>({ <span class="s1">arg</span> freq=1900,env,pan;</p>
515 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Pan2</span>.ar(<span class="s1">SinOsc</span>.ar(freq, 0.5pi, 0.3) * <span class="s1">EnvGen</span>.kr(env, doneAction: 2), pan)</p>
516 <p class="p6">},[</p>
517 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Prand</span>([1500, 700, 800, 3000] + 170.rand2, <span class="s1">inf</span>),</p>
518 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Env</span>.perc(0.002,0.01),</p>
519 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Prand</span>([-1,1],<span class="s1">inf</span>)</p>
520 <p class="p6">],0.125)</p>
521 <p class="p6">)</p>
522 <p class="p4"><br></p>
523 <p class="p6">~out.clear;</p>
524 <p class="p4"><br></p>
525 <p class="p4"><br></p>
526 <p class="p4"><br></p>
527 <p class="p7">// does not work (yet).</p>
528 <p class="p7">//~out.set(\dens, 120);</p>
529 <p class="p7">//~out.xset(\dens, 1030);<span class="Apple-converted-space"> </span></p>
530 <p class="p7">//~out.unmap(\ffreq);</p>
531 <p class="p7">//~out.set(\ffreq, 500);</p>
532 <p class="p12"><br></p>
533 <p class="p12"><br></p>
534 <p class="p9"><span class="s4"><span class="Apple-converted-space">                          </span></span>_____________________________________________________________________________________________</p>
535 <p class="p10"><br></p>
536 <p class="p10"><br></p>
537 <p class="p11">client side routines</p>
538 <p class="p12"><br></p>
539 <p class="p5">spawning<span class="Apple-converted-space"> </span></p>
540 <p class="p4"><br></p>
541 <p class="p6">~out.play;</p>
542 <p class="p7"><span class="s4">~out.awake = </span><span class="s1">false</span><span class="s4">; </span>// allow sound object assignment without immediate sending</p>
543 <p class="p4"><br></p>
544 <p class="p7">// putting an synthdef into the node proxy without playing it right away</p>
545 <p class="p7">// the synthdef has an envelope that frees by itself.</p>
546 <p class="p6">(</p>
547 <p class="p6">~out = <span class="s1">SynthDef</span>(<span class="s7">"a"</span>, { <span class="s1">arg</span> out=0, freq=800, pmf=1.0, pan;</p>
548 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">var</span> env, u;</p>
549 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>env = <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>.perc(0.001, 0.04, 0.4),doneAction:2); <span class="s3">// envelope</span></p>
550 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>u = <span class="s1">SinOsc</span>.ar(freq * <span class="s1">Rand</span>(0.9, 1.1), <span class="s1">SinOsc</span>.ar(pmf, 0, pi), env);</p>
551 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out, <span class="s1">Pan2</span>.ar(u, pan))</p>
552 <p class="p6"><span class="Apple-tab-span"> </span>})</p>
553 <p class="p6">);</p>
554 <p class="p4"><br></p>
555 <p class="p4"><br></p>
556 <p class="p7">// create a task to repeatedly send grains</p>
557 <p class="p6">(</p>
558 <p class="p6">t = <span class="s1">Task</span>.new({</p>
559 <p class="p6"><span class="Apple-tab-span"> </span>loop({</p>
560 <p class="p7"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// starts a synth with the current synthdef at index 0</p>
561 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>~out.spawn([<span class="s2">\pmf</span>, [1, 20, 300].choose, <span class="s2">\pan</span>, [0, -1, 1].choose]);<span class="Apple-converted-space"> </span></p>
562 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[0.1, 0.01, 0.25].choose.wait;</p>
563 <p class="p6"><span class="Apple-tab-span"> </span>})</p>
564 <p class="p6">});</p>
565 <p class="p6">)</p>
566 <p class="p4"><br></p>
567 <p class="p6">t.start;</p>
568 <p class="p6">t.stop;</p>
569 <p class="p6">t.start;</p>
570 <p class="p4"><br></p>
571 <p class="p7">// note: if you want to avoid using interpreter variables (single letter, like "t"),</p>
572 <p class="p7">// you can use Tdef for this. (see Tdef.help)</p>
573 <p class="p4"><br></p>
574 <p class="p7">// set some argument</p>
575 <p class="p6">~out.set(<span class="s2">\freq</span>, 300);</p>
576 <p class="p6">~out.set(<span class="s2">\freq</span>, 600);</p>
577 <p class="p6">~out.map(<span class="s2">\freq</span>, ~lfo);</p>
578 <p class="p6">~lfo = { <span class="s1">SinOsc</span>.kr(0.1, 0, 3000, 4000) };</p>
579 <p class="p6">~lfo = { <span class="s1">SinOsc</span>.kr(0.1, 0, 600, 700) };</p>
580 <p class="p6">~lfo.add({ <span class="s1">Trig</span>.kr(<span class="s1">Dust</span>.kr(1), 0.1) * 3000 });</p>
581 <p class="p6">~lfo = 300;</p>
582 <p class="p4"><br></p>
583 <p class="p7">// change the definition while going along</p>
584 <p class="p6">(</p>
585 <p class="p6">~out = <span class="s1">SynthDef</span>(<span class="s7">"a"</span>, { <span class="s1">arg</span> out, freq=800;</p>
586 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">var</span> env;</p>
587 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>env = <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>.perc(0.01, 0.1, 0.3),doneAction:2);</p>
588 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out, <span class="s1">Pulse</span>.ar(freq * <span class="s1">Rand</span>([0.9,0.9], 1.1), 0.5, env) )</p>
589 <p class="p6"><span class="Apple-tab-span"> </span>});</p>
590 <p class="p6">)</p>
591 <p class="p4"><br></p>
592 <p class="p4"><br></p>
593 <p class="p6">t.stop;</p>
594 <p class="p7"><span class="s4">~out.awake = </span><span class="s1">true</span><span class="s4">; </span>// don't forget this</p>
595 <p class="p7">//<span class="Apple-converted-space">  </span>free all synths in this current ProxySpace</p>
596 <p class="p6">currentEnvironment.clear;</p>
597 <p class="p12"><br></p>
598 <p class="p12"><br></p>
599 <p class="p12"><br></p>
600 <p class="p12"><br></p>
601 <p class="p9"><span class="s4"><span class="Apple-converted-space">                          </span></span>_____________________________________________________________________________________________</p>
602 <p class="p12"><br></p>
603 <p class="p12"><br></p>
604 <p class="p12"><br></p>
605 <p class="p5">granular synthesis: efficient code</p>
606 <p class="p4"><br></p>
607 <p class="p15">see also [jitlib_efficiency]</p>
608 <p class="p4"><br></p>
609 <p class="p6">~out.play;</p>
610 <p class="p12"><br></p>
611 <p class="p6">(</p>
612 <p class="p6"><span class="s1">SynthDef</span>(<span class="s7">"grain"</span>, { <span class="s1">arg</span> i_out = 0, pan;</p>
613 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">var</span> env;</p>
614 <p class="p6"><span class="Apple-tab-span"> </span>env = <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>.perc(0.001, 0.003, 0.2),doneAction:2);</p>
615 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(i_out, <span class="s1">Pan2</span>.ar(<span class="s1">FSinOsc</span>.ar(<span class="s1">Rand</span>(1000,10000)), pan) * env)<span class="Apple-converted-space"> </span></p>
616 <p class="p6">}).send(s);</p>
617 <p class="p6">)</p>
618 <p class="p4"><br></p>
619 <p class="p7">// a target for the grains</p>
620 <p class="p7"><span class="s4">~someInput.ar(2);<span class="Apple-converted-space">  </span></span>// initialize to 2 channels audio</p>
621 <p class="p6">~out = ~someInput;</p>
622 <p class="p4"><br></p>
623 <p class="p6">(</p>
624 <p class="p6">t = <span class="s1">Task</span>({</p>
625 <p class="p6"><span class="Apple-tab-span"> </span>loop({</p>
626 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.sendMsg(<span class="s7">"/s_new"</span>,<span class="s7">"grain"</span>,-1,0,0,<span class="Apple-converted-space"> </span></p>
627 <p class="p7"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">\i_out</span><span class="s4">, ~someInput.index, </span>// returns the bus index of the proxy</p>
628 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">\pan</span>, [1, 1, -1].choose * 0.2</p>
629 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>); <span class="Apple-converted-space"> </span></p>
630 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[0.01, 0.02].choose.wait;</p>
631 <p class="p6"><span class="Apple-tab-span"> </span>})</p>
632 <p class="p6">});</p>
633 <p class="p6">)</p>
634 <p class="p6">t.play;</p>
635 <p class="p4"><br></p>
636 <p class="p7">// different filters;</p>
637 <p class="p4"><br></p>
638 <p class="p6">~out.fadeTime = 1.0;</p>
639 <p class="p4"><br></p>
640 <p class="p6">~out = { <span class="s1">BPF</span>.ar(~someInput.ar, <span class="s1">MouseX</span>.kr(100, 18000, 1), 0.1) };</p>
641 <p class="p4"><br></p>
642 <p class="p6">~out = { <span class="s1">CombL</span>.ar(~someInput.ar * (<span class="s1">LFNoise0</span>.ar(2) &gt; 0), 0.2, 0.2, <span class="s1">MouseX</span>.kr(0.1, 5, 1)) };</p>
643 <p class="p4"><br></p>
644 <p class="p6">~out = { <span class="s1">RLPF</span>.ar(~someInput.ar, <span class="s1">LFNoise1</span>.kr(3, 1000, 1040), 0.05) };</p>
645 <p class="p4"><br></p>
646 <p class="p4"><br></p>
647 <p class="p6">t.stop;</p>
648 <p class="p4"><br></p>
649 <p class="p4"><br></p>
650 <p class="p4"><br></p>
651 <p class="p7">// end</p>
652 <p class="p4"><br></p>
653 <p class="p6">~out.stop;</p>
654 <p class="p6">currentEnvironment.clear;</p>
655 <p class="p7"><span class="s1">ProxySpace</span><span class="s4">.pop; </span>// restore original environment</p>
656 <p class="p12"><br></p>
657 <p class="p12"><br></p>
658 <p class="p12"><br></p>
659 <p class="p9"><span class="s4"><span class="Apple-converted-space">                          </span></span>_____________________________________________________________________________________________</p>
660 <p class="p12"><br></p>
661 <p class="p12"><br></p>
662 <p class="p12"><br></p>
663 <p class="p5">using multiple proxyspaces</p>
664 <p class="p5">can be done while the server is not running: with p.wakeUp or p.play</p>
665 <p class="p5">the environment can be played back.</p>
666 <p class="p12"><br></p>
667 <p class="p7">// quit server:</p>
668 <p class="p4"><br></p>
669 <p class="p6">s.quit;</p>
670 <p class="p4"><br></p>
671 <p class="p4"><br></p>
672 <p class="p7">// create two proxyspaces without a running server</p>
673 <p class="p6">(</p>
674 <p class="p14"><span class="s4">p = </span>ProxySpace<span class="s4">(s);</span></p>
675 <p class="p14"><span class="s4">q = </span>ProxySpace<span class="s4">(s);</span></p>
676 <p class="p4"><br></p>
677 <p class="p6">p.use({</p>
678 <p class="p6"><span class="Apple-tab-span"> </span>~out = { <span class="s1">Resonz</span>.ar(~in.ar, ~freq.kr, 0.01) };</p>
679 <p class="p6"><span class="Apple-tab-span"> </span>~in = { <span class="s1">WhiteNoise</span>.ar(0.5) };</p>
680 <p class="p6"><span class="Apple-tab-span"> </span>~freq = { <span class="s1">LFNoise2</span>.kr(1, 1000, 2000) };</p>
681 <p class="p6">});</p>
682 <p class="p4"><br></p>
683 <p class="p6">q.use({</p>
684 <p class="p4"><span class="Apple-tab-span"> </span></p>
685 <p class="p6"><span class="Apple-tab-span"> </span>~in = { <span class="s1">Dust</span>.ar(20, 0.1) };</p>
686 <p class="p6"><span class="Apple-tab-span"> </span>~out = { <span class="s1">Resonz</span>.ar(~in.ar * 450, ~freq.kr, 0.005) };</p>
687 <p class="p6"><span class="Apple-tab-span"> </span>~freq = { <span class="s1">LFNoise2</span>.kr(1, 400, 2000) };</p>
688 <p class="p6">});</p>
689 <p class="p6">)</p>
690 <p class="p4"><br></p>
691 <p class="p7">// wait for the booted<span class="Apple-converted-space">  </span>server</p>
692 <p class="p6">s.boot;</p>
693 <p class="p4"><br></p>
694 <p class="p7">// play the proxy at \out</p>
695 <p class="p6">p.play(<span class="s2">\out</span>);<span class="Apple-converted-space"> </span></p>
696 <p class="p7"><span class="s4">q.play; </span>// out is the default output</p>
697 <p class="p4"><br></p>
698 <p class="p4"><br></p>
699 <p class="p5">external access</p>
700 <p class="p4"><br></p>
701 <p class="p4"><br></p>
702 <p class="p6">q[<span class="s2">\in</span>][1] = { <span class="s1">Impulse</span>.ar(2, 0, 0.5) }; <span class="s3">// adding a synth at index 1</span></p>
703 <p class="p4"><br></p>
704 <p class="p7">// equivalent to</p>
705 <p class="p6">q.at(<span class="s2">\in</span>).put(1, { <span class="s1">Impulse</span>.ar(7, 0, 0.5) });</p>
706 <p class="p8"><br></p>
707 <p class="p4"><br></p>
708 <p class="p5">connecting two spaces (must be on one server)</p>
709 <p class="p4"><br></p>
710 <p class="p4"><br></p>
711 <p class="p6">(</p>
712 <p class="p6">q.use({</p>
713 <p class="p6"><span class="Apple-tab-span"> </span>~freq =<span class="Apple-converted-space">  </span>100 + p[<span class="s2">\freq</span>] / 2;</p>
714 <p class="p6">})</p>
715 <p class="p6">)</p>
716 <p class="p4"><br></p>
717 <p class="p5">recording output (see also: [<a href="../nodeproxy/RecNodeProxy.html"><span class="s1">RecNodeProxy</span></a>])</p>
718 <p class="p4"><br></p>
719 <p class="p4"><br></p>
720 <p class="p6">r = p.record(<span class="s2">\out</span>, <span class="s7">"proxySpace.aiff"</span>);</p>
721 <p class="p4"><br></p>
722 <p class="p7">// start recording</p>
723 <p class="p6">r.unpause;</p>
724 <p class="p4"><br></p>
725 <p class="p7">// pause recording</p>
726 <p class="p6">r.pause;</p>
727 <p class="p4"><br></p>
728 <p class="p7">// stop recording</p>
729 <p class="p6">r.close;</p>
730 <p class="p4"><br></p>
731 <p class="p4"><br></p>
732 <p class="p4"><br></p>
733 <p class="p4"><br></p>
734 <p class="p4"><br></p>
735 <p class="p5">push/pop</p>
736 <p class="p4"><br></p>
737 <p class="p4"><br></p>
738 <p class="p7">// make p the currentEnvironment</p>
739 <p class="p6">p.push;<span class="Apple-converted-space"> </span></p>
740 <p class="p4"><br></p>
741 <p class="p6">~freq = 700;</p>
742 <p class="p6">~freq = 400;</p>
743 <p class="p6">~freq = { p.kr(<span class="s2">\freq</span>) + <span class="s1">LFNoise1</span>.kr(1, 200, 300) % 400 }; <span class="s3">// feedback</span></p>
744 <p class="p6">~freq = 400;</p>
745 <p class="p4"><br></p>
746 <p class="p7"><span class="s4">p.pop; </span>// restore environment</p>
747 <p class="p4"><br></p>
748 <p class="p4"><br></p>
749 <p class="p7">// make y the currentEnvironment</p>
750 <p class="p6">q.push;<span class="Apple-converted-space"> </span></p>
751 <p class="p4"><br></p>
752 <p class="p6">~freq = 1000;</p>
753 <p class="p6">~in = { <span class="s1">WhiteNoise</span>.ar(0.01) };</p>
754 <p class="p4"><br></p>
755 <p class="p7"><span class="s4">q.pop; </span>// restore environment</p>
756 <p class="p4"><br></p>
757 <p class="p6">q.clear;</p>
758 <p class="p6">p.clear;</p>
759 <p class="p4"><br></p>
760 <p class="p4"><br></p>
761 <p class="p4"><br></p>
762 <p class="p4"><br></p>
763 <p class="p4"><br></p>
764 <p class="p9"><span class="s4"><span class="Apple-converted-space">                          </span></span>_____________________________________________________________________________________________</p>
765 <p class="p4"><br></p>
766 <p class="p4"><br></p>
767 <p class="p4"><br></p>
768 <p class="p5">some more topics</p>
769 <p class="p4"><br></p>
770 <p class="p5">nodeproxy with numbers as input:</p>
771 <p class="p4"><br></p>
772 <p class="p6">p = <span class="s1">ProxySpace</span>.push(s.boot);</p>
773 <p class="p4"><br></p>
774 <p class="p4"><br></p>
775 <p class="p6">~out = { <span class="s1">SinOsc</span>.ar(~a.kr * <span class="s1">Rand</span>(1, 2), 0, 0.1) };</p>
776 <p class="p6">~out.play;</p>
777 <p class="p4"><br></p>
778 <p class="p6">~a = 900;</p>
779 <p class="p4"><br></p>
780 <p class="p7">// these add up:</p>
781 <p class="p6">~a[0] = 440;</p>
782 <p class="p6">~a[1] = 220;</p>
783 <p class="p6">~a[2] = 20;</p>
784 <p class="p4"><br></p>
785 <p class="p6">~a.fadeTime = 2;</p>
786 <p class="p4"><br></p>
787 <p class="p7"><span class="s4">~a[0] = 300; </span>// now there is a crossfade.</p>
788 <p class="p6">~a[1] = { <span class="s1">SinOsc</span>.kr(5, 0, 20) };<span class="Apple-converted-space"> </span></p>
789 <p class="p6">~a[2] = { <span class="s1">SinOsc</span>.kr(30, 0, 145) };</p>
790 <p class="p4"><br></p>
791 <p class="p4"><br></p>
792 <p class="p4"><br></p>
793 <p class="p7">// internally a numerical input is approximately replaced by:</p>
794 <p class="p7">// (pseudocode)</p>
795 <p class="p6"><span class="s1">SynthDef</span>(<span class="s7">"name"</span>, { <span class="s1">arg</span> out, fadeTime;</p>
796 <p class="p6"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.kr(out,</p>
797 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Control</span>.kr(<span class="s1">Array</span>.fill(proxy.numChannels, { the number }))<span class="Apple-converted-space"> </span></p>
798 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>* <span class="s1">EnvGate</span>.new(fadeTime:fadeTime)</p>
799 <p class="p6"><span class="Apple-tab-span"> </span>)<span class="Apple-converted-space"> </span></p>
800 <p class="p6">});</p>
801 <p class="p4"><br></p>
802 <p class="p4"><br></p>
803 <p class="p4"><br></p>
804 <p class="p4"><br></p>
805 <p class="p4"><br></p>
806 </body>
807 </html>