1title:: the_lazy_proxy 2summary:: the lazy proxy 3categories:: JITLib>Tutorials 4related:: Overviews/JITLib, Classes/NodeProxy, Classes/ProxySpace 5 6The 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:: : 7 8code:: 9p = ProxySpace.push; 10~x.isNeutral; 11:: 12 13as soon as the first time the source is set, it derives its bus arguments from that input 14 15code:: 16~x = { Array.fill(14, { SinOsc.kr(1.0.rand, 0, 100) }) }; //~x is now 14 channels control rate 17~x; 18:: 19 20in order to reset these properties, clear is used: 21 22code:: 23~x.clear; 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. 26:: 27 28for a quick initialisation, also code::defineBus:: can be used: 29 30code:: 31~x.defineBus(\control, 5); 32// or in another way: 33~x.kr(5) 34:: 35 36the properties are also set when some other proxy reads from it: 37 38code:: 39~x = { LFPulse.kr * ~b.kr(7) }; //the first arg to kr / ar is the default number of channels 40:: 41 42if no number of channels is passed in, the default value is used: 43 44code:: 45~test.ar; // 2 46~krtest.kr; // 1 47:: 48 49the default can be set in the class NodeProxy: 50 51code:: 52NodeProxy.defaultNumAudio = 3; 53NodeProxy.defaultNumControl = 13; 54 55~test3.ar; // 3 56~krtest3.kr; // 13 57 58// set them back: 59NodeProxy.defaultNumAudio = 2; 60NodeProxy.defaultNumControl = 1; 61:: 62 63also if a proxy is used as a map source, control rate is assumed: 64 65code:: 66~u; 67~x.map(\zzz, ~u); 68~u; 69:: 70 71when unary or binary operations are performed, the highest rate / numChannels is used to initialize all uninitialized proxies: 72 73code:: 74~x.clear; 75~x.defineBus(\control, 5); 76~x = ~e + ~f; 77 78~x.clear; ~e.clear; ~f.clear; 79~e.defineBus(\audio, 1); 80~x = ~e + ~f.squared + ~r; 81~x; 82 83~x.clear; ~e.clear; ~f.clear; 84~e.defineBus(\audio, 3); 85~x = ~e; 86:: 87 88if a rate-1 proxy is used as rate-2 input, the rate is converted and the channels are expanded in the usual multichannel expansion pattern: 89 90code:: 91~f.defineBus(\control); 92~f.ar(2); 93 94~f.defineBus(\audio); 95~f.kr(2); 96 97// if the number of channels passed in is less, it only uses the first n channels 98~f.defineBus(\audio, 8); 99~f.ar(2); 100:: 101 102an offset can be passed in as second argument to ar/kr 103 104code:: 105//modulate offset: 106p = ProxySpace.push(s.boot); 107 108~out.play; 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 112:: 113