polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Libraries / JITLib / tutorials / jitlib_basic_concepts_02.html
blobd825f240ebd772f1229e25ac80d4c32e73cb0d85
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="949.43">
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: 9.0px Monaco; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0018ea}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #852a1a}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #852a1a; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
21 span.s1 {font: 36.0px Georgia}
22 span.s2 {color: #000000}
23 span.s3 {text-decoration: underline}
24 span.s4 {color: #852a1a}
25 span.s5 {color: #4f6923}
26 span.s6 {color: #0e34af}
27 span.s7 {color: #002df4}
28 span.s8 {color: #0d3ef4}
29 span.s9 {font: 9.0px Monaco; color: #000000}
30 span.s10 {text-decoration: underline ; color: #0c3ae3}
31 span.s11 {color: #007300}
32 span.s12 {color: #0000bf}
33 span.Apple-tab-span {white-space:pre}
34 </style>
35 </head>
36 <body>
37 <p class="p1"><b>proxy space - basic concepts<span class="Apple-converted-space">  <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span></b><span class="s1"><b>2</b></span></p>
38 <p class="p2"><br></p>
39 <p class="p2"><br></p>
40 <p class="p3">external structure of the node proxy, referencing in proxyspace and environments.</p>
41 <p class="p4"><br></p>
42 <p class="p5"><span class="s2">previous: <a href="jitlib_basic_concepts_01.html"><span class="s3">jitlib_basic_concepts_01</span></a><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>next: <a href="jitlib_basic_concepts_03.html"><span class="s3">jitlib_basic_concepts_03</span></a><span class="Apple-converted-space"> </span></span></p>
43 <p class="p4"><br></p>
44 <p class="p2"><br></p>
45 <p class="p3">This document covers:</p>
46 <p class="p4"><br></p>
47 <p class="p3">a) <span class="Apple-tab-span"> </span>normal environment lookup</p>
48 <p class="p3">b) <span class="Apple-tab-span"> </span>proxyspace as an environment</p>
49 <p class="p3">c) <span class="Apple-tab-span"> </span>using the proxyspace to change processes on the fly</p>
50 <p class="p3">d) <span class="Apple-tab-span"> </span>when are the node proxies initialized?</p>
51 <p class="p3">e) <span class="Apple-tab-span"> </span>moving out of the proxy space</p>
52 <p class="p3">f ) <span class="Apple-tab-span"> </span>using ProxySpace together with other Environments</p>
53 <p class="p2"><br></p>
54 <p class="p2"><br></p>
55 <p class="p2"><br></p>
56 <p class="p2"><br></p>
57 <p class="p2"><br></p>
58 <p class="p3"><b>a) normal environment lookup</b></p>
59 <p class="p2"><br></p>
60 <p class="p2"><br></p>
61 <p class="p2"><br></p>
62 <p class="p6"><span class="s2">currentEnvironment.postln; </span>// anEnvironment (if not, you haven't left it from last helppage..)</p>
63 <p class="p2"><br></p>
64 <p class="p6"><span class="s2">~a; </span>// access the environment: there is nothing stored: nil</p>
65 <p class="p6"><span class="s2">~a = 9; </span>// store something</p>
66 <p class="p6"><span class="s2">~a; <span class="Apple-tab-span"> </span></span>// now 9 is stored</p>
67 <p class="p6"><span class="s2">~a + 100; </span>// calculate with it</p>
68 <p class="p2"><br></p>
69 <p class="p6"><span class="s2">currentEnvironment.postln; </span>// the value is stored in the environment</p>
70 <p class="p2"><br></p>
71 <p class="p6"><span class="s2">~b + ~a; </span>// cause an error: ~b is nil.</p>
72 <p class="p7">~b = -90; <span class="s4">// set ~b</span></p>
73 <p class="p2"><br></p>
74 <p class="p6"><span class="s2">~b + ~a; </span>// now this works.</p>
75 <p class="p2"><br></p>
76 <p class="p6">// note that you can always access environments (or ProxySpaces) from outside as well:</p>
77 <p class="p2"><br></p>
78 <p class="p7">x = currentEnvironment;</p>
79 <p class="p6"><span class="s2">x[</span><span class="s5">\a</span><span class="s2">] + x[</span><span class="s5">\b</span><span class="s2">] </span>// equivalent to ~b + ~a</p>
80 <p class="p8"><br></p>
81 <p class="p6">// or, if "know" is true, you can access named things with message-like syntax:</p>
82 <p class="p7">x.know = <span class="s6">true</span>;</p>
83 <p class="p7">x.a + x.b;</p>
84 <p class="p2"><br></p>
85 <p class="p2"><br></p>
86 <p class="p2"><br></p>
87 <p class="p2"><br></p>
88 <p class="p2"><br></p>
89 <p class="p7"><span class="Apple-tab-span"> </span>further readings: <a href="../../../Collections/Environment.html"><span class="s7">Environment</span></a></p>
90 <p class="p2"><br></p>
91 <p class="p2"><br></p>
92 <p class="p2"><br></p>
93 <p class="p2"><br></p>
94 <p class="p2"><br></p>
95 <p class="p3"><b>b) a proxyspace as an environment</b></p>
96 <p class="p2"><br></p>
97 <p class="p2"><br></p>
98 <p class="p3">one can replace the current environment with a special type of environment, a ProxySpace.</p>
99 <p class="p3">this environment represents processes that play audio on a server.</p>
100 <p class="p2"><br></p>
101 <p class="p2"><br></p>
102 <p class="p6"><span class="s2">p = </span><span class="s6">ProxySpace</span><span class="s2">.new(s); </span>// create a new environment, store it in variable p for now.</p>
103 <p class="p6"><span class="s2">p.push;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// push it, so i becomes the current environment.</p>
104 <p class="p7">currentEnvironment.postln;<span class="Apple-converted-space"> </span></p>
105 <p class="p7">currentEnvironment === p; <span class="s4">// and they are identical.</span></p>
106 <p class="p2"><br></p>
107 <p class="p6"><span class="s2">~x;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// accessing creates a NodeProxy (uninitialized) automatically.</p>
108 <p class="p6"><span class="s2">~x + ~y; <span class="Apple-tab-span"> </span></span>// this works immediately, because the lookup does not return nil,<span class="Apple-converted-space"> </span></p>
109 <p class="p6"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-converted-space">    </span></span>// but a placeholder (proxy) instead</p>
110 <p class="p2"><br></p>
111 <p class="p6"><span class="s2">p.postln; </span>// now there are two empty placeholders in the environment.</p>
112 <p class="p2"><br></p>
113 <p class="p2"><br></p>
114 <p class="p2"><br></p>
115 <p class="p2"><br></p>
116 <p class="p2"><br></p>
117 <p class="p2"><br></p>
118 <p class="p3"><b>c) using the proxyspace to change processes on the fly</b></p>
119 <p class="p2"><br></p>
120 <p class="p2"><br></p>
121 <p class="p6">//<span class="Apple-converted-space">  </span>boot the server</p>
122 <p class="p7">s.boot;</p>
123 <p class="p2"><br></p>
124 <p class="p2"><br></p>
125 <p class="p6">// as soon as a sound function (or any compatible input) is assigned to a proxy</p>
126 <p class="p6">// this sound plays on its own private bus (so it is not audible yet.)</p>
127 <p class="p7">(</p>
128 <p class="p7">~x = {</p>
129 <p class="p2"><span class="Apple-tab-span"> </span></p>
130 <p class="p7"><span class="Apple-tab-span"> </span><span class="s6">RLPF</span>.ar(<span class="s6">Impulse</span>.ar(4) * 20, [850, 950], 0.2)</p>
131 <p class="p2"><span class="Apple-tab-span"> </span></p>
132 <p class="p7">}</p>
133 <p class="p7">)</p>
134 <p class="p2"><br></p>
135 <p class="p6">// the proxy has been initialized by its first assignment.</p>
136 <p class="p6">// it plays at audio rate (because we have assigned an audio rate ugen function)</p>
137 <p class="p6">// and it has two channels (because the function has stereo output)</p>
138 <p class="p2"><br></p>
139 <p class="p6"><span class="s2">~x.index; </span>// a nodeproxy owns a private bus, so its signal can be used in diverse ways.<span class="Apple-converted-space"> </span></p>
140 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// what is the proxy bus's index? this posts the index to the postwindow<span class="Apple-converted-space"> </span></p>
141 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// before it was .ir(nil), now it is initialized to .ar(2)</p>
142 <p class="p2"><br></p>
143 <p class="p6"><span class="s2">~x.bus </span>// what is the proxy's bus?</p>
144 <p class="p2"><br></p>
145 <p class="p2"><br></p>
146 <p class="p6"><span class="s2">~x.play; </span>// now listen to it. a monitor is created (see <a href="../nodeproxy/Monitor.html"><span class="s8">Monitor</span></a>) that plays the signal</p>
147 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// onto a public bus - by default, this is bus 0, the first audio output bus.</p>
148 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// This monitoring function is independent of the proxy itself.</p>
149 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// for further info see: <a href="jitlib_basic_concepts_03.html"><span class="s8">jitlib_basic_concepts_03</span></a> (part c)</p>
150 <p class="p8"><br></p>
151 <p class="p2"><br></p>
152 <p class="p2"><br></p>
153 <p class="p6">// the sound function can be changed at any time:</p>
154 <p class="p7">(</p>
155 <p class="p7">~x = {</p>
156 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">RLPF</span>.ar(<span class="s6">Impulse</span>.ar([5, 7]) * 5, [1450, 1234], 0.2)</p>
157 <p class="p7">}</p>
158 <p class="p7">)</p>
159 <p class="p2"><br></p>
160 <p class="p6">// You can tune a sound function to your liking very easily</p>
161 <p class="p6">// by replacing it with little (or big) variations:</p>
162 <p class="p2"><br></p>
163 <p class="p6"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// filter freqs higher:</p>
164 <p class="p7">~x = {<span class="Apple-tab-span"> </span><span class="s6">RLPF</span>.ar(<span class="s6">Impulse</span>.ar([5, 7]) * 5, [1800, 2000], 0.2) }</p>
165 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
166 <p class="p6"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// same pulse ratio (5/8), different pulse tempo:</p>
167 <p class="p7">~x = {<span class="Apple-tab-span"> </span><span class="s6">RLPF</span>.ar(<span class="s6">Impulse</span>.ar([5, 8] * 3.2) * 5, [1800, 2000], 0.2) }</p>
168 <p class="p2"><br></p>
169 <p class="p6"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// different filter:</p>
170 <p class="p7">~x = {<span class="Apple-tab-span"> </span><span class="s6">Ringz</span>.ar(<span class="s6">Impulse</span>.ar([5, 8] * 3.2), [1800, 2000], 0.05) }</p>
171 <p class="p2"><br></p>
172 <p class="p6">// and if you set the proxy's fadeTime, you can create little<span class="Apple-converted-space"> </span></p>
173 <p class="p6">// textures by hand:<span class="Apple-converted-space"> </span></p>
174 <p class="p2"><br></p>
175 <p class="p7">~x.fadeTime = 3;<span class="Apple-converted-space"> </span></p>
176 <p class="p6"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// different filter freqs every time:</p>
177 <p class="p7">~x = {<span class="Apple-tab-span"> </span><span class="s6">Ringz</span>.ar(<span class="s6">Impulse</span>.ar([5, 8] * rrand(0.5, 1.5)) * 0.5, ({ exprand(200, 4000) } ! 2), 0.05) }</p>
178 <p class="p2"><br></p>
179 <p class="p2"><br></p>
180 <p class="p2"><br></p>
181 <p class="p6">// here is another proxy:</p>
182 <p class="p7">~y = { <span class="s6">Pan2</span>.ar(<span class="s6">Dust</span>.ar(20), 0) };</p>
183 <p class="p2"><br></p>
184 <p class="p6"><span class="s2">~y.bus; </span>// it has two channels, just as the ~x., but it plays on another (private) bus.</p>
185 <p class="p2"><br></p>
186 <p class="p6">// note that ~y is not audible directly,</p>
187 <p class="p6">// but it can be used like a UGen in any other proxy:</p>
188 <p class="p7">(</p>
189 <p class="p7">~x = {</p>
190 <p class="p2"><span class="Apple-tab-span"> </span></p>
191 <p class="p7"><span class="Apple-tab-span"> </span><span class="s6">RLPF</span>.ar(~y.ar * 8,<span class="Apple-converted-space">  </span>[1450, 1234], 0.2)</p>
192 <p class="p7">}</p>
193 <p class="p7">)</p>
194 <p class="p2"><br></p>
195 <p class="p6">// when the proxy changes, the result changes dynamically:</p>
196 <p class="p2"><br></p>
197 <p class="p7">~y = { <span class="s6">Impulse</span>.ar(<span class="s6">MouseX</span>.kr(2, 18, 1)) * [1, 1] };</p>
198 <p class="p2"><br></p>
199 <p class="p7">~y = { <span class="s6">PinkNoise</span>.ar(<span class="s6">MouseX</span>.kr(0, 0.2) * [1, 1]) };</p>
200 <p class="p2"><br></p>
201 <p class="p7">~y = { <span class="s6">Impulse</span>.ar([<span class="s6">MouseX</span>.kr(2, 18, 1), <span class="s6">MouseY</span>.kr(2, 18, 1)]) };</p>
202 <p class="p2"><br></p>
203 <p class="p2"><br></p>
204 <p class="p2"><br></p>
205 <p class="p6">// stop listening. the proxies run in the background.</p>
206 <p class="p2"><br></p>
207 <p class="p7">~x.stop;</p>
208 <p class="p2"><br></p>
209 <p class="p6"><span class="s2">~y.bus; </span>// ~y is playing on a different bus ...</p>
210 <p class="p6"><span class="s2">~x.bus; </span>// than ~x.</p>
211 <p class="p2"><br></p>
212 <p class="p6">// we can also listen to ~y directly:</p>
213 <p class="p7">~y.play;</p>
214 <p class="p2"><br></p>
215 <p class="p6">// to remove a proxy source, nil can be used:</p>
216 <p class="p2"><br></p>
217 <p class="p7">~y = <span class="s6">nil</span>;</p>
218 <p class="p2"><br></p>
219 <p class="p6">// stop listening</p>
220 <p class="p7">~y.stop;</p>
221 <p class="p2"><br></p>
222 <p class="p2"><br></p>
223 <p class="p5"><span class="s9"><span class="Apple-tab-span"> </span></span><span class="s2">further readings: <a href="proxyspace_examples.html"><span class="s10">proxyspace_examples</span></a> <a href="../../../ServerArchitecture/Bus.html"><span class="s3">Bus</span></a> <a href="../../../Core/Kernel/AbstractFunction.html"><span class="s3">AbstractFunction</span></a> <a href="../../../UGens/UGens.html"><span class="s3">UGens</span></a></span></p>
224 <p class="p2"><br></p>
225 <p class="p2"><br></p>
226 <p class="p2"><br></p>
227 <p class="p2"><br></p>
228 <p class="p2"><br></p>
229 <p class="p3"><b>d) when are the node proxies initialized?</b></p>
230 <p class="p2"><br></p>
231 <p class="p3">bus initialization of a node proxy happens as soon as it is used for the first time.</p>
232 <p class="p3">later inputs are adjusted to this bus, as far as it is possible.</p>
233 <p class="p2"><br></p>
234 <p class="p2"><br></p>
235 <p class="p7">~z2 = { <span class="s6">LFNoise0</span>.kr([1, 2, 3, 4]) }; // a four channel control rate proxy</p>
236 <p class="p7">~z2.bus.postln;</p>
237 <p class="p2"><br></p>
238 <p class="p7">~z100 = 0.5; // a constant value creates a single channel control rate proxy.</p>
239 <p class="p7">~z100.bus.postln;</p>
240 <p class="p2"><br></p>
241 <p class="p7">~z34.ar(3) <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// the first access (with a numChannels argument) allocates the bus</p>
242 <p class="p7">~z34.bus.postln;<span class="Apple-tab-span"> </span>// a 3 channel audio proxy</p>
243 <p class="p2"><br></p>
244 <p class="p6">// these initializations can be removed by using clear:</p>
245 <p class="p7">~z34.clear;</p>
246 <p class="p7">~z34.bus.postln;</p>
247 <p class="p2"><br></p>
248 <p class="p3">This initialisation happens whenever the proxy is first used. Later, the proxy can</p>
249 <p class="p3">be accessed with other rate/numChannels combinations as needed (rates are converted,</p>
250 <p class="p3">numChannels are extended by wrapping, sources with too many channels are wrapped).</p>
251 <p class="p4"><br></p>
252 <p class="p3">Note that this might cause ambiguous initialisation in which case the proxy should</p>
253 <p class="p3">be always initialized first. A typical problem is demonstrated here:</p>
254 <p class="p2"><br></p>
255 <p class="p7">~u.play(0, 2); <span class="Apple-tab-span"> </span>// initialize 2 audio channels (default). 0 is the output bus number.</p>
256 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// if the proxy is not inititialized, play defaults to 2 channels.</p>
257 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// here it is explicitly given only to make it more clear.</p>
258 <p class="p7">~u = { <span class="s6">PinkNoise</span>.ar(0.2) }; <span class="s4">// use only one</span></p>
259 <p class="p7">~u.numChannels; <span class="s4">// 2 channels</span></p>
260 <p class="p7">~u.clear;</p>
261 <p class="p2"><br></p>
262 <p class="p3">if evaluated the other way round, only one channel is used:</p>
263 <p class="p2"><br></p>
264 <p class="p7">~u = { <span class="s6">PinkNoise</span>.ar(0.2) }; // initialize 1 audio channel</p>
265 <p class="p7">~u.play(0, 2); <span class="Apple-tab-span"> </span>// play 2 channels: the 1 channel is expanded into 2.</p>
266 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// numChannels of .play defaults to the proxy's numChannels.</p>
267 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// here it is explicitly given, so to expand the channels</p>
268 <p class="p7">~u.numChannels; <span class="s4">// 1 channel</span></p>
269 <p class="p7">~u.clear;</p>
270 <p class="p8"><br></p>
271 <p class="p3">Thus it can be useful to explicitly initialize proxies that use variable type inputs:</p>
272 <p class="p8"><br></p>
273 <p class="p7">~b.kr(8); ~c.ar; // explicit initialisation</p>
274 <p class="p7">p.postln;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// post the whole proxy space</p>
275 <p class="p2"><br></p>
276 <p class="p2"><br></p>
277 <p class="p2"><br></p>
278 <p class="p3"><b>e) moving out of the proxy space:</b></p>
279 <p class="p2"><br></p>
280 <p class="p2"><br></p>
281 <p class="p6">// play the audio:</p>
282 <p class="p7">~x.play;</p>
283 <p class="p2"><br></p>
284 <p class="p7">~x = { <span class="s6">PinkNoise</span>.ar(0.5) };</p>
285 <p class="p2"><br></p>
286 <p class="p6">// p is the proxy space:</p>
287 <p class="p7">p.postln;</p>
288 <p class="p2"><br></p>
289 <p class="p6">// to end all processes in p, use end:</p>
290 <p class="p7">p.end(2) // 2 seconds fade out.</p>
291 <p class="p2"><br></p>
292 <p class="p6">// to remove all bus objects and free them from the bus allocato, use clear:</p>
293 <p class="p7">p.clear;</p>
294 <p class="p2"><br></p>
295 <p class="p7">currentEnvironment.postln;</p>
296 <p class="p2"><br></p>
297 <p class="p6">// restore original environment:</p>
298 <p class="p2"><br></p>
299 <p class="p7">p.pop;</p>
300 <p class="p2"><br></p>
301 <p class="p7">currentEnvironment.postln;</p>
302 <p class="p2"><br></p>
303 <p class="p7">~a + ~b; // the old values are still here.</p>
304 <p class="p8"><br></p>
305 <p class="p7">p === currentEnvironment; // this is not the case anymore.</p>
306 <p class="p2"><br></p>
307 <p class="p6">// remove the content, so the garbage collector can release their memory.</p>
308 <p class="p7">p.clear;</p>
309 <p class="p2"><br></p>
310 <p class="p6">// note that if you use this kind of accessing scheme, the objects are not garbage collected</p>
311 <p class="p6">// until the keys are set to nil. This is a common mistake when using normal environments.</p>
312 <p class="p2"><br></p>
313 <p class="p6">// clear all in the normal environment:</p>
314 <p class="p2"><br></p>
315 <p class="p7">currentEnvironment.clear;</p>
316 <p class="p2"><br></p>
317 <p class="p2"><br></p>
318 <p class="p2"><br></p>
319 <p class="p2"><br></p>
320 <p class="p2"><br></p>
321 <p class="p3"><b>f) using ProxySpace together with other Environments</b></p>
322 <p class="p2"><br></p>
323 <p class="p3">using proxy space as an access scheme for node proxies can get in the way of the</p>
324 <p class="p3">normal use of environments as pseudo variables. Here are some ways to cope with this.</p>
325 <p class="p4"><br></p>
326 <p class="p9">//////////////<span class="Apple-tab-span"> </span>EnvirDocument is currently unavailable ////////////</p>
327 <p class="p9">//// if you want to keep using the current environment as usual, you can restrict the</p>
328 <p class="p9">//// scope of proxyspace to one document (note: this is mac-only currently)</p>
329 <p class="p9">//</p>
330 <p class="p9">//EnvirDocument(p, "proxyspace"); <span class="Apple-tab-span"> </span>// to test this, check for currentEnvironment here<span class="Apple-converted-space"> </span></p>
331 <p class="p9">//<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// and in the envir document.</p>
332 <p class="p10"><br></p>
333 <p class="p9">// you can also access the proxy space and the proxies in it indirectly:</p>
334 <p class="p11">p[<span class="s11">\x</span>].play;</p>
335 <p class="p11">p[<span class="s11">\x</span>] = { <span class="s12">SinOsc</span>.ar(450, 0, 0.1) };</p>
336 <p class="p10"><br></p>
337 <p class="p9">// or: when the proxyspace is pushed, you can use a normal environment indirectly:</p>
338 <p class="p11">p.push;</p>
339 <p class="p11">d = ();</p>
340 <p class="p11">d[<span class="s11">\buffer1</span>] = <span class="s12">Buffer</span>.alloc(s, 1024);</p>
341 <p class="p9"><span class="s2">d.use { ~buffer1.postln; ~zz = 81; }; </span>// for more than one access to the environment, use .use</p>
342 <p class="p10"><br></p>
343 <p class="p10"><br></p>
344 <p class="p9">// to access the inner environment of proxy space directly,<span class="Apple-converted-space"> </span></p>
345 <p class="p9">// e.g. to check whether a proxy exists, one can use .envir:</p>
346 <p class="p10"><br></p>
347 <p class="p11">p.envir.postln;</p>
348 <p class="p9"><span class="s2">p.envir[</span><span class="s11">\x</span><span class="s2">].postln;<span class="Apple-tab-span"> </span></span>// a proxy with this name exists<span class="Apple-converted-space"> </span></p>
349 <p class="p9"><span class="s2">p.envir[</span><span class="s11">\nono</span><span class="s2">].postln;<span class="Apple-tab-span"> </span></span>// there is no proxy with this name.<span class="Apple-converted-space"> </span></p>
350 <p class="p10"><br></p>
351 <p class="p9">// p[\nono].postln; <span class="Apple-tab-span"> </span>// this access would have created a new proxy called \nono.</p>
352 <p class="p2"><br></p>
353 <p class="p2"><br></p>
354 <p class="p2"><br></p>
355 <p class="p5"><span class="s2">previous: <a href="jitlib_basic_concepts_01.html"><span class="s3">jitlib_basic_concepts_01</span></a><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>next: <a href="jitlib_basic_concepts_03.html"><span class="s3">jitlib_basic_concepts_03</span></a><span class="Apple-converted-space"> </span></span></p>
356 <p class="p2"><br></p>
357 </body>
358 </html>