Although PSloop is not a subclass of PStream, instances of PSloop have a state by storing a PStream of the source pattern in an instance variable. So the specific characteristics of PSx patterns are indirectly inherited by PSloop. This especially concerns the way to generate new, fresh PSloop streams, see examples in PSx_stream_patterns.
Note that impossible lookBack and indices values will be clipped, see descriptions of args bufSize, lookBack and indices.
Creates a new PSloop object.
srcPat |
Source pattern for looping, can be value or event pattern. |
length |
Number of output items, may be Pattern or Stream, defaults to inf. |
bufSize |
Integer size of buffer to store last values. Determines and clips the maximum lookBack index. Defaults to 1. |
lookBack |
Non-negative Integer determining the depth of looking backwards when looping, may be Pattern or Function also. Default 0 means going on with the Stream of the source pattern srcPat. If no indices is given, a positive Integer lookBack = n causes straight looping from the nth item in the past up to the last item of the Stream. If indices is given, an index array is produced by this function applied to lookBack = n. The array refers to the nth item in the past by array index 0. If lookBack values are derived from a Pattern or Function, they might be polled at the end of the loops or with every item, this is determined by the current value of doSkip. lookBack will be clipped by bufSize if it is greater than the latter. |
doSkip |
Integer or Boolean or: Function or Stream returning such. Determines if lookBack values are polled at the end of loops (0, false) or within loops (1, true) also. In the latter case a new lookBack value will stop the current loop and start a new one. Defaults to 1. |
loopFunc |
Function or Pattern returning Functions, to be applied to items of the loops. If Functions are streamed by passing a Function-generating Pattern loopFuncPerItem determines if a Function will be applied per item (1, true) or to all items of a loop (0, false). When loopFunc is nil or the loopFunc stream returns nil, no Function is applied. |
loopFuncPerItem |
Integer or Boolean or: Function or Stream returning such. If loopFunc is given, loopFuncPerItem determines if a Function will be applied per item (1, true) or to all items of a loop (0, false). |
loopFuncAsGoFunc |
Integer or Boolean or: Function or Stream returning such. Determines if loopFunc will be used for new items outside loops too (1, true). In this case goFunc is ignored (resp. nothing is polled from a goFunc stream) and nil values from the loopFunc stream are also taken over (no Function is applied outside loops then). |
goFunc |
Function or Pattern returning Functions, to be applied to new items outside loops. When goFunc is nil or the goFunc stream returns nil, no Function is applied. Note that goFunc has no effect when loopFuncAsGoFunc determines to use loopFunc generally. |
indices |
SequenceableCollection, Function, or Pattern returning SequenceableCollections or Functions. If no indices is passed (default nil) a positive Integer lookBack = n causes straight looping from the nth item in the past up to the last item of the Stream. A SequenceableCollection passed via indices is taken as array of indices and determines the items of the buffer, identifying the nth item in the past with array index 0. A Function passed via indices takes lookBack = n as argument and must return an index array which also determines the items of the buffer, identifying the nth item in the past with array index 0. A Pattern passed via indices should be defined to generate Functions or SequenceableCollections, which are interpreted in the same way as above. In case of a Pattern a new indices value is polled within a loop if current doSkip equals 1 or true. indices will be clipped by lookBack - 1, lookBack itself might be clipped by bufSize. |
copyItems |
Argument passed to the PS wrapper of srcPat. See PS. Determines if and how to copy items 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 |
Argument passed to the PS wrapper of srcPat. See PS. Determines if and how 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 PSrecur's buffer as well as the output of a Stream derived from the PSrecur. When such a Stream is outputting copies this prevents unintended altering of items stored in the buffer of PSrecur. On the other hand storing copies in PSrecur's buffer prevents these from being altered unintendedly. |
Instance variable getter and setter methods. psPat holds a Pstream with args srcPat, length, bufSize, copyItems, copySets.