1class:: PlazyEnvirN 2summary:: instantiate new patterns from a function and multichannel expand them 3related:: Classes/Plazy, Classes/PlazyEnvir, Classes/Pfunc 4categories:: Streams-Patterns-Events>Patterns>Function 5 6description:: 7 8Evaluates a function that returns a pattern and embeds it in a stream. 9list:: 10## In difference to link::Classes/Plazy::, the function is evaluated using the environment passed in by the stream. 11## In difference to link::Classes/PlazyEnvir::, PlayzEnvirN expands to strong::multiple parallel patterns:: if the function arguments receive multiple channels. This works only with event streams. 12:: 13 14ClassMethods:: 15 16method::new 17 18argument::func 19A link::Classes/Function:: that returns a pattern or any other valid pattern input. 20 21code:: 22( 23f = { arg g=0, h=0, dur=1; 24 Pbind(\degree, Pseq([g, g, h, g, h], 2), \dur, Pseries(dur, 0.1)) 25}; 26// compare: 27a = Pchain(PlazyEnvirN(f), (g: [1, 2], h: 3, dur:0.2)).trace(\degree).asStream; 28c = Pchain(Plazy(f), (g: [1, 2], h: 3, dur:0.2)).asStream; 29) 30 31a.nextN(4); 32c.nextN(4); // no degrees, because stream ends 33:: 34 35 36Examples:: 37 38code:: 39( 40SynthDef(\help_sinegrain, 41 { arg out=0, freq=440, sustain=0.05, pan=0; 42 var env; 43 env = EnvGen.kr(Env.perc(0.01, sustain, 0.2), doneAction: Done.freeSelf); 44 Out.ar(out, Pan2.ar(SinOsc.ar(freq, 0, env), pan)) 45 }).add; 46 47a = PlazyEnvirN({ arg g=0, h=0, dur=1; 48 postf("g: %, h: %, dur: %\n", g, h, dur); 49 50 Pbind( 51 \instrument, \help_sinegrain, 52 \dur, dur, 53 \degree, Pseq([g, g, h, g, h], 2) 54 ) 55}); 56) 57 58// different variants 59(a <> (g: 0, h: 3, dur:0.2)).play; // single stream 60(a <> (g: [0, 4], h: [3, -1], dur:0.2)).play; // same durations, two streams 61(a <> (g: [0, 4], h: [3, -1], dur: [0.2, 0.3])).play; // different durations, two streams 62:: 63 64For more about the composition operator code::<>:: see: link::Classes/Pchain::. 65