1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.44">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
; min-height: 22.0px}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
; min-height: 16.0px}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0000bf}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000; min-height: 12.0px}
20 p
.p11
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
21 p
.p12
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
22 p
.p13
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0000ff}
23 span
.s1
{color: #007300}
24 span
.s2
{color: #0000bf}
25 span
.s3
{color: #000000}
26 span
.s4
{color: #bf0000}
27 span
.s5
{color: #606060}
28 span
.Apple-tab-span
{white-space:pre
}
32 <p class=
"p1"><br></p>
33 <p class=
"p2"><b>Understanding Streams, Patterns and Events - Part
4</b></p>
34 <p class=
"p1"><br></p>
35 <p class=
"p3">The preceeding sections showed how to use Streams and Patterns to generate complex sequences of values for a single parameter at a time.
</p>
36 <p class=
"p4"><br></p>
37 <p class=
"p3">This section covers Environments and Events, which are used to build a symbolic event framework for patterns, allowing you to control all aspects of a composition using patterns.
</p>
38 <p class=
"p4"><br></p>
39 <p class=
"p5"><b>Environment
</b></p>
40 <p class=
"p4"><br></p>
41 <p class=
"p3">An Environment is an IdentityDictionary mapping Symbols to values. There is always one current Environment which is stored in the currentEnvironment class variable of class Object.
</p>
42 <p class=
"p4"><br></p>
43 <p class=
"p3">Symbol and value pairs may be put into the current Environment as follows:
</p>
44 <p class=
"p4"><br></p>
45 <p class=
"p6">currentEnvironment.put(
<span class=
"s1">\myvariable
</span>,
999);
</p>
46 <p class=
"p4"><br></p>
47 <p class=
"p3">and retrieved from the current Environment as follows:
</p>
48 <p class=
"p4"><br></p>
49 <p class=
"p6">currentEnvironment.at(
<span class=
"s1">\myvariable
</span>).postln;
</p>
50 <p class=
"p7"><br></p>
51 <p class=
"p3">The compiler provides a shorthand for the two constructs above .
</p>
52 <p class=
"p4"><br></p>
53 <p class=
"p6">~myvariable =
888;
</p>
54 <p class=
"p4"><br></p>
55 <p class=
"p3">is equivalent to:
</p>
56 <p class=
"p4"><br></p>
57 <p class=
"p6">currentEnvironment.put(
<span class=
"s1">\myvariable
</span>,
888);
</p>
58 <p class=
"p4"><br></p>
59 <p class=
"p3">and:
</p>
60 <p class=
"p4"><br></p>
61 <p class=
"p6">~myvariable.postln;
</p>
62 <p class=
"p7"><br></p>
63 <p class=
"p3">is equivalent to:
</p>
64 <p class=
"p4"><span class=
"Apple-converted-space"> </span></p>
65 <p class=
"p6">currentEnvironment.at(
<span class=
"s1">\myvariable
</span>).postln;
</p>
66 <p class=
"p7"><br></p>
67 <p class=
"p8"><b>Making an Environment
</b></p>
68 <p class=
"p4"><br></p>
69 <p class=
"p3">Environment has a class method
<b>make
</b> which can be used to create an Environment and fill it with values. What
<b>make
</b> does is temporarily replace the current Environment with a new one, call your function where you fill the Environment with values, then it replaces the previous current Environment and returns you the new one.
</p>
70 <p class=
"p4"><br></p>
72 <p class=
"p6"><span class=
"s2">var
</span> a;
</p>
73 <p class=
"p6">a =
<span class=
"s2">Environment
</span>.make({
</p>
74 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~a =
100;
</p>
75 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~b =
200;
</p>
76 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~c =
300;
</p>
78 <p class=
"p6">a.postln;
</p>
80 <p class=
"p4"><br></p>
81 <p class=
"p8"><b>Using an Environment
</b></p>
82 <p class=
"p4"><br></p>
83 <p class=
"p3">The instance method
<b>use
</b> lets you temporarily replace the current Environment with one you have made. The
<b>use
</b> method returns the result of your function instead of the Environment like
<b>make
</b> does.
</p>
84 <p class=
"p4"><br></p>
86 <p class=
"p6"><span class=
"s2">var
</span> a;
</p>
87 <p class=
"p6">a =
<span class=
"s2">Environment
</span>.make({
</p>
88 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~a =
10;
</p>
89 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~b =
200;
</p>
90 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~c =
3000;
</p>
92 <p class=
"p6">a.use({
</p>
93 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~a + ~b + ~c
</p>
94 <p class=
"p6">}).postln;
</p>
96 <p class=
"p4"><br></p>
97 <p class=
"p3">There is also a
<b>use
</b> class method for when you want to make and use the result from an Environment directly.
</p>
98 <p class=
"p4"><br></p>
100 <p class=
"p6"><span class=
"s2">var
</span> a;
</p>
101 <p class=
"p9"><span class=
"s3">a =
</span>Environment
<span class=
"s3">.use({
</span></p>
102 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~a =
10;
</p>
103 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~b =
200;
</p>
104 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~c =
3000;
</p>
105 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~a + ~b + ~c
</p>
106 <p class=
"p6">}).postln;
</p>
108 <p class=
"p4"><br></p>
109 <p class=
"p8"><b>Calling Functions with arguments from the current Environment
</b></p>
110 <p class=
"p4"><br></p>
111 <p class=
"p3">It is possible to call a Function and have it look up any unspecified argument values from the current Environment. This is done with the
<b>valueEnvir
</b> and
<b>valueArrayEnvir
</b> methods. These methods will, for any unspecified argument value, look in the current Environment for a symbol with the same name as the argument. If the argument is not found then whatever the function defines as the default value for that argument is used.
</p>
112 <p class=
"p4"><br></p>
114 <p class=
"p6"><span class=
"s2">var
</span> f;
</p>
115 <p class=
"p10"><br></p>
116 <p class=
"p11">// define a function
</p>
117 <p class=
"p6">f = {
<span class=
"s2">arg
</span> x, y, z; [x, y, z].postln; };
</p>
118 <p class=
"p10"><br></p>
119 <p class=
"p9">Environment
<span class=
"s3">.use({
</span></p>
120 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~x =
7;
</p>
121 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~y =
8;
</p>
122 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~z =
9;
</p>
123 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
124 <p class=
"p6"><span class=
"Apple-tab-span"> </span>f.valueEnvir(
1,
2,
3);
<span class=
"Apple-tab-span"> </span><span class=
"s4">// all values supplied
</span></p>
125 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span>f.valueEnvir(
1,
2);
<span class=
"Apple-tab-span"> </span></span>// z is looked up in the current Environment
</p>
126 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span>f.valueEnvir(
1);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// y and z are looked up in the current Environment
<span class=
"Apple-converted-space"> </span></p>
127 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span>f.valueEnvir;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// all arguments are looked up in the current Environment
</p>
128 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span>f.valueEnvir(z:
1);
<span class=
"Apple-tab-span"> </span></span>// x and y are looked up in the current Environment
</p>
129 <p class=
"p6">});
</p>
131 <p class=
"p7"><br></p>
132 <p class=
"p3">Here is a somewhat contrived example of how the Environment might be used to manufacture SynthDefs.
</p>
133 <p class=
"p3">Even though the three functions below have the freq, amp and pan args declared in different orders it does not matter, because valueEnvir looks them up in the environment.
<span class=
"Apple-converted-space"> </span></p>
134 <p class=
"p4"><br></p>
136 <p class=
"p6"><span class=
"s2">var
</span> a, b, c, n;
</p>
137 <p class=
"p10"><br></p>
138 <p class=
"p6">n =
40;
</p>
139 <p class=
"p6">a = {
<span class=
"s2">arg
</span> freq, amp, pan;
</p>
140 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s2">Pan2
</span>.ar(
<span class=
"s2">SinOsc
</span>.ar(freq), pan, amp);
</p>
142 <p class=
"p6">b =
<span class=
"Apple-converted-space"> </span>{
<span class=
"s2">arg
</span> amp, pan, freq;
</p>
143 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s2">Pan2
</span>.ar(
<span class=
"s2">RLPF
</span>.ar(
<span class=
"s2">Saw
</span>.ar(freq), freq *
6,
0.1), pan, amp);
</p>
145 <p class=
"p6">c =
<span class=
"Apple-converted-space"> </span>{
<span class=
"s2">arg
</span> pan, freq, amp;
</p>
146 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s2">Pan2
</span>.ar(
<span class=
"s2">Resonz
</span>.ar(
<span class=
"s2">GrayNoise
</span>.ar, freq *
2,
0.1), pan, amp *
2);
</p>
148 <p class=
"p10"><br></p>
149 <p class=
"p9">Task
<span class=
"s3">({
</span></p>
150 <p class=
"p6"><span class=
"Apple-tab-span"> </span>n.do({
<span class=
"s2">arg
</span> i;
</p>
151 <p class=
"p12"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span><span class=
"s2">SynthDef
</span><span class=
"s3">(
</span>"Help-SPE4-EnvirDef-"<span class=
"s3"> ++ i.asString, {
</span></p>
152 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span> out;
</p>
153 <p class=
"p9"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>Environment
<span class=
"s3">.use({
</span></p>
154 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// set values in the environment
</p>
155 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~freq = exprand(
80,
600);
</p>
156 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp =
0.1 +
0.3.rand;
</p>
157 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~pan =
1.0.rand2;
</p>
158 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
159 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// call a randomly chosen instrument function
<span class=
"Apple-converted-space"> </span></p>
160 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// with values from the environment
</p>
161 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>out = [a,b,c].choose.valueEnvir;
</p>
162 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
163 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>out =
<span class=
"s2">CombC
</span>.ar(out,
0.2,
0.2,
3,
1, out);
</p>
164 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>out = out *
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"Apple-converted-space"> </span></p>
165 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Env
</span>.sine, doneAction:
2, timeScale:
1.0 +
6.0.rand, levelScale:
0.3<span class=
"Apple-converted-space"> </span></p>
166 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>);
</p>
167 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(
0, out );
</p>
168 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}).send(s);
</p>
169 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>0.02.wait;
</p>
170 <p class=
"p6"><span class=
"Apple-tab-span"> </span>});
</p>
171 <p class=
"p6"><span class=
"Apple-tab-span"> </span>loop({
</p>
172 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Synth
</span>(
<span class=
"s5">"Help-SPE4-EnvirDef-"</span> ++ n.rand.asString );
</p>
173 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(
0.5 +
2.0.rand).wait;
</p>
174 <p class=
"p6"><span class=
"Apple-tab-span"> </span>});
</p>
175 <p class=
"p6">}).play;
</p>
177 <p class=
"p4"><br></p>
178 <p class=
"p1"><br></p>
179 <p class=
"p2"><b>Event
</b></p>
180 <p class=
"p4"><br></p>
181 <p class=
"p3">The class Event is a subclass of Environment. Events are mappings of Symbols representing names of parameters for a musical event to their value. This lets you put any information you want into an event.
<span class=
"Apple-converted-space"> </span></p>
182 <p class=
"p4"><br></p>
183 <p class=
"p3">The class getter method
<b>default
</b> retrieves the default prototype event which has been initialized with values for many useful parameters. It represents only one possible event model. You are free to create your own, however it would be good to understand the one provided first so that you can see what can be done.
</p>
184 <p class=
"p4"><br></p>
185 <p class=
"p3">A prototype event is a default event which will be transformed by the streams returned by patterns. Compositions produced by event patterns are created entirely from transformations of copies of a single protoEvent.
</p>
186 <p class=
"p4"><br></p>
187 <p class=
"p3"><i>It's all a part of the Big Note, but don't tell the pigs and ponies.
</i></p>
188 <p class=
"p4"><br></p>
189 <p class=
"p8"><b>Value Patterns, Event Patterns and Pbind
</b></p>
190 <p class=
"p4"><br></p>
191 <p class=
"p3">The patterns discussed in parts
2 and
3 are known as
"value patterns" because their streams return a single value for each call to
<b>next
</b>. Here we introduce
"event patterns" which once turned into streams, return an Event for each call to
<b>next
</b>.
</p>
192 <p class=
"p4"><br></p>
193 <p class=
"p3">The class
<b>Pbind
</b> provides a bridge between value patterns and event patterns. It binds symbols in each event to values obtained from a pattern. Pbind takes arguments in pairs, the first of a pair being a Symbol and the second being a value Pattern. Any object can act as a Pattern, so you can use constants as the pattern ( see \amp in the example below ).
</p>
194 <p class=
"p4"><br></p>
195 <p class=
"p3">The Pbind stream returns nil whenever the first one of its streams ends.
</p>
196 <p class=
"p7"><br></p>
197 <p class=
"p6"><span class=
"s2">Pbind
</span>(
<span class=
"s1">\freq
</span>,
<span class=
"s2">Pseq
</span>([
440,
880]) ).play
</p>
198 <p class=
"p4"><br></p>
199 <p class=
"p3">An event stream is created for a Pattern by sending it the
<b>asStream
</b> message. What Pbind does is to produce a stream which puts the values for its symbols into the event, possibly overwriting previous bindings to those symbols:
</p>
200 <p class=
"p4"><br></p>
201 <p class=
"p6">t
<span class=
"Apple-converted-space"> </span>=
<span class=
"Apple-converted-space"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\freq
</span>,
<span class=
"s2">Pseq
</span>([
440,
880]) ).asStream;
</p>
202 <p class=
"p6">t.next(
<span class=
"s2">Event
</span>.default);
</p>
203 <p class=
"p6">t.next(
<span class=
"s2">Event
</span>.default);
</p>
204 <p class=
"p6">t.next(
<span class=
"s2">Event
</span>.default);
</p>
205 <p class=
"p4"><br></p>
206 <p class=
"p3">When calling Pattern-play an EventStreamPlayer is automatically generated which handles scheduling as well as passing the protoEvent into the event stream.
</p>
207 <p class=
"p4"><br></p>
208 <p class=
"p8"><b>EventStreamPlayer
</b></p>
209 <p class=
"p4"><br></p>
210 <p class=
"p3"><b>EventStreamPlayer
</b> is a subclass of
<b>PauseStream
</b>. A PauseStream is just a wrapper for a stream allowing
<span class=
"Apple-converted-space"> </span>to play, stop, start it, etc...
<span class=
"Apple-converted-space"> </span></p>
211 <p class=
"p4"><br></p>
212 <p class=
"p3">EventStreamPlayers are initialized using the event stream returned by Pbind-asStream, as well as with a protoEvent. The EventStreamPlayer passes in a
<b>protoEvent
</b>, at each call to
<b>next
</b> on the Pbind stream. The Pbind stream copies the event to pass down and back up the tree of pattern streams so that each stream can modify it.
</p>
213 <p class=
"p4"><br></p>
214 <p class=
"p3">An EventStreamPlayer is itself a stream which returns scalars (numbers) which are used by the clock to schedule its next invocation. At every call to EventStreamPlayer-next by the clock, the player gets its delta values by querying the Event after it has been returned by the Pbind stream traversal.
<span class=
"Apple-converted-space"> </span></p>
215 <p class=
"p4"><br></p>
216 <p class=
"p4"><br></p>
217 <p class=
"p3"><b>Changes in SC3
</b></p>
218 <p class=
"p4"><br></p>
219 <p class=
"p3">In SC2, you called asEventStream on an Pattern and you'd get a stream which actually returned events.
</p>
220 <p class=
"p4"><br></p>
221 <p class=
"p3">In SC3, if you want an event stream proper you call asStream on the Event Pattern. This will give you a stream of events which you can then use to initialize an EventStreamPlayer object. You don't however need to worry about that because it is usually done for you in Pattern's play method. Also changed is that you do not pass
</p>
222 <p class=
"p3">in your protoEvent through the asStream method. It is passed in for you by the EventStreamPlayer at each call
</p>
223 <p class=
"p3">to next on the stream.
</p>
224 <p class=
"p4"><br></p>
225 <p class=
"p3">Here you can see what the stream returned from a Pbind looks like.
</p>
226 <p class=
"p4"><br></p>
228 <p class=
"p6"><span class=
"s2">var
</span> pattern, stream;
</p>
229 <p class=
"p10"><br></p>
230 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>// bind Symbol xyz to values obtained from a pattern
</p>
231 <p class=
"p6">pattern =
<span class=
"s2">Pbind
</span>(
<span class=
"Apple-converted-space"> </span></p>
232 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s1">\xyz
</span>,
<span class=
"s2">Pseq
</span>([
1,
2,
3])
<span class=
"Apple-converted-space"> </span></p>
234 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
235 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>// create a stream of events for the Pbind pattern.
</p>
236 <p class=
"p6">stream = pattern.asStream;
</p>
237 <p class=
"p10"><br></p>
238 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>// event Streams require a prototype event as input.
</p>
239 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>// this example uses an empty Event as a prototype
</p>
240 <p class=
"p6">4.do({
<span class=
"Apple-converted-space"> </span>stream.next(
<span class=
"s2">Event
</span>.new).postln; });
</p>
242 <p class=
"p7"><br></p>
243 <p class=
"p3">Here is an example with more bindings.
</p>
244 <p class=
"p4"><br></p>
246 <p class=
"p6"><span class=
"s2">var
</span> pattern, stream;
</p>
247 <p class=
"p10"><br></p>
248 <p class=
"p6">pattern =
<span class=
"s2">Pbind
</span>(
<span class=
"Apple-converted-space"> </span></p>
249 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s1">\abc
</span>,
<span class=
"s2">Prand
</span>([
6,
7,
8,
9],
<span class=
"s2">inf
</span> ),
<span class=
"Apple-converted-space"> </span></p>
250 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s1">\xyz
</span>,
<span class=
"s2">Pseq
</span>([
1,
2,
3],
2 ),
<span class=
"Apple-converted-space"> </span></p>
251 <p class=
"p11"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span><span class=
"s1">\uuu
</span><span class=
"s3">,
999 </span>// a constant represents an infinite sequence of itself
</p>
253 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
254 <p class=
"p6">stream = pattern.asStream;
</p>
255 <p class=
"p10"><br></p>
256 <p class=
"p6">7.do({
<span class=
"Apple-converted-space"> </span>stream.next(
<span class=
"s2">Event
</span>.new).postln; });
</p>
258 <p class=
"p7"><br></p>
259 <p class=
"p3">The ListPatterns discussed in part
3 can be put around Event Streams to create sequences of Event Streams.
</p>
260 <p class=
"p4"><br></p>
262 <p class=
"p6"><span class=
"s2">var
</span> pattern, stream;
</p>
263 <p class=
"p6">pattern =
<span class=
"Apple-converted-space"> </span></p>
264 <p class=
"p9"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pseq
<span class=
"s3">([
</span></p>
265 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\abc
</span>,
<span class=
"s2">Pseq
</span>([
1,
2,
3])),
</p>
266 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\def
</span>,
<span class=
"s2">Pseq
</span>([
4,
5,
6])),
</p>
267 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\xyz
</span>,
<span class=
"s2">Pseq
</span>([
7,
8,
9]))
</p>
268 <p class=
"p6"><span class=
"Apple-tab-span"> </span>]);
<span class=
"Apple-tab-span"> </span></p>
269 <p class=
"p6">stream = pattern.asStream;
</p>
270 <p class=
"p6">10.do({
<span class=
"Apple-converted-space"> </span>stream.next(
<span class=
"s2">Event
</span>.new).postln; });
</p>
272 <p class=
"p10"><br></p>
274 <p class=
"p6"><span class=
"s2">var
</span> pattern, stream;
</p>
275 <p class=
"p6">pattern =
<span class=
"Apple-converted-space"> </span></p>
276 <p class=
"p9"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Prand
<span class=
"s3">([
</span></p>
277 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\abc
</span>,
<span class=
"s2">Pseq
</span>([
1,
2,
3])),
</p>
278 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\def
</span>,
<span class=
"s2">Pseq
</span>([
4,
5,
6])),
</p>
279 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Pbind
</span>(
<span class=
"s1">\xyz
</span>,
<span class=
"s2">Pseq
</span>([
7,
8,
9]))
</p>
280 <p class=
"p6"><span class=
"Apple-tab-span"> </span>],
3);
<span class=
"Apple-tab-span"> </span></p>
281 <p class=
"p6">stream = pattern.asStream;
</p>
282 <p class=
"p6">10.do({
<span class=
"Apple-converted-space"> </span>stream.next(
<span class=
"s2">Event
</span>.new).postln; });
</p>
284 <p class=
"p4"><br></p>
285 <p class=
"p3">To go to the next file:
</p>
286 <p class=
"p13"><a href=
"Streams-Patterns-Events5.html">Streams-Patterns-Events5
</a></p>
287 <p class=
"p4"><br></p>
288 <p class=
"p4"><br></p>