Ref a reference to a value

superclass: AbstractFunction

A Ref holds an object which may be retrieved and altered with the messages value and value_(obj).   

The backquote ` is a unary operator that is equivalent to calling

Refs are most commonly used to prevent multi-channel expansion in SynthDefs and Patterns (see Klank for an example).

Refs can also be used to simplify the coding of co-routines used in EventStreams (see Proutine for an example).


x = Ref(nil);

z = obj.method(x); // method puts something in reference

x.value.doSomething; // retrieve value and use it

Ref is also used as a quoting device to protect against multi channel expansion in certain UGens that require Arrays.

Class methods:


create a Ref of an object.


create a Ref of an object.

Instance methods:


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.


Answers the receiver. In class Object this message is defined to create a Ref of the object.


Returns value.


Sets value.


Returns value.


Sets value.

at (index)


put(index, value)

Executes value.put(index, value)


this method is used to return values from within a Routine definition

{ this.value = output.embedInStream(this.value); }


Returns the Ref - this prevents multi-channel expansion in a SynthDef


Returns the value - this is used when sending a Ref as a control value to a server Node.

Typical uses of Ref:

preventing multi-channel expansion:

Consult MultiChannel for details on multi-channel expansion in SynthDefs.

Refs prevent multi-channel expansion in a SynthDef, so the array below defines one Klank UGen rather than three.

{`[[800, 1071, 1153, 1723], nil, [1, 1, 1, 1]],, 0, 0.1)) }.play;

Refs cannot be used reliably to suppress multi-channel expansion within Events and Patterns.  

Instead, it is necessary to enclose the array of values in another array:


SynthDef(\multi, { | out, freq = #[100,200,300], amp = 0.1, pan = 0, sustain = 1|

var audio, env;

env =, sustain), doneAction:2);

audio = Mix(;

audio = * env, pan, amp);, audio)


( instrument: \multi, freq: [ [500, 501, 700] ], sustain: 2).play




instrument: \multi,

freq: Prand([ 

[[100, 141, 103] ], 

[[100, 310, 190] ], 

[[100, 100.1, 110] ], 

], inf),

dur: 0.2,

sustain: 0.3