Rest:
Filter:

Rest : Operand : AbstractFunction : Object

Represents a rest in event patterns
Source: Rest.sc

Description

A Rest may be used in event patterns to indicate that the resulting event should be a rest (i.e., silent). It should be used in one of the child patterns belonging to a Pbind, for instance.

// do nothing for 2 seconds
(note:Rest(), dur:2).play;

// intersperse pauses in pattern
Pbind(\note, Pseq([0, 4, 7, 11], inf), \dur, Pseq([2, 1, Rest(1)], inf) / 5).play;

Expressing rests in event patterns

The Rest class allows rests to be indicated in any stream, not only frequency or event type. Also, using the duration argument (see the *new method below), rests may be embedded into a duration stream. That is, rests may be treated as part of the rhythmic specification, rather than the pitch specification.

NOTE: As of SuperCollider 3.9, Rest's behavior has changed to be more intuitive. Note that you have to now use Rest() - the shortcut of Rest as class directly is not supported anymore.

Usage

Class Methods

All methods of Rest except *new are private, and should not be used directly.

Rest.new(value: 1)

Create an instance of Rest, with a value to be used in the resulting rest event.

Arguments:

value

The Rest instance's numeric value, to be used in math operations. Note that a Rest's value is ignored for most Event keys (assuming the Event does nothing in response to .play). If a Rest appears in a rhythm key (dur or delta), then the number is the time until the next event. Consequently, numeric Rests are often used for duration -- but there is no requirement that a Rest's value must be a duration.

Discussion:

a = Rest(6);
b = a * 2; // returns Rest(12)
b = 2 * a; // the same
b.value; // returns 12

The rest of a rest is always a rest. This idempotence is implemented by Rest's superclass Operand.

Rest(Rest(1)) // returns Rest(1)

Inherited class methods

Instance Methods

.isRest

returns true

.unwrapBoolean

returns the value.

Discussion:

This method implements the following behavior.

Rest(6) + 1 // Rest(7)
Rest(true) // true

This makes comparisons work:

Rest(6) < 7 // true, and not Rest(true)
a = Pseq([1, 2, 1, 3, Rest(1), 2, Rest(3)], inf); // e.g. as a duration pattern
b = a.collect { |x| if(x > 2) { x / 2 } { x } };
b.asStream.nextN(8)

Inherited instance methods

Examples

Using Rest instances in a pitch stream

(
Pbind(
    \degree, Pif(
        0.1.loop.coin,
        Pseq([Rest(), 7], inf), // every second is a Rest
        Pseries(0, 1, inf).fold(-7, 7)
    ),
    \dur, 0.125
).play
)

Using a Rest instance in a duration stream

(
Pbind(
    \degree, Pseries(0, 1, inf).fold(-7, 7),
    \dur, Pseq([Pn(0.125, { rrand(3, 6) }), Rest(0.25)], inf)
).play
)

Alternatives to Rest

In addition to Rest, in events, rests can be specified in two other ways (legacy usages).