PSdup Pattern which returns last values from other patterns via PSx


Part of: miSCellaneous


Inherits from: PS / PStream


See also: MemoRoutine, PSx stream patterns, PS, PSrecur



PSdup uses the storage functionality of other PSx patterns. To track a value stream or event stream from a pattern you'd have to wrap the pattern into a PSx.



Creation / Class Methods


*new (psxPat, length, bufSize, copyItems, copySets)

Creates a new PSdup object.

psxPat - Source pattern, must be a PSx pattern.

length - Number of output items, may be pattern or stream, defaults to inf.

bufSize - Size of buffer to store last values, defaults to 1.

copyItems - Determines if and how to copy the last items from psxPat's buffer

which are either non-Sets or member of Sets. 

Takes Integer 0 (or false or Symbol \false), 1 (or true or Symbol \true) or 2 (or Symbol \deep). 

Other values are interpreted as 0. Defaults to 0.

0: original item 

1: copy item

2: deepCopy item

copySets - Determines if and how to copy the last items from psxPat's buffer

which are Sets. 

Takes Integer 0 (or false or Symbol \false), 1 (or true or Symbol \true). 

Other values are interpreted as 0. Defaults to 1.

0: original Set 

1: copy Set

NOTE 1: The distinction of copying items and sets makes sense in the case of event streams.

Per default Events are copied (copySets == 1), not their values (copyItems == 0). 

By playing Events those are used to store additional data (synth ids, msgFuncs …) 

which is mostly not of interest when refering to the event stream, e.g. with PSx patterns which use 

MemoRoutine - copied Events will not contain this additional data. 

If values of Events or values returned directly by the stream (being no kind of Sets) are unstructured 

then copying makes no sense, this is the normal case, so copyItems defaults to 0.

When going to alter the ouput, you might want to set copyItems to 1 for a PSx returning 

simple arrays or 2 for nested arrays (deepCopy). For deepCopying Events you'd have to set

copySets to 1 and copyItems to 2 (an option copySets == 2 doesn't exist as

it would be contradictory in combination with copyItems < 2).


NOTE 2: Copy options concern copying into PSdup's buffer as well as 

the output of a Stream derived from the PSdup. When such a Stream is outputting copies 

this prevents unintended altering of items stored in the buffer of psxPat. On the other hand

storing copies in PSdup's buffer prevents these from being altered unintendedly.



Instance Methods


psxPat, psxPat_(value)

Instance variable getter and setter methods. 



Examples


(

s = Server.local;

Server.default = s;

s.boot;

)

// copying of value patterns

// PSdup needs a PSx as input, as its value storage is used,

// so it's easiest to wrap the original pattern into a PS


(

p = PS(Pseries());

q = PSdup(p);


// PSx patterns have a state and, in this regard, behave like Streams.

// However, like other Patterns, for generating they must be made to Streams 

// which are the objects actually returning items. 


x = p.asStream;

y = q.asStream;

)


// y follows x (as in the array left is evaluated before right) 


(

a = [];

10.do { a = a.add([x.next, y.next]) };

a;

)



// get values from original Pattern / Stream


x.nextN(10)


// now y copies the last value of x resp. p


y.nextN(10)




// data sharing with event patterns


(

p = Pbind(

\midinote, Pwhite(60, 90) + PLrand([0, 0, [0, -3]]),

\dur, PLrand([0.2, 0.4]),

\amp, PLrand([0.07, 0.12, 0.2]),

\type, Pfunc { 0.1.coin.if { \rest }{ \note } },

\pan, 1

);


q = PS(p);


// use PSdup as base for alterings

// it takes the last event stored in PS(p)


r = Pbindf(Padd(\midinote, PLrand([1,2,4,5]), PSdup(q)), \pan, -1);


// as in general with event stream data sharing it's recommended to invent a small delta 

// between streams, here this is extended to a clear echo 


t = Ptpar([0, q, 0.1, r]).trace.play;

)


t.stop;



// data sharing with event patterns, more voices 



(

p = Pbind(

\midinote, Pwhite(50.0, 65),

\dur, PLrand([0.7, 0.9, 1.2]),

\amp, PLrand([0.1, 0.15, 0.2]),

\legato, 0.1

);


q = PS(p);


// make pattern maker Function for parametrized alterings


f = { |div, add| Padd(\midinote, add, Pmul(\dur, 1 / div, PSdup(q))) };

d = 0.001;


t = Ptpar([

0, q, 

d, f.(2, 5 + PLrand([0, [0, 12.05]])),

d*2, f.(4, 7 + PLrand([0, [0, 12.1]])),

d*3, f.(8, 10 + PLrand([0, [0, 12.2]]))

]).play

)



t.stop;