2 summary:: a reference to a value
7 A Ref holds an object which may be retrieved and altered with the messages value and value_(obj).
8 The backquote code:: ` :: is a unary operator that is equivalent to calling code::Ref.new(obj)::.
10 Refs are most commonly used to prevent multi-channel expansion in link::Classes/SynthDef::s and link::Classes/Pattern::s (see link::Classes/Klank:: for an example).
11 Refs can also be used to simplify the coding of co-routines used in EventStreams (see link::Classes/Proutine:: for an example).
16 z = obj.method(x); // method puts something in reference
17 x.value.doSomething; // retrieve value and use it
21 Ref is also used as a quoting device to protect against multi channel expansion in certain UGens that require Arrays.
27 create a Ref of an object.
39 Answer the value. This message is also defined in class Object where it just returns the receiver. Therefore anything.dereference will remove a Ref if there is one. This is slightly different than the value message, because value will also cause functions to evaluate themselves whereas dereference will not.
43 Answers the receiver. In class Object this message is defined to create a Ref of the object.
59 Returns code::value.at(index)::
62 Executes value.put(index, value)
66 this method is used to return values from within a Routine definition
70 { this.value = output.embedInStream(this.value); }
75 Returns the Ref - this prevents multi-channel expansion in a SynthDef
77 method::asControlInput
79 Returns the value - this is used when sending a Ref as a control value to a server Node.
81 section::Typical uses of Ref:
83 subsection::preventing multi-channel expansion
85 Consult link::Reference/MultiChannel:: for details on multi-channel expansion in SynthDefs.
87 Refs prevent multi-channel expansion in a SynthDef, so the array below defines one Klank UGen rather than three.
90 { Klank.ar(`[[800, 1071, 1153, 1723], nil, [1, 1, 1, 1]], Impulse.ar(2, 0, 0.1)) }.play;
93 Refs cannot be used reliably to suppress multi-channel expansion within Events and Patterns.
94 Instead, it is necessary to enclose the array of values in another array:
98 SynthDef(\multi, { | out, freq = #[100,200,300], amp = 0.1, pan = 0, sustain = 1|
100 env = EnvGen.kr(Env.perc(0.01, sustain), doneAction:2);
101 audio = Mix(Saw.ar(freq));
102 audio = Pan2.ar(audio * env, pan, amp);
103 OffsetOut.ar(out, audio)
106 ( instrument: \multi, freq: [ [500, 501, 700] ], sustain: 2).play
118 [[100, 100.1, 110] ],