Classes | Libraries > JITLib > Patterns | Live Coding

PatternProxy : Pattern : AbstractFunction : Object

stream reference
Source: Pdef.sc
Subclasses: Pdefn, TaskProxy

Description

Keeps a reference to a stream that can be replaced while playing. Multiple streams are thus handled without creating dependencies.

Class Methods

PatternProxy.new(source)

create a new instance with a pattern (the source). the pattern should be a value pattern (see Pdefn).

for event pattern proxy, see: EventPatternProxy. instead of a pattern, a function can be passed in, creating a routine.

PatternProxy.default

a default source, if none is given. the default is 1.0 (it is not 0.0 in order to make it safe for durations)

PatternProxy.defaultQuant

PatternProxy.defaultQuant = value

set the default quantization value for the class. (default: nil)

PatternProxy.defaultValue

a default return value, if no source is given. the default is 1.0 (it is not 0.0 in order to make it safe for durations). This is used in -endless.

Inherited class methods

Instance Methods

.asStream

Return a Stream from this pattern. One pattern proxy can be used to produce any number of independent streams.

a = PatternProxy.new;
a.source = Pgeom(1, Pwhite(1.01, 1.2), inf);
b = a.asStream; c = a.asStream;

b.next;
b.next;
b.next;

c.next; // c is independent from b
c.next;

a.source = Pgeom([1, 2, 3], Pwhite(1.01, 1.2), inf); // replace the source

b.next;
c.next;

.embedInStream(inval, embed: true, default)

Given a Stream like e.g. Routine, yield all values from the pattern in the proxy before continuing. One pattern proxy can be used to produce values for any number of independent streams.

Arguments:

inval

The inval is passed into all substreams and can be used to control how they behave from the outside.

embed

See Object: -streamArg for explanation.

default

Replacement for nil outputs of the source pattern. One use case is -endless.

a = PatternProxy.new;
a.source = Pgeom(1, Pwhite(1.01, 1.2), 4);
r = Routine { loop { 2.yield; 3.yield; a.embedInStream }; };
r.nextN(12); // the next 12 values from r
a.source = Pgeom([1, 2, 3], Pwhite(1.01, 1.2), inf); // replace the source
r.nextN(12); // the next 12 values from r

.source

.source = obj

set the source. If a quantization is given, schedule this change to the next beat

.clear

set the source to nil

.quant

.quant = val

set or get the quantization value

.condition

.condition = value

provide a condition under which the pattern is switched when a new one is inserted. the stream value and a count is passed into the function. the methods count_(n) simply counts up to n and switches the pattern then

.embedInStream(inval, embed: true, default)

just like any pattern, embeds itself in stream

Methods implemented for subclasses

PatternProxy implements some methods for the benefits of its subclasses Pdefn / Pdef / Tdef which are not useful for PatternProxy and TaskProxy.

.envir

.envir = value

provide a default environment for the proxy. If given, it is used as an environment for the routine function. When set for the first time, the routine pattern is rebuilt.

.set( ... args)

set arguments in the environment. If there is none, it is created and the pattern is rebuilt.

.endless(default)

returns a Prout that plays the proxy endlessly, replacing nil with a default value (1). This allows to create streams that idle on until a new pattern is inserted.

Inherited instance methods

Undocumented instance methods

.asCode

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/Patterns/extPostAsCode.sc

.buildForProxy

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.clock

.clock = value

.constrainStream(stream, newStream)

.convertFunction(func)

.copy

.copyState(proxy)

.count(n: 1)

.defaultEvent

.embed(val)

.get(key)

.isEventPattern

.pattern

.pattern = pat

.phase

.phase = val

.place( ... args)

.quantBeat

.quantBeat = val

.receiveEvent

.remove

.repositoryArgs

.reset

.sched(func)

.setSource(obj)

.softSet(param, val, within: 0.025, mapped: true, lastVal, spec)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/GUI/extSoftSet.sc

.timingOffset

.timingOffset = val

.unset( ... args)

Examples

a = PatternProxy(Pseq([1, 2, 3], inf));

x = Pseq([0, 0, a], inf).asStream;

t = Task({ loop({ x.next.postln; 0.3.wait }) }).play;


a.source = Pseq([55, 66, 77], inf);
a.source = Pseq([55, 66, 77], 1);

t.stop;
// PatternProxy, like Pdefn can be accessed in multiple streams

(
SynthDef("Pdefhelp", { arg out, freq, sustain=1, amp=1, pan;
    var env, u=1;
    env = EnvGen.kr(Env.perc(0.03, sustain), 1, doneAction: Done.freeSelf);
    5.do { var d; d = exprand(0.01, 1); u = SinOsc.ar(d * 300, u, rrand(0.1,1.2) * d, 1) };
    Out.ar(out, Pan2.ar(SinOsc.ar(u + 1 * freq, 0, amp * env), pan));

}).add;
s.boot;
)

(
x = PatternProxy.new;
x.source = Pseq([0, 3, 2], inf);

Pset(\instrument, \Pdefhelp,
    Ppar([
    Pbind(\degree, x),
    Pbind(\degree, x, \dur, 1/3)
])
).play;
)

x.source = Prand([0, 3, [1s, 4]], inf);

x.source = Pn(Pshuf([0, 3, 2, 7, 6], 2), inf);



// if quant is set, the update is done at the next beat or whatever is specified:

x.quant = 4;
x.source = Pn(Pseries(0, 1, 8), inf);

x.quant = nil; // reactivate immediacy

(
x.source = Prout {
    loop {
    4.do { |i|
        #[2, 3, 4].choose.yield;
        #[5, 0, 11].choose.yield;
        #[6, 3, 4].choose.do { |j| (i % j).yield };
    }
    }
}
)