rsc3/doc-schelp/Help-3.12.2/Classes/Clock.html

78 lines
No EOL
9.6 KiB
HTML

<!doctype html><html lang='en'><head><title>Clock | SuperCollider 3.9.3 Help</title>
<link rel='stylesheet' href='./../scdoc.css' type='text/css' />
<link rel='stylesheet' href='./../frontend.css' type='text/css' />
<link rel='stylesheet' href='./../custom.css' type='text/css' />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script>
var helpRoot = './..';
var scdoc_title = 'Clock';
var scdoc_sc_version = '3.9.3';
</script>
<script src='./../scdoc.js' type='text/javascript'></script>
<script src='./../docmap.js' type='text/javascript'></script>
<script src='./../prettify.js' type='text/javascript'></script>
<script src='./../lang-sc.js' type='text/javascript'></script>
</head>
<body onload='fixTOC();prettyPrint()'>
<div id='toc'>
<div id='toctitle'>Clock:</div>
<span class='toc_search'>Filter: <input id='toc_search'></span><ul class='toc'><li class='toc1'><a href='#description'>Description</a></li>
<ul class='toc'><li class='toc2'><a href='#Scheduling'>Scheduling</a></li>
<ul class='toc'></ul><li class='toc2'><a href='#Useful%20Tasks'>Useful Tasks</a></li>
<ul class='toc'></ul><li class='toc2'><a href='#Scheduling%20and%20Threads'>Scheduling and Threads</a></li>
<ul class='toc'></ul></ul><li class='toc1'><a href='#classmethods'>Class methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Inherited%20class%20methods'>Inherited class methods</a></li>
<li class='toc2'><a href='#Undocumented%20class%20methods'>Undocumented class methods</a></li>
<ul class='toc'><li class='toc3'><a href='#*bars2beats'>bars2beats</a> </li>
<li class='toc3'><a href='#*beats'>beats</a> </li>
<li class='toc3'><a href='#*beats2bars'>beats2bars</a> </li>
<li class='toc3'><a href='#*beats2secs'>beats2secs</a> </li>
<li class='toc3'><a href='#*nextTimeOnGrid'>nextTimeOnGrid</a> </li>
<li class='toc3'><a href='#*play'>play</a> </li>
<li class='toc3'><a href='#*seconds'>seconds</a> </li>
<li class='toc3'><a href='#*secs2beats'>secs2beats</a> </li>
<li class='toc3'><a href='#*timeToNextBeat'>timeToNextBeat</a> </li>
</ul></ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
</ul></ul></div><div class='contents'>
<div id='menubar'></div>
<div class='header'>
<div id='label'>
<span id='folder'>Classes</span>
| <span id='categories'><a href='./../Browse.html#Scheduling'>Scheduling</a>&#8201;&gt;&#8201;<a href='./../Browse.html#Scheduling>Clocks'>Clocks</a></span>
</div><h1>Clock<span id='superclasses'> : <a href="../Classes/Object.html">Object</a></span>
</h1>
<div id='summary'>abstract superclass for clocks</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Clock.sc' title='/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Clock.sc'>Clock.sc</a></div><div id='subclasses'>Subclasses: <a href="../Classes/AppClock.html">AppClock</a>, <a href="../Classes/FollowerClock.html">FollowerClock</a>, <a href="../Classes/SystemClock.html">SystemClock</a>, <a href="../Classes/TempoClock.html">TempoClock</a></div>
<div id='related'>See also: <a href="./../Classes/AppClock.html">AppClock</a>, <a href="./../Classes/SystemClock.html">SystemClock</a>, <a href="./../Classes/TempoClock.html">TempoClock</a></div>
</div>
<h2><a class='anchor' name='description'>Description</a></h2>
<p>Clock is an abstract class: it only defines an abstract set of methods that all clocks should implement. See its subclasses: <a href="./../Classes/SystemClock.html">SystemClock</a>, <a href="./../Classes/TempoClock.html">TempoClock</a>, <a href="./../Classes/AppClock.html">AppClock</a> for specific implementations.<h3><a class='anchor' name='Scheduling'>Scheduling</a></h3>
<p>A Clock keeps track of time and allows <strong>tasks</strong> to be <strong>scheduled</strong> for some time in the future (e.g. using <a href="./../Classes/TempoClock.html#-sched">sched</a>, <a href="./../Classes/TempoClock.html#-schedAbs">schedAbs</a> or <a href="./../Classes/TempoClock.html#-play">play</a> methods). A task can be any <a href="./../Classes/Object.html">Object</a>. When the time at which a task was scheduled is up, the task is <em>awoken</em>, i.e. its <a href="./../Classes/Object.html#-awake">awake</a> method is evaluated. If the value returned by this method is a number, the task is automatically <strong>rescheduled</strong> for the time equal to its last scheduled time plus the return value (in <a href="./../Classes/TempoClock.html#-beats">beats</a>).<h3><a class='anchor' name='Useful%20Tasks'>Useful Tasks</a></h3>
<p>Objects of different classes may do different things in response to being scheduled on a clock by having own implementation of the <code class='code prettyprint lang-sc'>awake</code> method. The <a href="./../Classes/Object.html#-awake">Object: -awake</a> method that all classes inherit simply calls the same object's <a href="./../Classes/Object.html#-next">next</a> method, forwarding the <code class='code prettyprint lang-sc'>beats</code> argument as well as the return value, so subclasses may implement either one to equivalent effect, as far as clock scheduling is concerned. <a class='footnote anchor' name='footnote_org_1' href='#footnote_1'><sup>1</sup></a>
<p>Examples of useful objects to be scheduled on clocks:<ul>
<li><a href="./../Classes/Function.html#-awake">Function: -awake</a> method is implemented so as to call the function's own <a href="./../Classes/Function.html#-value">Function: -value</a> method, effectively running the code within the function.<li><a href="./../Classes/Routine.html#-awake">Routine: -awake</a> calls own <a href="./../Classes/Routine.html#-next">Routine: -next</a>, in turn starting or resuming the Routine's Function.<li>Some subclasses of <a href="./../Classes/Stream.html">Stream</a> will have its <code class='code prettyprint lang-sc'>next</code> method do something useful aside from returning a new value in a stream.</ul>
<h3><a class='anchor' name='Scheduling%20and%20Threads'>Scheduling and Threads</a></h3>
<p>Whenever a task is awaken, its <code class='code prettyprint lang-sc'>awake</code> method is called in the context of the <a href="./../Classes/Process.html#-mainThread">main thread</a>. Just before that, the main thread's <a href="./../Classes/Thread.html#-beats">logical time</a> is set to the scheduling time of the awaken task, and its <a href="./../Classes/Thread.html#-clock">clock</a> is set to the scheduling clock. Note however that if the task is a <a href="./../Classes/Routine.html">Routine</a> it will then immediately start or resume its Function, setting itself as the <a href="./../Classes/Thread.html#.thisThread">current thread</a>.<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3><a class='anchor' name='Inherited%20class%20methods'>Inherited class methods</a></h3>
<div id='inheritedclassmets'></div><h3><a class='anchor' name='Undocumented%20class%20methods'>Undocumented class methods</a></h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*bars2beats' href='./../Overviews/Methods.html#bars2beats'>bars2beats</a></h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*beats' href='./../Overviews/Methods.html#beats'>beats</a></h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*beats' href='./../Overviews/Methods.html#beats'>beats</a> = </h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*beats2bars' href='./../Overviews/Methods.html#beats2bars'>beats2bars</a></h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*beats2secs' href='./../Overviews/Methods.html#beats2secs'>beats2secs</a>(<span class='argstr'>beats</span>)</h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*nextTimeOnGrid' href='./../Overviews/Methods.html#nextTimeOnGrid'>nextTimeOnGrid</a>(<span class='argstr'>quant: 1</span>, <span class='argstr'>phase: 0</span>)</h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*play' href='./../Overviews/Methods.html#play'>play</a>(<span class='argstr'>task</span>)</h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*seconds' href='./../Overviews/Methods.html#seconds'>seconds</a></h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*secs2beats' href='./../Overviews/Methods.html#secs2beats'>secs2beats</a>(<span class='argstr'>secs</span>)</h3>
<h3 class='method-code'><span class='method-prefix'>Clock.</span><a class='method-name' name='*timeToNextBeat' href='./../Overviews/Methods.html#timeToNextBeat'>timeToNextBeat</a></h3>
<h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
<div id='inheritedinstmets'></div><div class='footnotes'>
<a class='anchor' name='footnote_1'/><div class='footnote'>[<a href='#footnote_org_1'>1</a>] - However, note that the <code class='code prettyprint lang-sc'>next</code> method is also involved in the concept of <a href="./../Tutorials/Streams-Patterns-Events1.html#Streams">streams</a>.</div></div><div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/Clock.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/Clock.schelp</a><br>link::Classes/Clock::<br></div></div></body></html>