PLswitch dynamic scope Pswitch variant
Part of: miSCellaneous
Inherits from: PL_Pattern
Takes Symbol args for later reference by the Streams, which will read from variables in the Environments of their instantiation. See PLx suite.
See also: Pswitch, PLswitch1, Event patterns and Functions, VarGui, VarGui shortcut builds
Creation / Class Methods
*new (list, which, cutItems, envir)
Creates a new PLswitch object.
list - Symbol or Pswitch list arg.
If a Symbol is passed, list can be assigned to an envir variable later on.
This lists's elements can be dynamically replaced by Patterns or Streams.
which - Symbol or Pswitch which arg. Defaults to 0.
If a Symbol is passed, which can be assigned to an envir variable later on.
Can be dynamically replaced by Patterns or Streams.
cutItems - Symbol or Boolean or Integer (0 or 1) or a Function returning Boolean or Integer.
If a Symbol is passed, cutItems can be assigned to an envir variable later on.
Determines if list items, which are Patterns or Streams themselves,
will be finished if a replacement occurs during their embedding, or if they will be replaced immediately.
The latter is the default behaviour (default value true).
For protecting whole lists from immediate replacements see PLn.
envir - Dictionary or one of the Symbols
\top, \t (topEnvironment), \current, \c (currentEnvironment).
Dictionary to be taken for variable reference. Defaults to \current.
Examples
(
s = Server.local;
Server.default = s;
s.boot;
)
// definition for future reference in arbitrary Environments
p = PLswitch(\a, \w);
// define array
// PLseq defaults to repeats = inf
(
~a = (70..75) ++ Pshuf((85..80), 2) ++ Pseq((90..94));
~w = PLseq((0..7));
x = Pbind(\midinote, p, \dur, 0.1).play;
)
// update array element
~a[2] = Pseq([86, 85], 2) + [0, 3];
// reverse index pattern
~w = PLseq((7..0));
// keep in mind that indices are wrapped, no surprise here ...
~a = (70,72..84);
// ... but with shorter array indices are grouped in 5 + 3
~a = (70,72..78);
x.stop;
//////////////////////
// placeholder may also get lists of event patterns
(
p = PLswitch(\a, \w);
~a = [
Pbind(
\midinote, Pwhite(60, 65, 3),
\dur, 0.2
),
Pbind(
\midinote, Pwhite(70, 75, 3),
\dur, 0.15
),
Pbind(
\midinote, Pwhite(80, 85, 3),
\dur, 0.1
),
Pbind(
\midinote, Pwhite(90, 95, 6),
\dur, 0.05
)
];
~w = PLseq((0..3));
x = p.play;
)
// replace index sequence
~w = PLseq([3, 0]);
~w = PLseq([1, 2]);
// replace array element
(
~a[2] = Pbind(
\midinote, Pwhite(70, 75, 3) + [0, 5],
\dur, 0.15
);
)
// replace whole array
(
~a = [ Pbind(
\midinote, Pwhite(60, 65, 3) + [0, 5],
\dur, 0.15
),
Pbind(
\midinote, Pwhite(70, 80, 2) + [0, 4],
\dur, 0.25
),
Pbind(
\midinote, Pwhite(95, 100, 6) + [0, -9],
\dur, 0.05
)
];
)
x.stop;