PS:
Filter:
miSCellaneous_lib/Classes (extension) | Libraries > miSCellaneous > PSx stream patterns | Streams-Patterns-Events > PSx stream patterns

PS
ExtensionExtension

Pattern that behaves like a Stream

Description

In general Patterns are stateless. But e.g. for counted embedding in other Patterns the exception of stream-like behaviour is practical. PS might also be used in cases where Streams must not be passed to certain Patterns.

NOTE: Name and implementation of former Pstream has changed with miSCellaneous_v0.9, in compliance with other PSx patterns it's been renamed to PS / PStream, however for backwards compatibility Pstream will still work by subclassing.

Class Methods

.new

Creates a new PS object.

Arguments:

srcPat

Source pattern, might also be event 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 items, which are 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 to copy Sets (and hence Events). 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: 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: Copy options concern copying into PS's buffer as well as the output of a Stream derived from the PS. When such a Stream is outputting copies this prevents unintended altering of items from srcPat. On the other hand storing copies in PS's buffer prevents these from being altered unintendedly.

Instance Methods

.lastValue

Last value stored in memoRoutine

.lastValues

Array of last values stored in memoRoutine, latest value is first in array.

.at

Returns ith item of array of last values stored in memoRoutine (keep in mind reversed order: last value first)

.bufSize

Size of array of last values.

.srcPat

Instance variable getter and setter methods.

.length

Instance variable getter and setter methods.

.lengthStream

Instance variable getter and setter methods.

.memoRoutine

Instance variable getter and setter methods.

.count

Instance variable getter and setter methods. Counts each call of next / value / resume / run on the memoRoutine. If several Streams are derived from one PS each call of next on a derived Stream will be counted by the memoRoutine and thus by the PS.

.bufSeq

Returns items of the array lastValues, but in the order in which they appeared, i.e. latest value is first in array.

Arguments:

dropNils

Boolean. If dropNils is true (default), nils will be rejected from the array.

Examples

NOTE: Repeated streamifying of a PS is just like resuming a Stream (yes, PS behaves like ... a Stream). For getting a Stream to start at the beginning as defined by the Pattern enclosed by the PS, you'd have to generate a new PS, e.g. by reevaluating its definition or wrapping it into a Function.