SuperCollider CLASSES

Pif

Pattern-based conditional expression
Inherits from: Pattern : AbstractFunction : Object

Class Methods

*new (condition, iftrue, iffalse, default)

Arguments:

condition

A pattern or stream returning a Boolean value.

iftrue

This stream is evaluated if the Boolean is true.

iffalse

This stream is evaluated if the Boolean is false.

default

This value (not stream) is returned if "iftrue" or "iffalse" return nil at any time.

Inherited class methods

Instance Methods

Inherited instance methods

Undocumented instance methods

-asStream

-condition

-condition = value

-default

-default = value

-iffalse

-iffalse = value

-iftrue

-iftrue = value

Examples

p = Pif(Pfunc({ 0.3.coin }), Pwhite(0, 9, inf), Pwhite(100, 109, inf)).asStream;
p.nextN(20);

// 7 of the 20 values, or roughly 30%, are in the 0-9 range:

[ 105, 107, 107, 8, 100, 3, 105, 5, 107, 106, 1, 104, 8, 102, 102, 4, 108, 8, 109, 101 ]


// sound example
(
SynthDef(\help_sinegrain,
    { arg out=0, freq=440, sustain=0.05;
        var env;
        env = EnvGen.kr(Env.perc(0.01, sustain, 0.2), doneAction:2);
        Out.ar(out, SinOsc.ar(freq, 0, env))
    }).add;
)


(
var a;
a = Pif(Pfunc({ 0.3.coin }), Pn(Pseries(0.5, 0.1, 10)), Pn(Pseries(6, -0.1, 10))).asStream;
{
    loop {
        Synth(\help_sinegrain, [\freq, a.next * 600 + 300]);
        0.2.wait;
    }
}.fork;
)