2 summary:: the lazy proxy
3 categories:: Libraries>JITLib>Tutorials
4 related:: Overviews/JITLib, Classes/NodeProxy, Classes/ProxySpace
6 The class link::Classes/NodeProxy:: (and link::Classes/BusPlug::) uses a lazy evaluation scheme to derive its appropriate rate and numChannels from the first meaningful input that is assigned to it. see link::Classes/NodeProxy:: and link::Classes/ProxySpace:: helpfiles for basic info. So as long as the source is not set, the proxy is strong::neutral:: :
13 as soon as the first time the source is set, it derives its bus arguments from that input
16 ~x = { Array.fill(14, { SinOsc.kr(1.0.rand, 0, 100) }) }; //~x is now 14 channels control rate
20 in order to reset these properties, clear is used:
24 //note that no other proxy should be reading from ~x when this is done:
25 //for simplicity nodeproxy currently does not care for its children, only for its parents.
28 for a quick initialisation, also code::defineBus:: can be used:
31 ~x.defineBus(\control, 5);
36 the properties are also set when some other proxy reads from it:
39 ~x = { LFPulse.kr * ~b.kr(7) }; //the first arg to kr / ar is the default number of channels
42 if no number of channels is passed in, the default value is used:
49 the default can be set in the class NodeProxy:
52 NodeProxy.defaultNumAudio = 3;
53 NodeProxy.defaultNumControl = 13;
59 NodeProxy.defaultNumAudio = 2;
60 NodeProxy.defaultNumControl = 1;
63 also if a proxy is used as a map source, control rate is assumed:
71 when unary or binary operations are performed, the highest rate / numChannels is used to initialize all uninitialized proxies:
75 ~x.defineBus(\control, 5);
78 ~x.clear; ~e.clear; ~f.clear;
79 ~e.defineBus(\audio, 1);
80 ~x = ~e + ~f.squared + ~r;
83 ~x.clear; ~e.clear; ~f.clear;
84 ~e.defineBus(\audio, 3);
88 if a rate-1 proxy is used as rate-2 input, the rate is converted and the channels are expanded in the ususal multichannel expansion pattern:
91 ~f.defineBus(\control);
97 // if the number of channels passed in is less, it only uses the first n channels
98 ~f.defineBus(\audio, 8);
102 an offset can be passed in as second argument to ar/kr
106 p = ProxySpace.push(s.boot);
109 ~src = { SinOsc.ar(Array.rand(5, 400, 500.0), SinOsc.ar(Array.exprand(5, 2.1, 500.0)), 0.1) };
110 ~out = { ~src.ar(1, MouseX.kr(0, 5)) };
111 ~out = { Mix(~src.ar(3, MouseX.kr(0, 5))) }; //the wrapping offset is moved accordingly