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

318 lines
30 KiB
HTML
Raw Permalink Normal View History

2022-08-24 13:53:18 +00:00
<html><head><title>TempoClock</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 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>
<script type='text/javascript'>var helpRoot='./..';</script>
</head>
<ul id='menubar'></ul>
<body onload='fixTOC();prettyPrint()'>
<div class='contents'>
<div class='header'>
<div id='label'>SuperCollider CLASSES</div>
<div id='categories'><a href='./../Browse.html#Scheduling>Clocks'>Scheduling>Clocks</a></div>
<h1>TempoClock</h1>
<div id='summary'>tempo based scheduler</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Clock.sc'>/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Clock.sc</a></div><div id='superclasses'>Inherits from: <a href="../Classes/Clock.html">Clock</a> : <a href="../Classes/Object.html">Object</a></div>
<div id='subclasses'>Subclasses: <a href="../Classes/TempoBusClock.html">TempoBusClock</a></div>
<div id='related'>See also: <a href="./../Classes/AppClock.html">AppClock</a>, <a href="./../Classes/SystemClock.html">SystemClock</a></div>
</div>
<div id='toc'>
<ul class='toc'><li class='toc1'><a href='#description'>Description</a></li>
<ul class='toc'></ul><li class='toc1'><a href='#classmethods'>Class methods</a></li>
<ul class='toc'><li class='toc3'><a href='#*new'>new</a> </li>
<li class='toc3'><a href='#*default'>default</a> </li>
<li class='toc2'><a href='#Forwarding%20to%20the%20default%20instance'>Forwarding to the default instance</a></li>
<ul class='toc'><li class='toc3'><a href='#*stop'>stop</a> <a href='#*play'>play</a> <a href='#*sched'>sched</a> <a href='#*schedAbs'>schedAbs</a> <a href='#*clear'>clear</a> <a href='#*tempo'>tempo</a> <a href='#*etempo'>etempo</a> <a href='#*beats'>beats</a> <a href='#*beats2secs'>beats2secs</a> <a href='#*secs2beats'>secs2beats</a> <a href='#*nextTimeOnGrid'>nextTimeOnGrid</a> <a href='#*timeToNextBeat'>timeToNextBeat</a> <a href='#*setTempoAtBeat'>setTempoAtBeat</a> <a href='#*setTempoAtSec'>setTempoAtSec</a> <a href='#*setMeterAtBeat'>setMeterAtBeat</a> <a href='#*beatsPerBar'>beatsPerBar</a> <a href='#*baseBarBeat'>baseBarBeat</a> <a href='#*baseBar'>baseBar</a> <a href='#*playNextBar'>playNextBar</a> <a href='#*beatDur'>beatDur</a> <a href='#*elapsedBeats'>elapsedBeats</a> <a href='#*beats2bars'>beats2bars</a> <a href='#*bars2beats'>bars2beats</a> <a href='#*bar'>bar</a> <a href='#*nextBar'>nextBar</a> <a href='#*beatInBar'>beatInBar</a> </li>
</ul><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='#*all'>all</a> </li>
<li class='toc3'><a href='#*cmdPeriod'>cmdPeriod</a> </li>
</ul></ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc3'><a href='#-stop'>stop</a> </li>
<li class='toc3'><a href='#-clear'>clear</a> </li>
<li class='toc3'><a href='#-tempo'>tempo</a> </li>
<li class='toc3'><a href='#-permanent'>permanent</a> </li>
<li class='toc3'><a href='#-beats'>beats</a> </li>
<li class='toc3'><a href='#-schedAbs'>schedAbs</a> </li>
<li class='toc3'><a href='#-sched'>sched</a> </li>
<li class='toc3'><a href='#-play'>play</a> </li>
<li class='toc3'><a href='#-playNextBar'>playNextBar</a> </li>
<li class='toc3'><a href='#-queue'>queue</a> </li>
<li class='toc3'><a href='#-beatDur'>beatDur</a> </li>
<li class='toc3'><a href='#-beatsPerBar'>beatsPerBar</a> </li>
<li class='toc3'><a href='#-bar'>bar</a> </li>
<li class='toc3'><a href='#-nextBar'>nextBar</a> </li>
<li class='toc3'><a href='#-beatInBar'>beatInBar</a> </li>
<li class='toc3'><a href='#-baseBar'>baseBar</a> </li>
<li class='toc3'><a href='#-baseBarBeat'>baseBarBeat</a> </li>
<li class='toc3'><a href='#-beats2bars'>beats2bars</a> </li>
<li class='toc3'><a href='#-bars2beats'>bars2beats</a> </li>
<li class='toc3'><a href='#-timeToNextBeat'>timeToNextBeat</a> </li>
<li class='toc3'><a href='#-nextTimeOnGrid'>nextTimeOnGrid</a> </li>
<li class='toc3'><a href='#-elapsedBeats'>elapsedBeats</a> </li>
<li class='toc3'><a href='#-seconds'>seconds</a> </li>
<li class='toc3'><a href='#-beats2secs'>beats2secs</a> </li>
<li class='toc3'><a href='#-secs2beats'>secs2beats</a> </li>
<li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
<li class='toc2'><a href='#Undocumented%20instance%20methods'>Undocumented instance methods</a></li>
<ul class='toc'><li class='toc3'><a href='#-archiveAsCompileString'>archiveAsCompileString</a> </li>
<li class='toc3'><a href='#-etempo'>etempo</a> </li>
<li class='toc3'><a href='#-setMeterAtBeat'>setMeterAtBeat</a> </li>
<li class='toc3'><a href='#-setTempoAtBeat'>setTempoAtBeat</a> </li>
<li class='toc3'><a href='#-setTempoAtSec'>setTempoAtSec</a> </li>
</ul></ul><li class='toc1'><a href='#examples'>Examples</a></li>
<ul class='toc'></ul></ul></div><h2><a class='anchor' name='description'>Description</a></h2>
<p>TempoClock is a scheduler like <a href="./../Classes/SystemClock.html">SystemClock</a>, but it schedules relative to a <strong>tempo</strong> in beats per second.
<p>See <a href="./../Classes/Clock.html">Clock</a> for general explanation of how clocks operate.<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*new' href='./../Overviews/Methods.html#new'>new</a> (<span class='argstr'>tempo</span>, <span class='argstr'>beats</span>, <span class='argstr'>seconds</span>, <span class='argstr'>queueSize: 256</span>)</h3>
<div class='method'>
<p>Creates a new instance of TempoClock.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>tempo<td class='argumentdesc'>
<p>The initial <a href="#-tempo">tempo</a>. Defaults to <code class='code prettyprint lang-sc'>1</code>.<tr><td class='argumentname'>beats<td class='argumentdesc'>
<p>The time in beats, corresponding to the reference time given with the <code class='code prettyprint lang-sc'>seconds</code> argument. Defaults to <code class='code prettyprint lang-sc'>0</code>.<tr><td class='argumentname'>seconds<td class='argumentdesc'>
<p>The reference time in seconds, to which the <code class='code prettyprint lang-sc'>beats</code> argument corresponds. Defaults to the current Thread's logical time (see <a href="./../Classes/Thread.html#-seconds">Thread: -seconds</a>).<tr><td class='argumentname'>queueSize<td class='argumentdesc'>
<p>The storage size of the scheduling queue. Each scheduled item takes 2 counts of space, so this size divided by 2 gives the amount of items that can be scheduled at a time. See also <a href="#-queue">-queue</a>.</table><h4>Discussion:</h4>
<p>The TempoClock will be created <strong>as if</strong> it started counting beats at the time given in the <code class='code prettyprint lang-sc'>seconds</code> argument with the starting amount given in the <code class='code prettyprint lang-sc'>beats</code> argument. The current count of beats will thus be equal to that starting amount plus the amount of beats that would be counted since the given reference time in seconds, according to the given tempo.
<p>The default arguments create a TempoClock that starts counting beats with <code class='code prettyprint lang-sc'>0</code> at the current logical time.<pre class='code prettyprint lang-sc'>// Create a TempoClock that starts counting beats with 5 now.
(
t = TempoClock.new(2, 5);
"current beats:" + t.beats;
)
// Create a TempoClock, as if it started counting beats 5 seconds ago with 0.
(
t = TempoClock.new(2, 0, thisThread.seconds - 5);
"current beats:" + t.beats;
)</pre>
</div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*default' href='./../Overviews/Methods.html#default'>default</a></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*default' href='./../Overviews/Methods.html#default'>default</a> = value</h3>
<div class='method'>
<p>Sets or gets the permanent default TempoClock instantiated at startup.<pre class='code prettyprint lang-sc'>TempoClock.default.beats // beats since default TempoClock was started</pre>
</div><h3><a class='anchor' name='Forwarding%20to%20the%20default%20instance'>Forwarding to the default instance</a></h3>
<p>The following methods only forward to the <a href="#*default">default instance</a>, allowing you to use the TempoClock class itself in place of <code class='code prettyprint lang-sc'>TempoClock.default</code>.<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*stop' href='./../Overviews/Methods.html#stop'>stop</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*play' href='./../Overviews/Methods.html#play'>play</a> (<span class='argstr'>task</span>, <span class='argstr'>quant</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*sched' href='./../Overviews/Methods.html#sched'>sched</a> (<span class='argstr'>delta</span>, <span class='argstr'>item</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*schedAbs' href='./../Overviews/Methods.html#schedAbs'>schedAbs</a> (<span class='argstr'>beat</span>, <span class='argstr'>item</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*clear' href='./../Overviews/Methods.html#clear'>clear</a> (<span class='argstr'>releaseNodes</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*tempo' href='./../Overviews/Methods.html#tempo'>tempo</a></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*tempo' href='./../Overviews/Methods.html#tempo'>tempo</a> = <span class='argstr'>newTempo</span></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*etempo' href='./../Overviews/Methods.html#etempo'>etempo</a> = <span class='argstr'>newTempo</span></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beats' href='./../Overviews/Methods.html#beats'>beats</a></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beats' href='./../Overviews/Methods.html#beats'>beats</a> = </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beats2secs' href='./../Overviews/Methods.html#beats2secs'>beats2secs</a> (<span class='argstr'>beats</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*secs2beats' href='./../Overviews/Methods.html#secs2beats'>secs2beats</a> (<span class='argstr'>secs</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*nextTimeOnGrid' href='./../Overviews/Methods.html#nextTimeOnGrid'>nextTimeOnGrid</a> (<span class='argstr'>quant: 1</span>, <span class='argstr'>phase: 0</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*timeToNextBeat' href='./../Overviews/Methods.html#timeToNextBeat'>timeToNextBeat</a> (<span class='argstr'>quant: 1</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*setTempoAtBeat' href='./../Overviews/Methods.html#setTempoAtBeat'>setTempoAtBeat</a> (<span class='argstr'>newTempo</span>, <span class='argstr'>beats</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*setTempoAtSec' href='./../Overviews/Methods.html#setTempoAtSec'>setTempoAtSec</a> (<span class='argstr'>newTempo</span>, <span class='argstr'>secs</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*setMeterAtBeat' href='./../Overviews/Methods.html#setMeterAtBeat'>setMeterAtBeat</a> (<span class='argstr'>newBeatsPerBar</span>, <span class='argstr'>beats</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beatsPerBar' href='./../Overviews/Methods.html#beatsPerBar'>beatsPerBar</a></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beatsPerBar' href='./../Overviews/Methods.html#beatsPerBar'>beatsPerBar</a> = <span class='argstr'>newBeatsPerBar</span></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*baseBarBeat' href='./../Overviews/Methods.html#baseBarBeat'>baseBarBeat</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*baseBar' href='./../Overviews/Methods.html#baseBar'>baseBar</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*playNextBar' href='./../Overviews/Methods.html#playNextBar'>playNextBar</a> (<span class='argstr'>task</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beatDur' href='./../Overviews/Methods.html#beatDur'>beatDur</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*elapsedBeats' href='./../Overviews/Methods.html#elapsedBeats'>elapsedBeats</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beats2bars' href='./../Overviews/Methods.html#beats2bars'>beats2bars</a> (<span class='argstr'>beats</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*bars2beats' href='./../Overviews/Methods.html#bars2beats'>bars2beats</a> (<span class='argstr'>bars</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*bar' href='./../Overviews/Methods.html#bar'>bar</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*nextBar' href='./../Overviews/Methods.html#nextBar'>nextBar</a> (<span class='argstr'>beat</span>)</h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*beatInBar' href='./../Overviews/Methods.html#beatInBar'>beatInBar</a> </h3>
<div class='method'>
<p></div><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='cmethodname'><span class='methprefix'>*</span><a name='*all' href='./../Overviews/Methods.html#all'>all</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*cmdPeriod' href='./../Overviews/Methods.html#cmdPeriod'>cmdPeriod</a> </h3>
<h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-stop' href='./../Overviews/Methods.html#stop'>stop</a> </h3>
<div class='method'>
<p>Destroys the scheduler and releases the OS thread running the scheduler.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-clear' href='./../Overviews/Methods.html#clear'>clear</a> (<span class='argstr'>releaseNodes: true</span>)</h3>
<div class='method'>
<p>Removes all tasks from the scheduling queue.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-tempo' href='./../Overviews/Methods.html#tempo'>tempo</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-tempo' href='./../Overviews/Methods.html#tempo'>tempo</a> = <span class='argstr'>newTempo</span></h3>
<div class='method'>
<p>Sets or gets the current tempo in beats per second.<pre class='code prettyprint lang-sc'>t= TempoClock.new;
t.tempo_(2.0); // equivalent to t.tempo = 2.0;
t.tempo;
t.tempo_(72/60) // 72 beats per minute
t.tempo;</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-permanent' href='./../Overviews/Methods.html#permanent'>permanent</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-permanent' href='./../Overviews/Methods.html#permanent'>permanent</a> = value</h3>
<div class='method'>
<p>Sets or gets a <a href="./../Classes/Boolean.html">Boolean</a> value indicating whether the clock will survive cmd-period. If false the clock is stopped (and thus removed) on cmd-period. If true the clock survives cmd-period. It is false by default.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-beats' href='./../Overviews/Methods.html#beats'>beats</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-beats' href='./../Overviews/Methods.html#beats'>beats</a> = <span class='argstr'>beats</span></h3>
<div class='method'>
<p>Gets or sets the current logical time in beats according to this clock.
<p>When <strong>getting</strong> <code class='code prettyprint lang-sc'>beats</code>, if this clock is the current Thread's <a href="./../Classes/Thread.html#-clock">associated clock</a>, the Thread's own <a href="./../Classes/Thread.html#-beats">time in beats</a> is returned, otherwise the Thread's <a href="./../Classes/Thread.html#-seconds">time in seconds</a> converted to beats according to this clock is returned.
<p>After <strong>changing</strong> <code class='code prettyprint lang-sc'>beats</code> towards the <strong>future</strong>, the clock will immediately perform all tasks scheduled until the new time. Likewise, when changing <code class='code prettyprint lang-sc'>beats</code> towards the <strong>past</strong>, already scheduled tasks will be postponed, so they will still be performed at the scheduled time in beats.<div class='note'><span class='notelabel'>NOTE:</span> When changing <code class='code prettyprint lang-sc'>beats</code>, you are only changing the clocks's notion of time, and not the current Thread's <a href="./../Classes/Thread.html#-beats">logical time</a>, which will stay the same until the Thread is called again. Hence, if this clock is the current Thread's <a href="./../Classes/Thread.html#-clock">associated clock</a>, and you ask the clock for time in beats just after changing it, you will see no effect. Nevertheless, the effect will be visible immediately on a different Thread.</div><pre class='code prettyprint lang-sc'>(
t = TempoClock.new;
t.sched(3, {
t.beats = 100;
t.beats.postln; // still 3
nil
});
)
(
c = TempoClock.new;
fork {
loop {
c.beats.postln; // updates, because ".wait" calls the thread
1.wait;
}
};
)
c.beats = 100;</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-schedAbs' href='./../Overviews/Methods.html#schedAbs'>schedAbs</a> (<span class='argstr'>beat</span>, <span class='argstr'>item</span>)</h3>
<div class='method'>
<p>Schedules a task to be performed at a particular time in <strong>beats</strong>.
<p>When the scheduling time is up, the task's <code class='code prettyprint lang-sc'>awake</code> method is called. If the method returns a number, the task will be rescheduled for the time equal to the last scheduling time plus the returned value.
<p>See also: <a href="./../Classes/Clock.html#Scheduling">Clock: Scheduling</a>, <a href="./../Classes/Object.html#-awake">Object: -awake</a>.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-sched' href='./../Overviews/Methods.html#sched'>sched</a> (<span class='argstr'>delta</span>, <span class='argstr'>item</span>)</h3>
<div class='method'>
<p>Schedules a task to be performed <code class='code prettyprint lang-sc'>delta</code> amount of <strong>beats</strong> after the current Thread's logical time. If this clock is the current Thread's <a href="./../Classes/Thread.html#-clock">associated clock</a>, the Thread's <a href="./../Classes/Thread.html#-beats">time in beats</a> is used, otherwise the Thread's <a href="./../Classes/Thread.html#-seconds">time in seconds</a> is converted to beats according to this clock's tempo and time of origin.
<p>When the scheduling time is up, the task's <code class='code prettyprint lang-sc'>awake</code> method is called. If the method returns a number, the task will be rescheduled for the time equal to the last scheduling time plus the returned value.
<p>See also: <a href="./../Classes/Clock.html#Scheduling">Clock: Scheduling</a>, <a href="./../Classes/Object.html#-awake">Object: -awake</a>.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-play' href='./../Overviews/Methods.html#play'>play</a> (<span class='argstr'>task</span>, <span class='argstr'>quant: 1</span>)</h3>
<div class='method'>
<p>Plays task (a function) at the next beat, where <strong>quant</strong> is 1 by default. Shortcut for <a href="#-schedAbs">-schedAbs</a>; see <a href="#-seconds">-seconds</a> and <a href="#-nextTimeOnGrid">-nextTimeOnGrid</a> for further details on time and quant.<pre class='code prettyprint lang-sc'>t= TempoClock.default;
t.play({arg beats, time, clock; [beats, time, clock].postln});</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-playNextBar' href='./../Overviews/Methods.html#playNextBar'>playNextBar</a> (<span class='argstr'>task</span>)</h3>
<div class='method'>
<p>Plays task (a function) at the next bar using <a href="#-schedAbs">-schedAbs</a>.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-queue' href='./../Overviews/Methods.html#queue'>queue</a> </h3>
<div class='method'>
<p>Returns the scheduling queue Array in the form [beat, function]. The maximum number of items is determined by the clock's queueSize argument upon instantiation. The default queueSize of 256 allows 128 functions to be in the queue at any time.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-beatDur' href='./../Overviews/Methods.html#beatDur'>beatDur</a> </h3>
<div class='method'>
<p>Returns the duration in seconds of a current whole beat.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-beatsPerBar' href='./../Overviews/Methods.html#beatsPerBar'>beatsPerBar</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-beatsPerBar' href='./../Overviews/Methods.html#beatsPerBar'>beatsPerBar</a> = <span class='argstr'>newBeatsPerBar</span></h3>
<div class='method'>
<p>Gets or sets the number of beats per bar. The default is 4. Setting must be done from within the scheduling thread, e.g.<pre class='code prettyprint lang-sc'>t= TempoClock.new;
t.schedAbs(t.nextBar, {t.beatsPerBar_(3)});
t.beatsPerBar;</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-bar' href='./../Overviews/Methods.html#bar'>bar</a> </h3>
<div class='method'>
<p>Returns the current bar. See <a href="#-bars2beats">-bars2beats</a> for returning beat of current bar.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-nextBar' href='./../Overviews/Methods.html#nextBar'>nextBar</a> (<span class='argstr'>beat</span>)</h3>
<div class='method'>
<p>Returns the number of beats at the next bar line relative to the beat argument. If <strong>beat</strong> is not supplied, returns the beat at which the next bar begins.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-beatInBar' href='./../Overviews/Methods.html#beatInBar'>beatInBar</a> </h3>
<div class='method'>
<p>Returns the current bar beat (as a <a href="./../Classes/Float.html">Float</a>) in relation to <a href="#-beatsPerBar">-beatsPerBar</a>. Values range from 0 to &lt; beatsPerBar.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-baseBar' href='./../Overviews/Methods.html#baseBar'>baseBar</a> </h3>
<div class='method'>
<p>Returns bar at which <a href="#-beatsPerBar">-beatsPerBar</a> was last changed. If beatsPerBar has not been changed since the clock was created, returns 0.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-baseBarBeat' href='./../Overviews/Methods.html#baseBarBeat'>baseBarBeat</a> </h3>
<div class='method'>
<p>Returns beat at which the <a href="#-beatsPerBar">-beatsPerBar</a> was last changed. If beatsPerBar has not been changed since the clock was created, returns 0.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-beats2bars' href='./../Overviews/Methods.html#beats2bars'>beats2bars</a> (<span class='argstr'>beats</span>)</h3>
<div class='method'>
<p>Returns a bar as a float relative to <a href="#-baseBarBeat">-baseBarBeat</a>.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-bars2beats' href='./../Overviews/Methods.html#bars2beats'>bars2beats</a> (<span class='argstr'>bars</span>)</h3>
<div class='method'>
<p>Returns a beat relative to <a href="#-baseBar">-baseBar</a>.<pre class='code prettyprint lang-sc'>t= TempoClock.default;
t.bars2beats(t.bar) // downbeat of the current bar</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-timeToNextBeat' href='./../Overviews/Methods.html#timeToNextBeat'>timeToNextBeat</a> (<span class='argstr'>quant: 1</span>)</h3>
<div class='method'>
<p>Returns the logical time to next beat. <strong>quant</strong> is 1 by default, relative to baseBarBeat, see <a href="#-nextTimeOnGrid">-nextTimeOnGrid</a>.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-nextTimeOnGrid' href='./../Overviews/Methods.html#nextTimeOnGrid'>nextTimeOnGrid</a> (<span class='argstr'>quant: 1</span>, <span class='argstr'>phase: 0</span>)</h3>
<div class='method'>
<p>With default values, returns the next whole beat. <strong>quant</strong> is 1 by default, <strong>phase</strong> is 0. quant is relative to <a href="#-baseBarBeat">-baseBarBeat</a>, such that<pre class='code prettyprint lang-sc'>t= TempoClock.default;
t.nextTimeOnGrid(t.beatsPerBar) == t.nextBar // =&gt; true</pre>
<p>Together <strong>quant</strong> and <strong>phase</strong> are useful for finding the next n beat in a bar, e.g. <code class='code prettyprint lang-sc'>nextTimeOnGrid(4, 2)</code> will return the next 3rd beat of a bar (of 4 beats), whereas <code class='code prettyprint lang-sc'>nextBar-2</code> may return an elapsed beat.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-elapsedBeats' href='./../Overviews/Methods.html#elapsedBeats'>elapsedBeats</a> </h3>
<div class='method'>
<p>Returns the current elapsed time in beats. This is equivalent to <code class='code prettyprint lang-sc'>tempoClock.secs2beats(Main.elapsedTime)</code>. It is often preferable to use <a href="#-beats">-beats</a> instead of elapsedBeats because beats uses a thread's logical time.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-seconds' href='./../Overviews/Methods.html#seconds'>seconds</a> </h3>
<div class='method'>
<p>Returns the current elapsed time. (This method is inherited from <a href="./../Classes/Clock.html">Clock</a>.)</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-beats2secs' href='./../Overviews/Methods.html#beats2secs'>beats2secs</a> (<span class='argstr'>beats</span>)</h3>
<div class='method'>
<p>Converts absolute <strong>beats</strong> to absolute <strong>seconds</strong>, returning the elapsed time of the clock at the given <strong>beats</strong>. Only works for times in the current tempo. If the tempo changes any computed time in future will be wrong.<pre class='code prettyprint lang-sc'>t= TempoClock.default;
t.beats2secs(t.beats) // equivalent to t.seconds
t.beats2secs(0) // how many seconds after startup did beat 0 occur?</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-secs2beats' href='./../Overviews/Methods.html#secs2beats'>secs2beats</a> (<span class='argstr'>secs</span>)</h3>
<div class='method'>
<p>Converts absolute <strong>seconds</strong> to absolute beats. Only works for times in the current tempo. If the tempo changes any computed time in future will be wrong.</div><h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
<div id='inheritedinstmets'></div><h3><a class='anchor' name='Undocumented%20instance%20methods'>Undocumented instance methods</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-archiveAsCompileString' href='./../Overviews/Methods.html#archiveAsCompileString'>archiveAsCompileString</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-etempo' href='./../Overviews/Methods.html#etempo'>etempo</a> = <span class='argstr'>newTempo</span></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-setMeterAtBeat' href='./../Overviews/Methods.html#setMeterAtBeat'>setMeterAtBeat</a> (<span class='argstr'>newBeatsPerBar</span>, <span class='argstr'>beats</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-setTempoAtBeat' href='./../Overviews/Methods.html#setTempoAtBeat'>setTempoAtBeat</a> (<span class='argstr'>newTempo</span>, <span class='argstr'>beats</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-setTempoAtSec' href='./../Overviews/Methods.html#setTempoAtSec'>setTempoAtSec</a> (<span class='argstr'>newTempo</span>, <span class='argstr'>secs</span>)</h3>
<h2><a class='anchor' name='examples'>Examples</a></h2>
<pre class='code prettyprint lang-sc'>t = TempoClock(1); // create a TempoClock
// schedule an event at next whole beat
t.schedAbs(t.beats.ceil, { arg beat, sec; [beat, sec].postln; 1 });
t.tempo = 2;
t.tempo = 4;
t.tempo = 0.5;
t.tempo = 1;
t.clear;
t.schedAbs(t.beats.ceil, { arg beat, sec; [beat, sec].postln; 1 });
t.stop;</pre>
<p><pre class='code prettyprint lang-sc'>(
// get elapsed time, round up to next second
v = Main.elapsedTime.ceil;
// create two clocks in a 5:2 relation, starting at time v.
t = TempoClock(1, 0, v);
u = TempoClock(0.4, 0, v);
// start two functions at beat zero in each clock.
t.schedAbs(0, { arg beat, sec; [\t, beat, sec].postln; 1 });
u.schedAbs(0, { arg beat, sec; [\u, beat, sec].postln; 1 });
)
(
u.tempo = u.tempo * 3;
t.tempo = t.tempo * 3;
)
(
u.tempo = u.tempo * 1/4;
t.tempo = t.tempo * 1/4;
)
(
t.stop;
u.stop;
)</pre>
<p><pre class='code prettyprint lang-sc'>(
// get elapsed time, round up to next second
v = Main.elapsedTime.ceil;
// create two clocks, starting at time v.
t = TempoClock(1, 0, v);
u = TempoClock(1, 0, v);
// start two functions at beat zero in each clock.
// t controls u's tempo. They should stay in sync.
t.schedAbs(0, { arg beat, sec; u.tempo = t.tempo * [1,2,3,4,5].choose; [\t, beat, sec].postln; 1 });
u.schedAbs(0, { arg beat, sec; [\u, beat, sec].postln; 1 });
)
(
u.tempo = u.tempo * 3;
t.tempo = t.tempo * 3;
)
(
u.tempo = u.tempo * 1/4;
t.tempo = t.tempo * 1/4;
)
(
t.stop;
u.stop;
)</pre>
<p><div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/TempoClock.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/TempoClock.schelp</a><br>link::Classes/TempoClock::<br>sc version: 3.8.0</div></div></body></html>