2 summary:: a reference on a server
3 categories:: Libraries>JITLib>NodeProxy
4 related:: Classes/ProxySpace
7 Generally a strong::proxy:: is a placeholder for something. A node proxy is a placeholder for something strong::playing on a server:: that writes to a limited number of busses (e.g. a synth or an event stream). NodeProxy objects can be replaced and recombined while they play. Also they can be used to build a larger structure which is used and modified later on. Overview: link::Overviews/JITLib::.
9 NodeProxy is used internally in link::Classes/ProxySpace:: and it is a superclass of link::Classes/Ndef::, allowing to easily access and combine a large number of placeholders.
11 Graphical editor for a node proxy: link::Classes/NodeProxyEditor::.
14 NodeProxy plays on a emphasis::private bus::. If you want to strong::hear:: the output, use link::#-play:: and link::#-stop::. To free inner players and stop listen: link::#-end::. Entirely removing all inner settings: link::#-clear::
17 subsection::Further reading
20 ## link::Tutorials/JITLib/the_lazy_proxy::
21 ## link::Tutorials/JITLib/jitlib_efficiency::
22 ## link::Tutorials/JITLib/jitlib_fading::
23 ## link::Tutorials/JITLib/jitlib_asCompileString::
24 ## link::Reference/NodeProxy_roles::
27 subsection::First Example
32 a = NodeProxy.new.play; // play to hardware output.
33 a.fadeTime = 2; // fadeTime specifies crossfade
35 a.source = { SinOsc.ar([350, 351.3], 0, 0.2) };
36 a.source = { Pulse.ar([350, 351.3] / 4, 0.4) * 0.2 };
37 a.source = Pbind(\dur, 0.03, \freq, Pbrown(0, 1, 0.1, inf).linexp(0, 1, 200, 350));
40 a.source = { Ringz.ar(b.ar, [350, 351.3] * 8, 0.2) * 4 };
41 b.source = { Impulse.ar([5, 7]/2, [0, 0.5]) };
43 a.clear(3); // clear after 3 seconds
52 Return a new instance of NodeProxy.
56 a = NodeProxy(s, \audio, 4);
58 a.clear; // remove bus.
59 a.numChannels; // nil.
63 The server on which to run and where the bus is allocated (default: code::Server.default::)
66 If given, proxy is initialized to this rate
69 If given, proxy is initialized to this number of channels
72 If given, proxy is initialized with the given inputs as objects on subsequent slots.
75 Return a new audio rate NodeProxy of a given number of channels.
78 The server on which to run and where the bus is allocated (default: code::Server.default::)
81 If given, proxy is initialized to this number of channels (default: 2)
84 Return a new control rate NodeProxy of a given number of channels.
87 The server on which to run and where the bus is allocated (default: code::Server.default::)
90 If given, proxy is initialized to this number of channels (default: 1)
93 Return a new instance of NodeProxy using a given link::Classes/Bus::.
95 subsection::Accessing Class Variables
97 method::defaultNumAudio, defaultNumControl
98 set the default channel number for audio/control busses
102 private::prFadeTime, linkNodeMap, generateUniqueName, prepareOutput, addToChild
104 subsection::Listening to the output
107 plays to a bus index ( strong::out:: ) with a number of channels ( strong::numChannels:: ) within a target strong::group:: ( link::Classes/Group:: or link::Classes/Server:: ).
110 keep old links and add new one
113 volume at which to monitor
116 fade in fade out time
119 see link::Reference/playN::.
122 array of destination channels
125 array of amplitudes for each channel
128 array of source channels
131 stop to play out public channels (private channels keep playing as others might listen still) this stops the monitoring. To stop the objects playing, use link::#-free::, link::#-release::.
134 decay time for this action
137 releases the synths and stops playback.
139 argument::fadeTime: decay time for this action
142 return a link to my output, which is limited by [numChannels]. causes an uninitialized proxy to create a matching bus. normally strong::ar:: defaults to stereo, strong::kr:: to mono. this can be set in the classvars: link::#*defaultNumAudio::, link::#*defaultNumControl::.
144 subsection::Setting the source
146 NodeProxy keeps a number of slots which can be sources and are mixed on the same bus.. The default source is the slot 0. All objects can be exchanged while running, and also before and after. Normally, the source is active immediately. If sources are to be exchanged "quietly", set the node proxy to sleep (awake = false), or use the message prime().
148 See the list under section link::#supported_sources::
151 Play a new synth through proxy and release/remove any old ones.
154 can be one of the supported inputs (see link::#supported_sources::)
157 Set source without starting the synth. To start it, link::#-send:: can be used later. Running synths are released and proxy is initialized if still neutral.
160 Add a new source to the present ones
163 Remove the object at index i and its synths, if they exist.
166 Remove the last object and its synths, if they exist.
169 Set the source by index. Objects can be inserted at any index, only the order of indices is relevant. Internally, NodeProxy uses an link::Classes/Order:: to access the sources.
172 where the object should be placed in the internal order. if code::-1::, all objects are freed
175 A valid source (see link::#supported_sources::).
177 argument::channelOffset
178 using a multichannel setup it can be useful to set this, when the objects numChannels is smaller than the proxy
181 Arguments that can be sent with the object directly (not cached)
184 if set to false, only prepare the source and do not start the object (see link::#-prime::)
187 // put can be used with the array indexing syntax:
188 a = NodeProxy.new.play;
189 a[0] = { SinOsc.ar(Rand(200, 899)) * 0.1.dup };
190 a[2] = { SinOsc.ar(Rand(200, 899)) * 0.1.dup };
191 a.sources.do(_.postcs);
192 // using multiple index expands into multiple objects
193 a[0..5] = { SinOsc.ar(Rand(200, 899)) * 0.1.dup };
194 a.sources.do(_.postcs);
195 a.send; // exchange synths, using the sources as definitions
200 Pause all objects and set proxy to paused
203 If paused, start all objects
206 Rebuild all SynthDefs from sources.
209 Arrange the order of groups from this to the last. This can be important when external input is filtered in order to strong::minimize latency::. Note that if a link::#-parentGroup:: was provided, the nodes must be in the same parentGroup.
212 Usage: strong::proxyA <-- proxyB::. Set proxyA source to proxyB and play proxyA. If proxyB was playing, fade it out. This is convenient in the following situation:
215 b = NodeProxy.new.play;
216 b.source = { PinkNoise.ar(0.2.dup) };
217 // now I want to filter b through a new proxy.
219 a <-- b; a.source = { HPF.ar(b.ar, 7000) };
220 a.source = { HPF.ar(b.ar, 3000) };// changing the source
225 Chaining. Usage: strong::proxyA <<> proxyB <<> proxyC <<> ...:: . Map proxyC source to proxyB code::\in:: argument, and proxyB to proxyA's in argument.
228 a = NodeProxy.new.play;
229 a.source = { RLPF.ar(\in.ar(0!2), [4600, 7000], 0.1) };
230 b = NodeProxy.new.source_ { Impulse.ar([5, 7] / 2) };
235 Inverse of the above. Usage: strong::proxyA <>> proxyB <>> proxyC <>> ...:: .
237 subsection::Release and cleaning up
240 Release all running synths and the group. If patterns are playing, stop them.
243 decay time for this action
246 release running synths. If patterns are playing, stop them.
249 decay time for this action
252 reset everything to nil, neutralizes rate/numChannels
255 if a fadeTime is given, first fade out, then clear.
257 subsection::Accessing Instance Variables
260 Returns an array of all sources
263 Returns the first source.
266 The node proxy's server (a link::Classes/Server::).
269 The node proxy's private bus (a link::Classes/Bus::). Because it has a private bus, it is not audible directly - monitoring it by (.play or playN) routs it to the hardware output channels.
272 The bus rate (default: nil) The rate and number of channels is determined either when the instance is created (.control/.audio) or by lazy initialisation from the first source (see link::Tutorials/JITLib/the_lazy_proxy::)
275 The bus numChannels (default: nil)
278 true if the proxy has no initialized bus.
281 The node proxy's group (a link::Classes/Group::). This is maintained by the proxy and serves as a context in which all synths are placed.
284 Access the parentGroup (default: nil), which can be set to run the proxy's group in another group. This group has to be maintained (kept playing etc.) externally.
287 A clock, which can be set to account for different timing schemes, such as beat accurate replacement of sources.
290 A quant value, to specify quantizes replacement of sources. Compatible with the general use of quant in SuperCollider.
293 Synchronize the proxies by resending and adjusting to quant.
296 Access the link::Classes/Monitor:: object, which plays back the output of the proxy's private bus.
299 Returns true if the object has been initialized on the server, e.g. a synthDef has been stored.
302 Returns true if the processes are paused.
305 If set to false (default: true), a change of the source does not start a new synth immediately. This is useful when synths are triggered by link::#-spawn::, and a change of sound should not duplicate sends.
308 set the crossfade time. See: link::Tutorials/JITLib/jitlib_fading:: .
310 subsection::Setting synth controls
312 method::set, unset, unmap
313 NodeProxy behaves like its nodeMap ( link::Classes/NodeMap:: )
316 Map the arguments in keys to the subsequent channels of another proxy (keys can be a symbol or a number). If the proxy has strong::multiple channels::, subsequent channels of the control, if present, are mapped. Note that you should not map to more channels than the control has.
319 set ranges of controls
322 set with crossfade into new setting
325 map with crossfade into new setting
331 set the lag values of these args (identical to link::#-setRates::). To remove these settings, use: code::lag(\key1, nil, key2, nil, ...)::
334 set the default rate (\tr, \ir, numerical) for synthDef arg. A rate of nil removes setting.
337 Returns the link::Classes/ControlName:: objects of all slots, strong::except:: the names of this list (default: code::[\out, \i_out, \gate, \fadeTime]:: , which are used internally).
340 Returns the keys (symbols) of all control names objects of all slots, strong::except:: the names of this list. (default: none).
342 argument::noInternalKeys
343 If noInternalKeys is true (default: true), it ignores the keys code::[\out, \i_out, \gate, \fadeTime]:: .
345 method::getKeysValues
346 Get all key value pairs from both link::Classes/NodeMap:: (the settings) and default arguments.
348 method::controlKeysValues
349 Get all key value pairs from default arguments.
351 subsection::Bus-like behaviour
353 In some ways, NodeProxy behaves like a link::Classes/Bus:: :
356 set my bus to the new value in dur time linearly
359 set my bus to the new value in dur time exponentially
362 gate my bus to the level value for dur time
364 subsection::Sending synths to server
367 Send a new synth without releasing the old one. If the source is a stream or a pattern, it starts a new one.
370 Arguments used to set the synth. the argument list is applied to the synth only.
373 What slot to send a new synth with. If nil, uses all. (default: nil)
376 if to free the last synth at that index or not (default: true)
379 Send all synths, or restart all objects.
382 Arguments used to set the synth. the argument list is applied to the synth only.
385 if to free the last synth at that index or not (default: true)
388 Like send, just iterating seperately over the objects.
391 Until the proxy is not used by any output ( either .play or .ar/.kr ) it is not running on the server. you can wake it up to force it playing. Normally this is not needed.
394 record output to file (returns a link::Classes/RecNodeProxy:: that you can use for control)
399 Returns a new instance of link::Classes/NodeProxyEditor:: for this proxy.
406 a.source = { |freq = 440, rate = 2|
407 SinOsc.ar(freq * [1, 1.625]) * SinOsc.kr(rate).max(0) * 0.2
412 section::Supported sources
415 ## link::Classes/NodeProxy:: || played by reading from the other node proxie's bus.
416 ## link::Classes/Function:: || interpreted as ugen function, and plays a link::Classes/Synth::, similar to Function.play.
417 ## link::Classes/SimpleNumber:: || write this value to the bus continuously
418 ## link::Classes/Bus:: || reads from the bus
419 ## link::Classes/SynthDef:: || plays a link::Classes/Synth:: using the SynthDef. This is useful for triggering.
420 ## link::Classes/Symbol:: || plays a link::Classes/Synth:: from the SynthDef with this name. This is useful for triggering.
421 ## link::Classes/Pattern:: || played as event pattern (using link::Classes/Pbind:: or other event patterns)
422 ## link::Classes/Stream:: || played as event stream (a stream returning events)
423 ## nil || link::Classes/Nil:: removes all objects.
424 ## link::Classes/Pdef::, link::Classes/EventPatternProxy:: || played like a stream
425 ## link::Classes/Task:: || played, no output is assigned.
426 ## link::Classes/Tdef:: || played like Task
427 ## link::Classes/Event:: || played like in a pattern.
431 ## (\filter -> func) || filter previous input (with post control)
432 ## (\filterIn -> func) || filter previous input (with pre control)
433 ## (\set -> event pattern) || set controls with the event keys of the pattern
434 ## (\setbus -> event pattern) || set bus with an event pattern. Bus value is the \value key of each event.
435 ## (\setsrc -> event pattern) || set the source with an event pattern. source is the \source key of event.
436 ## (\control -> array or number) || prepare an efficient way to set values by index
437 ## (\mix -> func) || mix audio
440 ## crucial library: ||
442 ## link::Classes/AbstractPlayer:: || started in a separate bus, mapped to this bus
443 ## link::Classes/Instr:: || converted to player and started
447 Definitions for other sources can be added easily.
451 For more, see link::Classes/ProxySpace::
454 ///////////////////// using node proxy with ugen functions /////////////////////
458 a = NodeProxy.audio(s, 2);
459 a.play; // play to hardware output, return a group with synths
461 // setting the source
462 a.source = { SinOsc.ar([350, 351.3], 0, 0.2) };
464 // the proxy has two channels now:
465 a.numChannels.postln;
466 a.source = { SinOsc.ar([390, 286] * 1.2, 0, 0.2) };
468 // exeeding channels wrap:
469 a.source = { SinOsc.ar([390, 286, 400, 420, 300] * 1.2, 0, 0.2) };
472 a.source = { WhiteNoise.ar([0.01,0.01]) };
474 a.source = \default; // synthDef on server
475 a.source = SynthDef("w", { arg out=0; Out.ar(out,SinOsc.ar([Rand(430, 600), 600], 0, 0.2)) });
476 a.source = nil; // removes any object
479 a.source = { SinOsc.ar(a.ar * 7000 * LFNoise1.kr(1, 0.3, 0.6) + 200, 0, 0.1) };
480 a.source = { SinOsc.ar(a.ar * 6000 * MouseX.kr(0, 2) + [100, 104], 0, 0.1) };
484 a.source = { SinOsc.ar([390, 286] * ExpRand(1, 3), 0, 0.2) };
488 a.add({ SinOsc.ar([50, 390]*1.25, 0, 0.1) });
489 a.add({ BrownNoise.ar([0.02,0.02]) });
491 // setting nodes at indices:
492 a[0] = { SinOsc.ar( 700 * LFNoise1.kr(1, 0.3, 0.6) + 200, 0, 0.1) };
493 a[1] = { LFPulse.kr(3, 0.3) * SinOsc.ar(500, 0, 0.1) };
494 a[2] = { LFPulse.kr(3.5, 0.3) * SinOsc.ar(600, 0, 0.1) };
495 a[3] = { SinOsc.ar([1,1.25] * 840, 0, 0.1) };
497 // filtering: the first argument is the previous bus content. more args can be used as usual.
498 a[3] = \filter -> { arg in; in * SinOsc.ar(Rand(100,1000)) };
499 a[2] = \filter -> { arg in; in * MouseY.kr(0,1) };
500 a[8] = \filter -> { arg in; in * MouseX.kr(0,1) };
501 a[4] = \filter -> { arg in; in * SinOsc.ar(ExpRand(1,5)).max(0) };
507 a.source = { arg f=400; SinOsc.ar(f * [1,1.2] * rrand(0.9, 1.1), 0, 0.1) };
508 a.set(\f, rrand(900, 300));
509 a.set(\f, rrand(1500, 700));
510 a.xset(\f, rrand(1500, 700)); // crossfaded setting
511 a.source = { arg f=400; RLPF.ar(Pulse.ar(f * [1,1.02] * 0.05, 0.5, 0.2), f * 0.58, 0.2) };
514 a.lag(\f, 0.5); // the objects are built again internally and sent to the server.
515 a.set(\f, rrand(1500, 700));
517 a.set(\f, rrand(1500, 700));
521 // mapping controls to other node proxies
523 c = NodeProxy.control(s, 2);
524 c.source = { SinOsc.kr([10,20] * 0.1, 0, 150, 1300) };
526 a[0] = { arg f=400; RHPF.ar(Pulse.ar(f * [1,1.2] * 0.05, 0.5, 0.2), f * 0.58, 0.2) };
527 c.source = { SinOsc.kr([10,16] * 0.02, 0, 50, 700) };
528 c.source = { Line.kr(300, 1500, 10) + SinOsc.kr(20 * [1,2], 0, 100) };
529 a[1] = { arg f; LFPar.ar(f % MouseX.kr(1, 40, 1) * 4 + 360, 0, 0.2) };
531 // map multiple channels of one proxy to multiple controls of another
532 // recently changed behaviour!
534 a.source = { arg f=#[400, 400]; LPF.ar(Pulse.ar(f[0] * [0.4,1], 0.2, 0.2), f[1] * 3) };
535 a.map(\f, c); // multichannel proxy c is mapped to multichannel control of a
536 a.source = { arg f=#[400, 400]; LPF.ar(Pulse.ar(f, 0.2, 0.2), f[1]) };
537 a.source = { arg f=#[400, 400]; Formant.ar(140, f * 1.5, 100, 0.1) };
538 c.source = { SinOsc.kr([Line.kr(1, 30, 10), 1], 0, [100, 700], [300, 700]) };
543 c.source = { LFNoise0.kr([2.3, 1.0], [100, 700], [300, 1700]) };
544 c.source = { SinOsc.kr([2.3, 1.0], 0, [100, 700], [300, 1700]) };
548 // behave like a sc2 plug
554 a.lineAt(\f, 300, 2);
555 a.xlineAt(\f, 600, 0.3);
556 a.gateAt(\f, 1600, 0.3);
567 a.fadeToMap(n, [\f]); // linear interpolation to new map: experimental
568 a.map(\f, c); // restore mapping
571 // sending envelopes (up to 8 levels)
572 w = Env.new(Array.rand(3, 400, 1000),Array.rand(2, 0.3, 0.001), -4);
575 w = Env.new(Array.rand(8, 400, 1000),Array.rand(7, 0.03, 0.1));
579 // stop synthesis, then wake up proxies:
581 a.stop; // stop the monitor
582 a.play; // start the monitor
583 a.end; // release the synths and stop the monitor
584 c.free; // free the control proxy c
589 ///////////////////// channel offset/object index /////////////////////
592 a = NodeProxy.audio(s,2);
594 a[0] = { Ringz.ar(Impulse.ar(5, 0, 0.1), 1260) };
595 a.put(1, { Ringz.ar(Impulse.ar(5.3, 0, 0.1), 420) }, 1);
596 a.put(0, { Ringz.ar(Dust.ar([1,1]*15.3, 0.1), 720) }, 1);
597 a.put(1, { Ringz.ar(Impulse.ar(5.3, 0, 0.1), 420) }, 1);
603 ///////////////////// beat accurate playing /////////////////////
608 a = NodeProxy.audio(s,2);
611 a.clock = TempoClock(2.0).permanent_(true); // round to every 2.0 seconds
612 a.source = { Ringz.ar(Impulse.ar(0.5, 0, 0.3), 3000, 0.01) };
613 a[1] = { Ringz.ar(Impulse.ar([0.5, 1], 0, 0.3), 1000, 0.01) };
614 a[2] = { Ringz.ar(Impulse.ar([3, 5]/2, 0, 0.3), 8000, 0.01) };
615 a[3] = { Ringz.ar(Impulse.ar([3, 5]*16, 0, 0.3), 5000, 0.01) * LFPulse.kr(0.5, 0, 0.05) };
625 ///////////////////// using patterns - event streams /////////////////////
629 // must have 'out' or 'i_out' argument to work properly
630 SynthDef("who", { arg freq, gate=1, out=0, ffreq=800, amp=0.1;
632 env = Env.asr(0.01, amp, 0.5);
634 Formant.ar(freq, ffreq, 300, EnvGen.kr(env, gate, doneAction:2)), Rand(-1.0, 1.0))
643 a = NodeProxy.audio(s, 2);
645 b = NodeProxy.audio(s,2);
649 a.play; // monitor output
651 // play the pattern silently in b
652 b.source = Pbind(\instrument, \who, \freq, 500, \ffreq, 700, \legato, 0.02);
654 // play b out through a:
657 // filter b with ring modulation:
658 a.source = { b.ar * SinOsc.ar(SinOsc.kr(0.2, 300, 330)) }; // filter the input of the pattern
659 a.source = { b.ar * LFCub.ar([2, 8], add: -0.5) }; // filter the input of the pattern
663 // map b to another proxy
664 c = NodeProxy.control(s, 1).fadeTime_(1);
665 c.source = { SinOsc.kr(2, 0, 400, 700) };
668 // now one can simply embed a control node proxy into an event pattern.
669 // (this works not for \degree, \midinote, etc.)
670 // embedding in other patterns it will still return itself.
673 b.source = Pbind(\instrument, \who, \freq, 500, \ffreq, c, \legato, 0.02);
675 c.source = { SinOsc.kr(SinOsc.kr(0.2, 0, 10, 10), 0, 400, 700) };
677 c.source = { LFNoise1.kr(5, 1300, 1500) };
678 c.source = { MouseX.kr(100, 5500, 1) };
683 \freq, Pseq([600, 350, 300],inf),
685 \ffreq, Pseq([c, 100, c, 100, 300, 600], inf), // use proxy in a pattern
686 \dur, Pseq([1, 0.5, 0.75, 0.25] * 0.4, inf),
687 \amp, Pseq([0.2, 0.2, 0.1, 0.1, 0.2], inf)
693 b[2] = Pbind(\instrument, \who, \freq, 620, \ffreq, Prand([500,c],inf), \legato, 0.1, \dur, 0.1);
694 b[3] = Pbind(\instrument, \who, \ffreq, 5000, \freq, Pseq([720, 800],inf), \legato, 0.1, \dur, 0.1, \amp, 0.01);
695 b[4] = Pbind(\instrument, \who, \freq, Pseq([700, 400],inf), \legato, 0.1, \ffreq, 200);
696 b[1] = { WhiteNoise.ar([0.01,0.01]) };
697 b[4] = { arg ffreq=800; Resonz.ar(WhiteNoise.ar([1,1]), ffreq, 0.05) };
700 b.map(\ffreq, c); // map the control to the proxy
703 a.source = { b.ar * WhiteNoise.ar(0.1, 1) };
704 a.source = { b.ar * WhiteNoise.ar(0.1, 1) + (b.ar * SinOsc.ar(SinOsc.kr(0.01, 0, 50, 330))) };
706 c.source = { XLine.kr(1900, 10, 10) };
708 a.clear(10); b.clear(10); c.clear(10); // fade out and clear all (free bus, group and synths)