Pstream Pattern that behaves like a Stream 


Part of: miSCellaneous


Inherits from: Plazy


In general Patterns are stateless. But e.g. for counted embedding in other Patterns the exception of stream-like behaviour is practical.

Pstream may also be used in cases where Streams must not be passed to certain Patterns.



Creation / Class Methods


*new (src, length)

Creates a new Pstream object.

src - source pattern, may also be event pattern

length - number of output items, may be pattern or stream.


Examples


(

s = Server.local;

Server.default = s;

s.boot;

)

// PLx variants default to repeats = inf


(

p = PLseq([ 

Pstream(PLrand((60..65)), 3), 

Pstream(PLrand((80..90)), Pwhite(2,5)) 

]); 


x = Pbind(

\midinote, p,

\dur, 0.1

).play;

)


x.stop;



// with event patterns


(

p = Pbind(

\midinote, PLshuf((55..70)) + Pfunc { [0, [4,5].choose] },

\dur, 0.2

);


q = Pbind(

\midinote, PLshuf((80..100)),

\dur, 0.05

);


x = PLseq([

Pstream(p, Pwhite(2,6)), 

Pstream(q, Pwhite(2,6)) 

]).play;

)


x.stop;



Keep in mind that repeated streamifying of a Pstream is just like resuming a Stream (yes, Pstream behaves like ... a Stream).

For getting a fresh Stream you'd have to generate a new Pstream.



p = Pstream(Pseries(), 5);


// evaluate more than once


p.asStream.all;