1 title:: NodeProxy roles
2 summary:: Roles in NodeProxy
3 categories:: Libraries>JITLib>NodeProxy
4 related:: Classes/NodeProxy, Classes/Ndef, Classes/ProxySpace
6 Similar to Adverbs (see link::Guides/J-concepts-in-SC::), roles allow to specify how a source for a link::Classes/NodeProxy:: is being used. A role is an association of a link::Classes/Symbol:: and the new proxy source object.
8 The below examples can equally be used for link::Classes/Ndef:: and in link::Classes/ProxySpace::.
11 // Thus, the following expressions behave in an equivalent way:
22 section::Existing roles
25 ## \set -> event pattern
26 || Set the proxy controls with an event pattern of type code::\set::
30 a[0] = { |freq = 440, dt=0.1, rate=2| Ringz.ar(Impulse.ar(rate * [1, 1.2]), freq, dt)*0.1 };
34 \dur, Prand([1, 0.5], inf),
35 \freq, Pwhite(200.0, 1000, inf),
36 \rate, Pstutter(4, Prand([1, 3, 6, 10], inf)),
37 \dt, Pwhite(0.01, 0.1, inf)
40 // modify the source in the meanwhile:
41 a[0] = { |freq = 440, dt=0.1, rate=2| Ringz.ar(Dust.ar(rate * 10.dup), freq, dt)*0.1 };
46 ## \setbus -> event pattern
47 || Set the proxy bus with an event pattern of type code::\c_set::
51 b = NodeProxy(s).play;
52 b[0] = { SinOsc.ar(a.kr(4)).sum * 0.2 };
54 a[0] = \setbus -> Pbind(
55 \dur, Prand([1, 0.5], inf),
56 \value, Pfunc { var z = rrand(300, 4000); [300, 400, z, z + 30.rand2] }
59 // modify the other source in the meanwhile:
60 b[0] = { Pulse.ar(a.ar(4)).sum * 0.2 };
65 ## \setsrc -> event pattern
66 || Set the proxy source at the next index with any object, controlled by a pattern. Note that any existing source at the next index (in the example below it is index 1) is overridden by the procedure.
72 a[0] = \setsrc -> Pbind(
73 \dur, Prand([1, 0.5, 2], inf),
75 { SinOsc.ar(SinOsc.ar({5.rand}.dup + 4) * 50 + 400 + 50.rand) * 0.1 },
76 { SinOsc.ar(LFSaw.ar({5.rand}.dup + 4) * 50 + 400 + 50.rand) * 0.1},
77 { LFSaw.ar(SinOsc.ar({5.rand}.dup + 4) * 50 + 400 + 50.rand) * 0.1 },
78 { LFSaw.ar(LFSaw.ar({5.rand}.dup + 4) * 50 + 400 + 50.rand) * 0.1 }
86 ## \filter -> function
87 || Filter the audio on the proxy's own bus, using the first argument to pass in the sound. The function is any valid UGen function, which may be control or audio rate. Default controls are wet++index, where strong::index:: is the slot of the proxy (default 0), in the example below, the control is code::\wet1::.
91 a[0] = { PinkNoise.ar(0.1.dup) };
93 a[1] = \filter -> { |in| RLPF.ar(in, LFNoise2.kr(1).exprange(300, 1000), 0.1) };
98 ## \filterIn -> function
99 || Like code::\filter::, only that the input is controled by the code::\wet:: control, not the output.
103 a[0] = { PinkNoise.ar(0.1.dup) };
105 a[1] = \filterIn -> { |in| RLPF.ar(in, LFNoise2.kr(1).exprange(300, 1000), 0.1) };
111 || Mix in the UGen in the function.
115 a[0] = { PinkNoise.ar(0.1.dup) };
117 a[1] = \mix -> { Dust.ar(30.dup) };
122 section::Adding new roles
124 Roles can be added on the fly. They are kept in a dictionary ( strong::buildMethods:: ) in link::Classes/AbstractPlayControl::. A second dictionary ( strong::proxyControlClasses:: ) provides the wrapper class for a given key.
126 Here is a new role that allows you to set a control rate node proxy with the help of an event pattern. The new values are in a key named \value.
131 AbstractPlayControl.proxyControlClasses.put(\stream, PatternControl);
132 AbstractPlayControl.buildMethods.put(\stream,
133 #{ arg pattern, proxy, channelOffset=0, index;
137 \id, Pfunc { proxy.group.nodeID },
138 \array, Pkey(\value),
139 \out, Pfunc { proxy.index }
140 ).buildForProxy( proxy, channelOffset, index )
146 a = NodeProxy.control(s);
147 a.source = \stream -> Pbind(\value, Pseq([1, 2, 3], inf), \dur, 1.5).trace;
150 b.source = { SinOsc.ar([340, 440] * a.kr) * 0.1 };
153 a.source = \stream -> Pbind(\value, Pseq([1, 2, 3], inf) + Pwhite(0.0, 0.2, inf), \dur, 0.05);
154 b.source = { SinOsc.ar([5.6, 10.3] ** a.kr + 300) * 0.1 };