Ref:
Filter:
Classes | Core

Ref : AbstractFunction : Object

a reference to a value
Source: Ref.sc
Subclasses: Maybe, RefCopy

Description

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 Ref.new(obj).

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 Prout for an example).

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

Class Methods

Ref.new(thing)

create a Ref of an object.

Discussion:

Another syntax:

Inherited class methods

Instance Methods

.dereference

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.

.asRef

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

.value

.value = value

Get or set the value.

.get

Returns value.

.set(thing)

Sets value.

.at(key)

Returns value.at(index)

.put(key, val)

Executes value.put(index, value)

.seq(pat)

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

Discussion:

.asUGenInput

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

.asControlInput

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

Inherited instance methods

Undocumented instance methods

.asBufWithValues

.asOSCArgEmbeddedArray(array)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extConvertToOSC.sc

.multichannelExpandRef(rank)

.next

.valueArray

.valueArrayEnvir

.valueEnvir

Typical uses of Ref:

preventing multi-channel expansion

Consult Multichannel Expansion 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.

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:

multichannelExpandRef

This method is called internally on inputs to UGens that take multidimensional arrays, like Klank and it allows proper multichannel expansion even in those cases. For SequenceableCollection, this returns the collection itself, assuming that it contains already a number of Refs.

Arguments:

rank

The depth at which the list is expanded. For instance the Klank spec has a rank of 2.