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=
"949.43">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #7d261f}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0d2fae}
17 span
.s1
{font: 18.0px Helvetica
}
18 span
.s2
{font: 9.0px Monaco
}
19 span
.s3
{color: #1a47e2}
20 span
.s4
{color: #0d2fae}
21 span
.s5
{color: #606060}
22 span
.s6
{color: #000000}
23 span
.s7
{color: #516a22}
24 span
.s8
{color: #7d261f}
25 span
.Apple-tab-span
{white-space:pre
}
29 <p class=
"p1"><span class=
"s1"><b>TaskProxy
<span class=
"Apple-tab-span"> </span></b></span><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span><b>event stream reference
</b></p>
30 <p class=
"p2"><br></p>
31 <p class=
"p1">superclass: PatternProxy
</p>
32 <p class=
"p3"><br></p>
33 <p class=
"p1">Keeps a reference to a task (time pattern) that can be replaced while playing.
</p>
34 <p class=
"p1">It plays on when the old stream ended and a new stream is set and schedules the changes to the beat.
</p>
35 <p class=
"p3"><br></p>
36 <p class=
"p3"><br></p>
37 <p class=
"p1">related:
<a href=
"Tdef.html"><span class=
"s3">Tdef
</span></a></p>
38 <p class=
"p3"><br></p>
39 <p class=
"p3"><br></p>
40 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>*new(source)
</b></p>
41 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>create a new instance with a function (the source).
</p>
42 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>the source should be a
<b><i>routine function
</i></b> (see
<b>Tdef
</b>) or a
<b><i>pattern
</i></b> of time values.
</p>
43 <p class=
"p3"><br></p>
44 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>*default
</b></p>
45 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a default source, if none is given. the default is a loop that does nothing with a
1.0 beat wait time
</p>
46 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
47 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
48 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>source_(obj)
</b></p>
49 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>set the source. If a quantization is given, schedule this change to the next beat
</p>
50 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>the object is a
<b><i>routine function,
</i></b>which is evaluated in a protected way, so that
</p>
51 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>failure will notify the proxy that it has stopped.
<span class=
"Apple-converted-space"> </span></p>
52 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>The object can also be a
<b><i>pattern
</i></b> of time values.
</p>
53 <p class=
"p3"><br></p>
54 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>clear
</b><span class=
"Apple-tab-span"> </span>set the source to nil
</p>
55 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
56 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>quant_(beats)
</b></p>
57 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>set the quantization value. can be a pair [quant, offset]
</p>
58 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
59 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>quant
</b></p>
60 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>get the quantization value
</p>
61 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
62 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>*defaultQuant_(beats)
</b></p>
63 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>set the default quantization value for the class. (default:
1.0)
</p>
64 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>can be a pair [quant, offset]
</p>
65 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
66 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>condition_(func)
</b></p>
67 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>provide a condition under which the pattern is switched when a new one is inserted.
</p>
68 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>the stream value and a count is passed into the function.
</p>
69 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>the methods
<b>count_(n)
</b>simply counts up to n and switches the pattern then
</p>
70 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
71 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>reset
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
72 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>switch the pattern immediately. (stuck conditions can be subverted by this)
</p>
73 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
74 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>envir_(event)
</b></p>
75 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>provide a default environment for the proxy.
<span class=
"Apple-converted-space"> </span></p>
76 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>If given,
<span class=
"Apple-converted-space"> </span>it is used as an environment for the routine
<span class=
"Apple-converted-space"> </span></p>
77 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>function. When set for the first time, the routine pattern is rebuilt.
</p>
78 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
79 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>set(key, val, key2, val2, ...)
</b></p>
80 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>set arguments in the environment.
<span class=
"Apple-converted-space"> </span></p>
81 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>If there is none, it is created and the routine pattern is rebuilt.
</p>
82 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
83 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>endless
</b></p>
84 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns a Proutine that plays the proxy endlessly, replacing
<b>nil
</b> with a
<b>default
</b></p>
85 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>value (
1 s. wait time). This allows to create streams that idle on until a new pattern is inserted.
</p>
86 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
87 <p class=
"p3"><br></p>
88 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
89 <p class=
"p3"><br></p>
90 <p class=
"p1"><b><i>a) using it as stream reference
</i></b></p>
91 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
92 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>source_
<span class=
"Apple-tab-span"> </span></b></p>
93 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>set the routine function / pattern (internally done by *new(key, obj)
</p>
94 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
95 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
96 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>embedInStream(inval)
</b></p>
97 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>just like any stream, embeds itself in stream
</p>
98 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
99 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
100 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
101 <p class=
"p1"><b><i>b) using it as EventStreamPlayer
</i></b></p>
102 <p class=
"p3"><br></p>
103 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>play(clock, protoEvent, quant)
</b></p>
104 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>starts the TaskProxy and creates a player.
<span class=
"Apple-converted-space"> </span></p>
105 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if you want to play multiple instances, use
<b>.playOnce(clock, protoEvent, quant)
</b></p>
106 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>quant
</b>can be an array of [quant, phase]
</p>
107 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
108 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>stop
</b></p>
109 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>stops the player
</p>
110 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
111 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>player
</b><span class=
"Apple-tab-span"> </span></p>
112 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>the current player (if the TaskProxy is simply used in other streams this is nil)
</p>
113 <p class=
"p3"><br></p>
114 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>pause / resume / reset / mute / unmute
</b></p>
115 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>perform player method
<span class=
"Apple-converted-space"> </span></p>
116 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
117 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>isPlaying
</b><span class=
"Apple-converted-space"> </span></p>
118 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns true if TaskProxy is running.
</p>
119 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if a TaskProxy is playing and its stream ends, it will schedule a stream for playing
<span class=
"Apple-converted-space"> </span></p>
120 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>as soon as a new one is assigned to it.
</p>
121 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
122 <p class=
"p3"><span class=
"Apple-tab-span"> </span></p>
123 <p class=
"p3"><br></p>
124 <p class=
"p2"><br></p>
125 <p class=
"p2"><br></p>
126 <p class=
"p2"><br></p>
127 <p class=
"p1"><b><i>a) using TaskProxy as a player
</i></b></p>
128 <p class=
"p2"><br></p>
129 <p class=
"p2"><br></p>
130 <p class=
"p4">// create an empty Tdef and play it.
</p>
131 <p class=
"p5">x =
<span class=
"s4">TaskProxy
</span>.new;
</p>
132 <p class=
"p5">x.play;
<span class=
"Apple-converted-space"> </span></p>
133 <p class=
"p2"><br></p>
134 <p class=
"p2"><br></p>
135 <p class=
"p5">x.source =
<span class=
"Apple-converted-space"> </span>{ loop {
<span class=
"s5">"ggggggggggggggggg9999ggg999ggg999gg"</span>.scramble.postln;
0.5.wait; } };
</p>
136 <p class=
"p2"><br></p>
137 <p class=
"p2"><br></p>
138 <p class=
"p5">x.source = { loop {
<span class=
"s5">"---------////----------------------"</span>.scramble.postln;
0.25.wait; } };
</p>
139 <p class=
"p5">x.source = { loop {
<span class=
"s4">thisThread
</span>.seconds.postln;
1.wait; } };
</p>
140 <p class=
"p5">x.source = { loop {
<span class=
"s4">thisThread
</span>.seconds.postln;
1.01.wait; } };
</p>
141 <p class=
"p2"><br></p>
142 <p class=
"p5"><span class=
"s4">TempoClock
</span>.default.tempo =
2;
</p>
143 <p class=
"p2"><br></p>
144 <p class=
"p5">x.source = {
<span class=
"s5">"the end"</span>.postln };
</p>
145 <p class=
"p5">x.source = {
<span class=
"s5">"one more"</span>.postln };
</p>
146 <p class=
"p5">x.source = {
10.do {
<span class=
"s5">"ten more"</span>.scramble.postln;
0.25.wait; } };
</p>
147 <p class=
"p5">x.source = { loop {
<span class=
"s5">"many more"</span>.scramble.postln;
0.25.wait; } };
</p>
148 <p class=
"p2"><br></p>
149 <p class=
"p5"><span class=
"s4">TempoClock
</span>.default.tempo =
1;
</p>
150 <p class=
"p2"><br></p>
151 <p class=
"p5">x.stop;
</p>
152 <p class=
"p5">x.play;
</p>
153 <p class=
"p5">x.stop;
</p>
154 <p class=
"p2"><br></p>
155 <p class=
"p2"><br></p>
156 <p class=
"p2"><br></p>
157 <p class=
"p2"><br></p>
158 <p class=
"p4">// sound example
</p>
159 <p class=
"p2"><br></p>
161 <p class=
"p4">// load a synthdef
</p>
162 <p class=
"p5">s.boot;
</p>
163 <p class=
"p6"><span class=
"s4">SynthDef
</span><span class=
"s6">(
</span>"pdef_grainlet"<span class=
"s6">,
<span class=
"Apple-converted-space"> </span></span></p>
164 <p class=
"p5"><span class=
"Apple-tab-span"> </span>{
<span class=
"s4">arg
</span> out=
0, freq=
440, sustain=
0.05;
</p>
165 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> env;
</p>
166 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>env =
<span class=
"s4">EnvGen
</span>.kr(
<span class=
"s4">Env
</span>.perc(
0.01, sustain,
0.3), doneAction:
2);
</p>
167 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">Out
</span>.ar(out,
<span class=
"s4">SinOsc
</span>.ar(freq,
0, env))
</p>
168 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}).store;
</p>
170 <p class=
"p5">x.play;
</p>
171 <p class=
"p2"><br></p>
173 <p class=
"p5">x.source = {
<span class=
"Apple-converted-space"> </span></p>
174 <p class=
"p5"><span class=
"Apple-tab-span"> </span>loop {
</p>
175 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>s.sendMsg(
<span class=
"s5">"/s_new"</span>,
<span class=
"s5">"pdef_grainlet"</span>, -
1,
0,
0,
<span class=
"s7">\freq
</span>, rrand(
600,
640));
</p>
176 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>0.1.wait;
</p>
177 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}
</p>
180 <p class=
"p2"><br></p>
182 <p class=
"p5">x.source = {
<span class=
"Apple-converted-space"> </span></p>
183 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> x;
</p>
184 <p class=
"p5"><span class=
"Apple-tab-span"> </span>x =
<span class=
"s4">Pseries
</span>(
300,
20,
100).loop.asStream;
</p>
185 <p class=
"p5"><span class=
"Apple-tab-span"> </span>loop {
</p>
186 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>s.sendMsg(
<span class=
"s5">"/s_new"</span>,
<span class=
"s5">"pdef_grainlet"</span>, -
1,
0,
0,
<span class=
"s7">\freq
</span>, x.next);
</p>
187 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>0.05.wait;
</p>
188 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}
</p>
191 <p class=
"p2"><br></p>
193 <p class=
"p5">x.source = {
<span class=
"Apple-converted-space"> </span></p>
194 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> x;
</p>
195 <p class=
"p5"><span class=
"Apple-tab-span"> </span>x =
<span class=
"s4">Plazy
</span> {
<span class=
"s4">Pseries
</span>(
300 +
300.rand,
10 +
30.rand,
10 +
30.rand) }.loop.asStream;
</p>
196 <p class=
"p5"><span class=
"Apple-tab-span"> </span>loop {
</p>
197 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>s.sendMsg(
<span class=
"s5">"/s_new"</span>,
<span class=
"s5">"pdef_grainlet"</span>, -
1,
0,
0,
<span class=
"s7">\freq
</span>, x.next);
</p>
198 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>0.05.wait;
</p>
199 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}
</p>
202 <p class=
"p2"><br></p>
203 <p class=
"p4">// metronome
</p>
205 <p class=
"p7"><span class=
"s6">y =
</span>TaskProxy
<span class=
"s6"> {
<span class=
"Apple-converted-space"> </span></span></p>
206 <p class=
"p5"><span class=
"Apple-tab-span"> </span>loop { s.sendMsg(
<span class=
"s5">"/s_new"</span>,
<span class=
"s5">"pdef_grainlet"</span>, -
1,
0,
0,
<span class=
"s7">\freq
</span>,
1500);
1.wait; }
<span class=
"Apple-converted-space"> </span></p>
208 <p class=
"p5">y.play;
</p>
210 <p class=
"p2"><br></p>
211 <p class=
"p4">// play ending stream once
</p>
213 <p class=
"p5">x.source = {
<span class=
"Apple-converted-space"> </span></p>
214 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> x, dt;
</p>
215 <p class=
"p5"><span class=
"Apple-tab-span"> </span>dt = [
0.1,
0.125,
0.05].choose;
</p>
216 <p class=
"p5"><span class=
"Apple-tab-span"> </span>x =
<span class=
"s4">Plazy
</span> {
<span class=
"s4">Pseries
</span>(
1300 +
300.rand,
110 +
130.rand,
16) }.asStream;
</p>
217 <p class=
"p5"><span class=
"Apple-tab-span"> </span>x.do {
<span class=
"s4">arg
</span> item;
</p>
218 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>s.sendMsg(
<span class=
"s5">"/s_new"</span>,
<span class=
"s5">"pdef_grainlet"</span>, -
1,
0,
0,
<span class=
"s7">\freq
</span>, item);
</p>
219 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>dt.wait;
</p>
220 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}
</p>
223 <p class=
"p2"><br></p>
224 <p class=
"p5">... and so on ...
</p>
225 <p class=
"p2"><br></p>
226 <p class=
"p5">x.stop;
</p>
227 <p class=
"p5">y.stop;
</p>
228 <p class=
"p2"><br></p>
229 <p class=
"p2"><br></p>
230 <p class=
"p2"><br></p>
231 <p class=
"p2"><br></p>
232 <p class=
"p1"><b><i>b) embedding TaskProxy into other Tasks / Routines
</i></b></p>
233 <p class=
"p2"><br></p>
234 <p class=
"p2"><br></p>
236 <p class=
"p5">#a, c = {
<span class=
"s4">TaskProxy
</span>.new } !
2;
</p>
237 <p class=
"p5">a.source = {
<span class=
"s5">"one"</span>.postln;
1.wait;
<span class=
"s5">"two"</span>.postln };
</p>
238 <p class=
"p5">c.source = {
<span class=
"s4">var
</span> z; z =
<span class=
"s4">Synth
</span>(
<span class=
"s7">\default
</span>);
0.5.wait; z.release };
</p>
239 <p class=
"p5">r =
<span class=
"s4">Task
</span> {
</p>
240 <p class=
"p6"><span class=
"s6"><span class=
"Apple-tab-span"> </span></span>"counting..."<span class=
"s6">.postln;
</span></p>
241 <p class=
"p5"><span class=
"Apple-tab-span"> </span>2.wait;
</p>
242 <p class=
"p5"><span class=
"Apple-tab-span"> </span>a.embedInStream;
</p>
243 <p class=
"p5"><span class=
"Apple-tab-span"> </span>1.wait;
</p>
244 <p class=
"p5"><span class=
"Apple-tab-span"> </span>c.embedInStream;
</p>
245 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s5">"done."</span>.postln;
</p>
248 <p class=
"p2"><br></p>
249 <p class=
"p4"><span class=
"s6">r.play;
</span>// play a stream
</p>
250 <p class=
"p2"><br></p>
251 <p class=
"p5">c.source = {
<span class=
"s4">var
</span> z; z =
<span class=
"s4">Synth
</span>(
<span class=
"s7">\default
</span>, [
<span class=
"s7">\freq
</span>,
300]);
1.5.wait; z.release };
<span class=
"s8">// change the def
</span></p>
252 <p class=
"p2"><br></p>
253 <p class=
"p5">r.reset;
</p>
254 <p class=
"p5">r.play;
</p>
255 <p class=
"p2"><br></p>
256 <p class=
"p4">// of course TaskProxies can be used in other Tdefs:
</p>
258 <p class=
"p5">b =
<span class=
"s4">TaskProxy
</span>.new;
</p>
259 <p class=
"p5">b.source = {
</p>
260 <p class=
"p6"><span class=
"s6"><span class=
"Apple-tab-span"> </span></span>"counting..."<span class=
"s6">.postln;
</span></p>
261 <p class=
"p5"><span class=
"Apple-tab-span"> </span>2.wait;
</p>
262 <p class=
"p5"><span class=
"Apple-tab-span"> </span>a.embedInStream;
</p>
263 <p class=
"p5"><span class=
"Apple-tab-span"> </span>1.wait;
</p>
264 <p class=
"p5"><span class=
"Apple-tab-span"> </span>c.embedInStream;
</p>
265 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s5">"done."</span>.postln;
</p>
268 <p class=
"p5">b.playOnce;
</p>
269 <p class=
"p2"><br></p>
270 <p class=
"p4">// if one wants to branch off a stream in a separate thread, asStream is used.
</p>
272 <p class=
"p7">Routine
<span class=
"s6"> {
</span></p>
273 <p class=
"p5"><span class=
"Apple-tab-span"> </span>c.asStream.play;
</p>
274 <p class=
"p5"><span class=
"Apple-tab-span"> </span>0.1.wait;
</p>
275 <p class=
"p5"><span class=
"Apple-tab-span"> </span>c.asStream.play;
</p>
276 <p class=
"p5"><span class=
"Apple-tab-span"> </span>0.1.wait;
</p>
277 <p class=
"p5"><span class=
"Apple-tab-span"> </span>a.asStream.play;
</p>
278 <p class=
"p2"><br></p>
279 <p class=
"p5">}.play;
</p>
281 <p class=
"p2"><br></p>