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: 12.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0021e7}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; min-height: 12.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
; min-height: 14.0px}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica
}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; color: #842b1e}
20 p
.p11
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
}
21 p
.p12
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; color: #832519}
22 p
.p13
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
}
23 p
.p14
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
; min-height: 17.0px}
24 span
.s1
{font: 18.0px Helvetica
}
25 span
.s2
{color: #000000}
26 span
.s3
{color: #0033f1}
27 span
.s4
{color: #0000ff}
28 span
.s5
{color: #093caa}
29 span
.s6
{font: 12.0px Helvetica
; color: #000000}
30 span
.s7
{font: 9.0px Monaco
}
31 span
.s8
{text-decoration: underline
; color: #0039da}
32 span
.s9
{color: #0035aa}
33 span
.Apple-tab-span
{white-space:pre
}
37 <p class=
"p1"><span class=
"s1"><b>Thread
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><b>represents an individual operating system thread
<span class=
"Apple-converted-space"> </span></b></p>
38 <p class=
"p2"><br></p>
39 <p class=
"p3"><span class=
"s2"><b>Inherits from:
</b><a href=
"../Object.html"><span class=
"s3"><b>Object
</b></span></a><b> :
</b><a href=
"AbstractFunction.html"><b>AbstractFunction
</b></a><b> :
</b><a href=
"../../Streams-Patterns-Events/Stream.html"><b>Stream
</b></a></span></p>
40 <p class=
"p4"><br></p>
41 <p class=
"p1">Normally there is no need to instantiate a Thread, but its subclass
<a href=
"Routine.html"><span class=
"s4">Routine
</span></a> is very useful.
<span class=
"Apple-converted-space"> </span></p>
42 <p class=
"p2"><br></p>
43 <p class=
"p1">It is wise not to fiddle with the source code for this class; see the warnings in the class file.
<span class=
"Apple-converted-space"> </span></p>
44 <p class=
"p2"><br></p>
45 <p class=
"p1"><b>thisThread
</b> always returns the enclosing thread running the given code. A Thread is aware of its own attached clock and associated beats and seconds timing, and has an individual random number seed and exception handler.
</p>
46 <p class=
"p2"><br></p>
47 <p class=
"p1"><b>See also:
</b> <a href=
"Routine.html"><span class=
"s4">Routine
</span></a></p>
48 <p class=
"p2"><br></p>
49 <p class=
"p2"><br></p>
50 <p class=
"p5"><b>Creation / Class Methods
</b></p>
51 <p class=
"p6"><br></p>
52 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>*new (func, stackSize)
</b></p>
53 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
54 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Create a Thread. You will not typically do this yourself but as a result of creating Routines, for example.
<span class=
"Apple-converted-space"> </span></p>
55 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>func
</b>- A function with code for the thread to run.
</p>
56 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>stackSize
</b>- defaults to
64 depth call stack.
<span class=
"Apple-converted-space"> </span></p>
57 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
58 <p class=
"p10"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// example
</p>
59 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>g =
<span class=
"s5">Thread
</span>({
"hello".postln;});
</p>
60 <p class=
"p12"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>g.seconds;
</span>//time of creation, cannot advance without a clock
</p>
61 <p class=
"p6"><br></p>
62 <p class=
"p6"><br></p>
63 <p class=
"p8"><br></p>
64 <p class=
"p13"><b>Instance Methods
</b></p>
65 <p class=
"p8"><br></p>
66 <p class=
"p8"><span class=
"Apple-tab-span"> </span></p>
67 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>beats
</b> - return the elapsed beats (logical time) of the thread
<b><span class=
"Apple-tab-span"> </span></b></p>
68 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>seconds
</b> - return the elapsed seconds (logical time) of the thread.
</p>
69 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>clock
</b> - return the thread's clock
</p>
70 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>isPlaying
</b> - return true if it is playing
</p>
71 <p class=
"p8"><br></p>
72 <p class=
"p10"><span class=
"s6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// example
</p>
73 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>thisThread.beats;
</p>
74 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>thisThread.seconds;
</p>
75 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>thisThread.clock;
</p>
76 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
77 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
78 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>state
</b> - The internal state values for a Thread instance can be polled:
</p>
79 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
80 <p class=
"p1"><span class=
"s7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>0 = not started
</p>
81 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>7 = running
</p>
82 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>8 = stopped
</p>
83 <p class=
"p2"><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>
84 <p class=
"p2"><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>
85 <p class=
"p13"><b>Seeding the random number generator
</b></p>
86 <p class=
"p14"><br></p>
87 <p class=
"p7"><span class=
"s7"><span class=
"Apple-tab-span"> </span></span>see also:
<a href=
"randomSeed.html"><span class=
"s8">randomSeed
</span></a></p>
88 <p class=
"p6"><br></p>
89 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
90 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>randSeed_ (seed)
</b></p>
91 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
92 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>seed
</b>- Set the random number generator seed using a single integer
</p>
93 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
94 <p class=
"p12"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// inline example
</p>
95 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>g =
<span class=
"s9">thisThread
</span>.randSeed_(
4);
</p>
96 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10.do{
1.0.rand2.postln};
</p>
97 <p class=
"p6"><br></p>
98 <p class=
"p6"><br></p>
99 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>randData
</b></p>
100 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
101 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Get the three integer array which defines the internal basis for the random number generator.
<span class=
"Apple-converted-space"> </span>You can use this to get back the exact same random number sequence, and it provides a mechanism for automatic replay for generative music.
<span class=
"Apple-converted-space"> </span></p>
102 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
103 <p class=
"p10"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// inline example
</p>
104 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>g = this
<span class=
"s5">Thread
</span>.randData;
</p>
105 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10.do{
1.0.rand2.postln};
<span class=
"Apple-tab-span"> </span></p>
106 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
107 <p class=
"p7"><span class=
"s7"><span class=
"Apple-tab-span"> </span></span><b>randData_ (data)
</b></p>
108 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
109 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Get the three integer array which defines the internal basis for the random number generator. Equivalent to load for a generative music piece, as long as the program is the same as last time!
<span class=
"Apple-converted-space"> </span></p>
110 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>data
</b>- three integer array in the format previously obtained from the getter function.
<span class=
"Apple-converted-space"> </span></p>
111 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
112 <p class=
"p12"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// each time the seed is reset, the random number generation should give the same sequence
</p>
113 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">thisThread
</span>.randData_(
<span class=
"s9">Int32Array
</span>[ -
662787342,
1546785953,
1661466823 ]);
</p>
114 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10.do{
1.0.rand2.postln};
</p>
115 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
116 <p class=
"p4"><br></p>
117 <p class=
"p4"><br></p>