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.
140 decay time for this action
146 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::.
148 subsection::Setting the source
150 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().
152 See the list under section link::#supported_sources::
155 Play a new synth through proxy and release/remove any old ones.
158 can be one of the supported inputs (see link::#supported_sources::)
161 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.
164 Add a new source to the present ones
167 Remove the object at index i and its synths, if they exist.
170 Remove the last object and its synths, if they exist.
173 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.
176 where the object should be placed in the internal order. if code::-1::, all objects are freed
179 A valid source (see link::#supported_sources::).
181 argument::channelOffset
182 using a multichannel setup it can be useful to set this, when the objects numChannels is smaller than the proxy
185 Arguments that can be sent with the object directly (not cached)
188 if set to false, only prepare the source and do not start the object (see link::#-prime::)
191 // put can be used with the array indexing syntax:
192 a = NodeProxy.new.play;
193 a[0] = { SinOsc.ar(Rand(200, 899)) * 0.1.dup };
194 a[2] = { SinOsc.ar(Rand(200, 899)) * 0.1.dup };
195 a.sources.do(_.postcs);
196 // using multiple index expands into multiple objects
197 a[0..5] = { SinOsc.ar(Rand(200, 899)) * 0.1.dup };
198 a.sources.do(_.postcs);
199 a.send; // exchange synths, using the sources as definitions
204 Pause all objects and set proxy to paused
207 If paused, start all objects
210 Rebuild all SynthDefs from sources.
213 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.
216 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:
219 b = NodeProxy.new.play;
220 b.source = { PinkNoise.ar(0.2.dup) };
221 // now I want to filter b through a new proxy.
223 a <-- b; a.source = { HPF.ar(b.ar, 7000) };
224 a.source = { HPF.ar(b.ar, 3000) };// changing the source
229 Chaining. Usage: strong::proxyA <<> proxyB <<> proxyC <<> ...:: . Map proxyC source to proxyB code::\in:: argument, and proxyB to proxyA's in argument.
232 a = NodeProxy.new.play;
233 a.source = { RLPF.ar(\in.ar(0!2), [4600, 7000], 0.1) };
234 b = NodeProxy.new.source_ { Impulse.ar([5, 7] / 2) };
239 Inverse of the above. Usage: strong::proxyA <>> proxyB <>> proxyC <>> ...:: .
241 subsection::Release and cleaning up
244 Release all running synths and the group. If patterns are playing, stop them.
247 decay time for this action
253 release running synths. If patterns are playing, stop them.
256 decay time for this action
259 reset everything to nil, neutralizes rate/numChannels
262 if a fadeTime is given, first fade out, then clear.
264 subsection::Accessing Instance Variables
267 Returns an array of all sources
270 Returns the first source.
273 The node proxy's server (a link::Classes/Server::).
276 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.
279 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::)
282 The bus numChannels (default: nil)
285 true if the proxy has no initialized bus.
288 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.
291 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.
294 A clock, which can be set to account for different timing schemes, such as beat accurate replacement of sources.
297 A quant value, to specify quantizes replacement of sources. Compatible with the general use of quant in SuperCollider.
300 Synchronize the proxies by resending and adjusting to quant.
303 Access the link::Classes/Monitor:: object, which plays back the output of the proxy's private bus.
306 Returns true if the object has been initialized on the server, e.g. a synthDef has been stored.
309 Returns true if the processes are paused.
312 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.
315 set the crossfade time. See: link::Tutorials/JITLib/jitlib_fading:: .
317 subsection::Setting synth controls
319 method::set, unset, unmap
320 NodeProxy behaves like its nodeMap ( link::Classes/NodeMap:: )
323 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.
326 set ranges of controls
329 set with crossfade into new setting
332 map with crossfade into new setting
338 set the lag values of these args (identical to link::#-setRates::). To remove these settings, use: code::lag(\key1, nil, key2, nil, ...)::
341 set the default rate (\tr, \ir, numerical) for synthDef arg. A rate of nil removes setting.
344 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).
347 Returns the keys (symbols) of all control names objects of all slots, strong::except:: the names of this list. (default: none).
352 argument::noInternalKeys
353 If noInternalKeys is true (default: true), it ignores the keys code::[\out, \i_out, \gate, \fadeTime]:: .
355 method::getKeysValues
356 Get all key value pairs from both link::Classes/NodeMap:: (the settings) and default arguments.
358 method::controlKeysValues
359 Get all key value pairs from default arguments.
361 subsection::Sending synths to server
364 Send a new synth without releasing the old one. If the source is a stream or a pattern, it starts a new one.
367 Arguments used to set the synth. the argument list is applied to the synth only.
370 What slot to send a new synth with. If nil, uses all. (default: nil)
373 if to free the last synth at that index or not (default: true)
376 Send all synths, or restart all objects.
379 Arguments used to set the synth. the argument list is applied to the synth only.
382 if to free the last synth at that index or not (default: true)
385 Like send, just iterating seperately over the objects.
388 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.
393 Returns a new instance of link::Classes/NodeProxyEditor:: for this proxy.
400 a.source = { |freq = 440, rate = 2|
401 SinOsc.ar(freq * [1, 1.625]) * SinOsc.kr(rate).max(0) * 0.2
406 section::Supported sources
409 ## link::Classes/NodeProxy:: || played by reading from the other node proxie's bus.
410 ## link::Classes/Function:: || interpreted as ugen function, and plays a link::Classes/Synth::, similar to Function.play.
411 ## link::Classes/SimpleNumber:: || write this value to the bus continuously
412 ## link::Classes/Bus:: || reads from the bus
413 ## link::Classes/SynthDef:: || plays a link::Classes/Synth:: using the SynthDef. This is useful for triggering.
414 ## link::Classes/Symbol:: || plays a link::Classes/Synth:: from the SynthDef with this name. This is useful for triggering.
415 ## link::Classes/Pattern:: || played as event pattern (using link::Classes/Pbind:: or other event patterns)
416 ## link::Classes/Stream:: || played as event stream (a stream returning events)
417 ## nil || link::Classes/Nil:: removes all objects.
418 ## link::Classes/Pdef::, link::Classes/EventPatternProxy:: || played like a stream
419 ## link::Classes/Task:: || played, no output is assigned.
420 ## link::Classes/Tdef:: || played like Task
421 ## link::Classes/Event:: || played like in a pattern.
425 ## (\filter -> func) || filter previous input (with post control)
426 ## (\filterIn -> func) || filter previous input (with pre control)
427 ## (\set -> event pattern) || set controls with the event keys of the pattern
428 ## (\setbus -> event pattern) || set bus with an event pattern. Bus value is the \value key of each event.
429 ## (\setsrc -> event pattern) || set the source with an event pattern. source is the \source key of event.
430 ## (\control -> array or number) || prepare an efficient way to set values by index
431 ## (\mix -> func) || mix audio
434 ## crucial library: ||
436 ## AbstractPlayer || started in a separate bus, mapped to this bus
437 ## Instr || converted to player and started
441 Definitions for other sources can be added easily.
445 For more, see link::Classes/ProxySpace::
448 ///////////////////// using node proxy with ugen functions /////////////////////
452 a = NodeProxy.audio(s, 2);
453 a.play; // play to hardware output, return a group with synths
455 // setting the source
456 a.source = { SinOsc.ar([350, 351.3], 0, 0.2) };
458 // the proxy has two channels now:
459 a.numChannels.postln;
460 a.source = { SinOsc.ar([390, 286] * 1.2, 0, 0.2) };
462 // exeeding channels wrap:
463 a.source = { SinOsc.ar([390, 286, 400, 420, 300] * 1.2, 0, 0.2) };
466 a.source = { WhiteNoise.ar([0.01,0.01]) };
468 a.source = \default; // synthDef on server
469 a.source = SynthDef("w", { arg out=0; Out.ar(out,SinOsc.ar([Rand(430, 600), 600], 0, 0.2)) });
470 a.source = nil; // removes any object
473 a.source = { SinOsc.ar(a.ar * 7000 * LFNoise1.kr(1, 0.3, 0.6) + 200, 0, 0.1) };
474 a.source = { SinOsc.ar(a.ar * 6000 * MouseX.kr(0, 2) + [100, 104], 0, 0.1) };
478 a.source = { SinOsc.ar([390, 286] * ExpRand(1, 3), 0, 0.2) };
482 a.add({ SinOsc.ar([50, 390]*1.25, 0, 0.1) });
483 a.add({ BrownNoise.ar([0.02,0.02]) });
485 // setting nodes at indices:
486 a[0] = { SinOsc.ar( 700 * LFNoise1.kr(1, 0.3, 0.6) + 200, 0, 0.1) };
487 a[1] = { LFPulse.kr(3, 0.3) * SinOsc.ar(500, 0, 0.1) };
488 a[2] = { LFPulse.kr(3.5, 0.3) * SinOsc.ar(600, 0, 0.1) };
489 a[3] = { SinOsc.ar([1,1.25] * 840, 0, 0.1) };
491 // filtering: the first argument is the previous bus content. more args can be used as usual.
492 a[3] = \filter -> { arg in; in * SinOsc.ar(Rand(100,1000)) };
493 a[2] = \filter -> { arg in; in * MouseY.kr(0,1) };
494 a[8] = \filter -> { arg in; in * MouseX.kr(0,1) };
495 a[4] = \filter -> { arg in; in * SinOsc.ar(ExpRand(1,5)).max(0) };
501 a.source = { arg f=400; SinOsc.ar(f * [1,1.2] * rrand(0.9, 1.1), 0, 0.1) };
502 a.set(\f, rrand(900, 300));
503 a.set(\f, rrand(1500, 700));
504 a.xset(\f, rrand(1500, 700)); // crossfaded setting
505 a.source = { arg f=400; RLPF.ar(Pulse.ar(f * [1,1.02] * 0.05, 0.5, 0.2), f * 0.58, 0.2) };
508 a.lag(\f, 0.5); // the objects are built again internally and sent to the server.
509 a.set(\f, rrand(1500, 700));
511 a.set(\f, rrand(1500, 700));
515 // mapping controls to other node proxies
517 c = NodeProxy.control(s, 2);
518 c.source = { SinOsc.kr([10,20] * 0.1, 0, 150, 1300) };
520 a[0] = { arg f=400; RHPF.ar(Pulse.ar(f * [1,1.2] * 0.05, 0.5, 0.2), f * 0.58, 0.2) };
521 c.source = { SinOsc.kr([10,16] * 0.02, 0, 50, 700) };
522 c.source = { Line.kr(300, 1500, 10) + SinOsc.kr(20 * [1,2], 0, 100) };
523 a[1] = { arg f; LFPar.ar(f % MouseX.kr(1, 40, 1) * 4 + 360, 0, 0.2) };
525 // map multiple channels of one proxy to multiple controls of another
526 // recently changed behaviour!
528 a.source = { arg f=#[400, 400]; LPF.ar(Pulse.ar(f[0] * [0.4,1], 0.2, 0.2), f[1] * 3) };
529 a.map(\f, c); // multichannel proxy c is mapped to multichannel control of a
530 a.source = { arg f=#[400, 400]; LPF.ar(Pulse.ar(f, 0.2, 0.2), f[1]) };
531 a.source = { arg f=#[400, 400]; Formant.ar(140, f * 1.5, 100, 0.1) };
532 c.source = { SinOsc.kr([Line.kr(1, 30, 10), 1], 0, [100, 700], [300, 700]) };
537 c.source = { LFNoise0.kr([2.3, 1.0], [100, 700], [300, 1700]) };
538 c.source = { SinOsc.kr([2.3, 1.0], 0, [100, 700], [300, 1700]) };
542 // behave like a sc2 plug
548 a.lineAt(\f, 300, 2);
549 a.xlineAt(\f, 600, 0.3);
550 a.gateAt(\f, 1600, 0.3);
561 a.fadeToMap(n, [\f]); // linear interpolation to new map: experimental
562 a.map(\f, c); // restore mapping
565 // sending envelopes (up to 8 levels)
566 w = Env.new(Array.rand(3, 400, 1000),Array.rand(2, 0.3, 0.001), -4);
569 w = Env.new(Array.rand(8, 400, 1000),Array.rand(7, 0.03, 0.1));
573 // stop synthesis, then wake up proxies:
575 a.stop; // stop the monitor
576 a.play; // start the monitor
577 a.end; // release the synths and stop the monitor
578 c.free; // free the control proxy c
583 ///////////////////// channel offset/object index /////////////////////
586 a = NodeProxy.audio(s,2);
588 a[0] = { Ringz.ar(Impulse.ar(5, 0, 0.1), 1260) };
589 a.put(1, { Ringz.ar(Impulse.ar(5.3, 0, 0.1), 420) }, 1);
590 a.put(0, { Ringz.ar(Dust.ar([1,1]*15.3, 0.1), 720) }, 1);
591 a.put(1, { Ringz.ar(Impulse.ar(5.3, 0, 0.1), 420) }, 1);
597 ///////////////////// beat accurate playing /////////////////////
602 a = NodeProxy.audio(s,2);
605 a.clock = TempoClock(2.0).permanent_(true); // round to every 2.0 seconds
606 a.source = { Ringz.ar(Impulse.ar(0.5, 0, 0.3), 3000, 0.01) };
607 a[1] = { Ringz.ar(Impulse.ar([0.5, 1], 0, 0.3), 1000, 0.01) };
608 a[2] = { Ringz.ar(Impulse.ar([3, 5]/2, 0, 0.3), 8000, 0.01) };
609 a[3] = { Ringz.ar(Impulse.ar([3, 5]*16, 0, 0.3), 5000, 0.01) * LFPulse.kr(0.5, 0, 0.05) };
619 ///////////////////// using patterns - event streams /////////////////////
623 // must have 'out' or 'i_out' argument to work properly
624 SynthDef("who", { arg freq, gate=1, out=0, ffreq=800, amp=0.1;
626 env = Env.asr(0.01, amp, 0.5);
628 Formant.ar(freq, ffreq, 300, EnvGen.kr(env, gate, doneAction:2)), Rand(-1.0, 1.0))
637 a = NodeProxy.audio(s, 2);
639 b = NodeProxy.audio(s,2);
643 a.play; // monitor output
645 // play the pattern silently in b
646 b.source = Pbind(\instrument, \who, \freq, 500, \ffreq, 700, \legato, 0.02);
648 // play b out through a:
651 // filter b with ring modulation:
652 a.source = { b.ar * SinOsc.ar(SinOsc.kr(0.2, 300, 330)) }; // filter the input of the pattern
653 a.source = { b.ar * LFCub.ar([2, 8], add: -0.5) }; // filter the input of the pattern
657 // map b to another proxy
658 c = NodeProxy.control(s, 1).fadeTime_(1);
659 c.source = { SinOsc.kr(2, 0, 400, 700) };
662 // now one can simply embed a control node proxy into an event pattern.
663 // (this works not for \degree, \midinote, etc.)
664 // embedding in other patterns it will still return itself.
667 b.source = Pbind(\instrument, \who, \freq, 500, \ffreq, c, \legato, 0.02);
669 c.source = { SinOsc.kr(SinOsc.kr(0.2, 0, 10, 10), 0, 400, 700) };
671 c.source = { LFNoise1.kr(5, 1300, 1500) };
672 c.source = { MouseX.kr(100, 5500, 1) };
677 \freq, Pseq([600, 350, 300],inf),
679 \ffreq, Pseq([c, 100, c, 100, 300, 600], inf), // use proxy in a pattern
680 \dur, Pseq([1, 0.5, 0.75, 0.25] * 0.4, inf),
681 \amp, Pseq([0.2, 0.2, 0.1, 0.1, 0.2], inf)
687 b[2] = Pbind(\instrument, \who, \freq, 620, \ffreq, Prand([500,c],inf), \legato, 0.1, \dur, 0.1);
688 b[3] = Pbind(\instrument, \who, \ffreq, 5000, \freq, Pseq([720, 800],inf), \legato, 0.1, \dur, 0.1, \amp, 0.01);
689 b[4] = Pbind(\instrument, \who, \freq, Pseq([700, 400],inf), \legato, 0.1, \ffreq, 200);
690 b[1] = { WhiteNoise.ar([0.01,0.01]) };
691 b[4] = { arg ffreq=800; Resonz.ar(WhiteNoise.ar([1,1]), ffreq, 0.05) };
694 b.map(\ffreq, c); // map the control to the proxy
697 a.source = { b.ar * WhiteNoise.ar(0.1, 1) };
698 a.source = { b.ar * WhiteNoise.ar(0.1, 1) + (b.ar * SinOsc.ar(SinOsc.kr(0.01, 0, 50, 330))) };
700 c.source = { XLine.kr(1900, 10, 10) };
702 a.clear(10); b.clear(10); c.clear(10); // fade out and clear all (free bus, group and synths)