142 lines
No EOL
6.8 KiB
HTML
142 lines
No EOL
6.8 KiB
HTML
<!doctype html><html lang='en'><head><title>Condition | 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 = 'Condition';
|
|
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'>Condition:</div>
|
|
<span class='toc_search'>Filter: <input id='toc_search'></span><ul class='toc'><li class='toc1'><a href='#classmethods'>Class methods</a></li>
|
|
<ul class='toc'><li class='toc3'><a href='#*new'>new</a> </li>
|
|
<li class='toc2'><a href='#Inherited%20class%20methods'>Inherited class methods</a></li>
|
|
</ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
|
|
<ul class='toc'><li class='toc3'><a href='#-test'>test</a> </li>
|
|
<li class='toc3'><a href='#-wait'>wait</a> </li>
|
|
<li class='toc3'><a href='#-hang'>hang</a> </li>
|
|
<li class='toc3'><a href='#-signal'>signal</a> </li>
|
|
<li class='toc3'><a href='#-unhang'>unhang</a> </li>
|
|
<li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
|
|
</ul><li class='toc1'><a href='#examples'>Examples</a></li>
|
|
<ul class='toc'></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></span>
|
|
</div><h1>Condition<span id='superclasses'> : <a href="../Classes/Object.html">Object</a></span>
|
|
</h1>
|
|
<div id='summary'>Block the execution of a thread</div>
|
|
</div>
|
|
<div class='subheader'>
|
|
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Condition.sc' title='/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Core/Condition.sc'>Condition.sc</a></div></div>
|
|
<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
|
|
<h3 class='method-code'><span class='method-prefix'>Condition.</span><a class='method-name' name='*new' href='./../Overviews/Methods.html#new'>new</a>(<span class='argstr'>test: false</span>)</h3>
|
|
<div class='method'>
|
|
<p>Create a new instance, set the <strong>test</strong> variable.</div><h3><a class='anchor' name='Inherited%20class%20methods'>Inherited class methods</a></h3>
|
|
<div id='inheritedclassmets'></div><h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
|
|
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-test' href='./../Overviews/Methods.html#test'>test</a></h3>
|
|
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-test' href='./../Overviews/Methods.html#test'>test</a> = value</h3>
|
|
<div class='method'>
|
|
<p>Answer whether the condition will block or not (boolean).</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-wait' href='./../Overviews/Methods.html#wait'>wait</a></h3>
|
|
<div class='method'>
|
|
<p>Wait until the condition is true and signalled. This only works in a Routine. This method yields a symbol (\hang), so that the clock doesn't reschedule the Routine.<pre class='code prettyprint lang-sc'>c = Condition(false); fork { 0.5.wait; "started ...".postln; c.wait; "... and finished.".postln };
|
|
c.test = true;
|
|
c.signal;</pre>
|
|
</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-hang' href='./../Overviews/Methods.html#hang'>hang</a>(<span class='argstr'>value: 'hang'</span>)</h3>
|
|
<div class='method'>
|
|
<p>Wait for <strong>value</strong> time, regardless of test. This only works in a Routine. This method yields a symbol (\hang), so that the clock doesn't reschedule the Routine.<pre class='code prettyprint lang-sc'>c = Condition.new; fork { 0.5.wait; "started ...".postln; c.hang; "... and finished.".postln };
|
|
c.unhang;</pre>
|
|
</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-signal' href='./../Overviews/Methods.html#signal'>signal</a></h3>
|
|
<div class='method'>
|
|
<p>If <a href="#-test">-test</a> is true, reschedule blocked threads.</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-unhang' href='./../Overviews/Methods.html#unhang'>unhang</a></h3>
|
|
<div class='method'>
|
|
<p>Resume threads.</div><h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
|
|
<div id='inheritedinstmets'></div><h2><a class='anchor' name='examples'>Examples</a></h2>
|
|
<pre class='code prettyprint lang-sc'>(
|
|
c = Condition.new(false);
|
|
|
|
Routine {
|
|
1.wait;
|
|
"waited for 1 second".postln;
|
|
1.wait;
|
|
"waited for another second, now waiting for you ... ".postln;
|
|
c.wait;
|
|
"the condition has stopped waiting.".postln;
|
|
1.wait;
|
|
"waited for another second".postln;
|
|
"waiting for you ... ".postln;
|
|
c.test = false;
|
|
c.wait;
|
|
"the condition has stopped waiting.".postln;
|
|
1.wait;
|
|
"the end".postln;
|
|
}.play;
|
|
)
|
|
|
|
// continue
|
|
(
|
|
c.test = true;
|
|
c.signal;
|
|
)
|
|
|
|
// a typical use is a routine that can pause under certain conditions:
|
|
(
|
|
c = Condition.new;
|
|
fork { loop { 1.wait; "going".postln; c.wait } };
|
|
)
|
|
c.test = true; c.signal;
|
|
c.test = false;</pre>
|
|
<pre class='code prettyprint lang-sc'>// the same, using hang
|
|
|
|
(
|
|
c = Condition.new;
|
|
|
|
Routine {
|
|
1.wait;
|
|
"waited for 1 second".postln;
|
|
1.wait;
|
|
"waited for another second, now waiting for you ... ".postln;
|
|
c.hang;
|
|
"the condition has stopped waiting.".postln;
|
|
1.wait;
|
|
"waited for another second".postln;
|
|
"waiting for you ... ".postln;
|
|
c.hang;
|
|
"the condition has stopped waiting.".postln;
|
|
}.play;
|
|
)
|
|
|
|
// continue
|
|
c.unhang;</pre>
|
|
|
|
<p>Waiting for Synths to end (waitForFree) uses a Condition implicitly:<pre class='code prettyprint lang-sc'>(
|
|
SynthDef(\help, { |out|
|
|
var mod = LFNoise2.kr(ExpRand(0.5, 2)) * 0.5;
|
|
var snd = mod * Blip.ar(Rand(200, 800) * (mod + 1));
|
|
Out.ar(out, snd);
|
|
FreeSelf.kr(mod < 0); // free the synth when amplitude goes below 0.
|
|
}).add;
|
|
)
|
|
|
|
(
|
|
fork {
|
|
10.do {
|
|
"started a synth".postln;
|
|
Synth(\help).waitForFree;
|
|
"This one ended. Wait a second, I will start the next one.".postln;
|
|
1.wait;
|
|
};
|
|
"This is it.".postln;
|
|
}
|
|
);</pre>
|
|
<div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/Condition.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/Condition.schelp</a><br>link::Classes/Condition::<br></div></div></body></html> |