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: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
; min-height: 22.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.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: 12.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0029b0; min-height: 12.0px}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0029b0}
20 span
.s1
{color: #0029b0}
21 span
.s2
{color: #000000}
22 span
.s3
{color: #606060}
23 span
.s4
{font: 9.0px Monaco
}
24 span
.s5
{font: 12.0px Helvetica
}
25 span
.s6
{color: #0016bd}
26 span
.Apple-tab-span
{white-space:pre
}
30 <p class=
"p1"><b>SystemClock
</b></p>
31 <p class=
"p2"><br></p>
32 <p class=
"p3"><b>superclass: Clock
</b></p>
33 <p class=
"p4"><br></p>
34 <p class=
"p5">SystemClock is more accurate, but cannot call Cocoa primitives.
</p>
35 <p class=
"p5">AppClock is less accurate (uses NSTimers) but can call Cocoa primitives.
</p>
36 <p class=
"p6"><br></p>
37 <p class=
"p5"><b>*sched(delta,task)
</b></p>
38 <p class=
"p5"><span class=
"Apple-tab-span"> </span>the float you return specifies the delta to resched the function for
</p>
39 <p class=
"p6"><br></p>
40 <p class=
"p7"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>SystemClock
</span>.sched(
0.0,{ arg time;
<span class=
"Apple-converted-space"> </span></p>
41 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>time.postln;
<span class=
"Apple-converted-space"> </span></p>
42 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>rrand(
0.1,
0.9)
<span class=
"Apple-converted-space"> </span></p>
43 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
44 <p class=
"p6"><br></p>
45 <p class=
"p5"><span class=
"Apple-tab-span"> </span>returning
<span class=
"s1">nil
</span> will stop the task from being rescheduled
</p>
46 <p class=
"p6"><br></p>
47 <p class=
"p7"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>SystemClock
</span>.sched(
2.0,{
<span class=
"Apple-converted-space"> </span></p>
48 <p class=
"p8"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>"2.0 seconds later"<span class=
"s2">.postln;
<span class=
"Apple-converted-space"> </span></span></p>
49 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s1">nil
</span><span class=
"Apple-converted-space"> </span></p>
50 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
51 <p class=
"p6"><br></p>
52 <p class=
"p5"><b>*clear
</b></p>
53 <p class=
"p5"><span class=
"Apple-tab-span"> </span>clear the SystemClock's scheduler to stop it
</p>
54 <p class=
"p9"><br></p>
55 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>SystemClock
<span class=
"s2">.clear
</span></p>
56 <p class=
"p6"><br></p>
57 <p class=
"p5"><b>*schedAbs(time,task)
</b></p>
58 <p class=
"p4"><b><span class=
"Apple-tab-span"> </span></b></p>
59 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s1">SystemClock
</span>.schedAbs( (
<span class=
"s1">thisThread
</span>.seconds +
4.0).round(
1.0),{
<span class=
"s1">arg
</span> time;
</p>
60 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(
<span class=
"s3">"the time is exactly "</span> ++ time.asString
<span class=
"Apple-converted-space"> </span></p>
61 <p class=
"p8"><span class=
"s2"><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>" seconds since starting SuperCollider")
<span class=
"s2">.postln;
</span></p>
62 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
63 <p class=
"p4"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></p>
64 <p class=
"p6"><span class=
"Apple-tab-span"> </span></p>
65 <p class=
"p5"><b>*play(task)
</b></p>
66 <p class=
"p5"><span class=
"Apple-tab-span"> </span>Calls to the cocoa framework (including all GUI) may not be made directly
<span class=
"Apple-converted-space"> </span></p>
67 <p class=
"p5"><span class=
"Apple-tab-span"> </span>from actions triggered by SystemClock or incoming socket messages
<span class=
"Apple-converted-space"> </span></p>
68 <p class=
"p5"><span class=
"Apple-tab-span"> </span>(OSCresponder).
<span class=
"Apple-converted-space"> </span></p>
69 <p class=
"p4"><br></p>
70 <p class=
"p5"><span class=
"Apple-tab-span"> </span>To get around this, use
<span class=
"s4">{ }.defer
</span></p>
71 <p class=
"p5"><span class=
"Apple-tab-span"> </span>This will execute the function using the AppClock and is equivalent to
</p>
72 <p class=
"p7"><span class=
"s5"><span class=
"Apple-tab-span"> </span></span><span class=
"Apple-tab-span"> </span><span class=
"s1">AppClock
</span>.sched(
0, function):
</p>
73 <p class=
"p6"><br></p>
74 <p class=
"p6"><br></p>
75 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(
</p>
76 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s1">var
</span> w, r;
</p>
77 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w =
<span class=
"s6">Window
</span>.new(
<span class=
"s3">"trem"</span>,
<span class=
"s1">Rect
</span>(
512,
256,
360,
130));
</p>
78 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w.front;
</p>
79 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>r =
<span class=
"s1">Routine
</span>({ arg time;
</p>
80 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>60.do({
<span class=
"s1">arg
</span> i;
</p>
81 <p class=
"p7"><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>0.05.yield;
</p>
82 <p class=
"p7"><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>{
</p>
83 <p class=
"p7"><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 class=
"Apple-tab-span"> </span>w.bounds = w.bounds.moveBy(
10.rand2,
10.rand2);
</p>
84 <p class=
"p7"><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 class=
"Apple-tab-span"> </span>w.alpha = cos(i*
0.1pi)*
0.5+
0.5;
</p>
85 <p class=
"p7"><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>}.defer;
</p>
86 <p class=
"p7"><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>
87 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>1.yield;
</p>
88 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w.close;
</p>
89 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
90 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s1">SystemClock
</span>.play(r);
</p>
91 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>)
</p>
92 <p class=
"p6"><br></p>
93 <p class=
"p5"><span class=
"Apple-tab-span"> </span>This example is only to show how to make calls to Cocoa/GUI when
<span class=
"Apple-converted-space"> </span></p>
94 <p class=
"p5"><span class=
"Apple-tab-span"> </span>scheduling with the SystemClock.
</p>
95 <p class=
"p5"><span class=
"Apple-tab-span"> </span>If you only wish to control the GUI, use AppClock.
</p>
96 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
97 <p class=
"p4"><br></p>