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

394 lines
27 KiB
HTML
Raw Permalink Normal View History

2022-08-24 13:53:18 +00:00
<!doctype html><html lang='en'><head><title>Tdef | SuperCollider 3.10.3 Help</title>
<link rel='stylesheet' href='./../scdoc.css' type='text/css' />
<link rel='stylesheet' href='./../codemirror.css' type='text/css' />
<link rel='stylesheet' href='./../editor.css' type='text/css' />
<link rel='stylesheet' href='./../frontend.css' type='text/css' />
<link rel='stylesheet' href='./../custom.css' type='text/css' />
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script src='./../lib/jquery.min.js'></script>
<script src='./../lib/codemirror-5.39.2.min.js' type='text/javascript'></script>
<script src='./../lib/codemirror-addon-simple-5.39.2.min.js' type='text/javascript'></script>
<script>
var helpRoot = './..';
var scdoc_title = 'Tdef';
var scdoc_sc_version = '3.10.3';
</script>
<script src='./../scdoc.js' type='text/javascript'></script>
<script src='./../docmap.js' type='text/javascript'></script>
<script src='qrc:///qtwebchannel/qwebchannel.js' type='text/javascript'></script>
</head>
<body onload='fixTOC()'>
<div id='toc'>
<div id='toctitle'>Tdef:</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='#First%20Example'>First Example</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='#Creation'>Creation</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='toc3'><a href='#*removeAll'>removeAll</a> </li>
<li class='toc3'><a href='#*clear'>clear</a> </li>
<li class='toc3'><a href='#*all'>all</a> </li>
<li class='toc3'><a href='#*defaultQuant'>defaultQuant</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='#*gui'>gui</a> </li>
<li class='toc3'><a href='#*hasGlobalDictionary'>hasGlobalDictionary</a> </li>
</ul></ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Changing%20the%20definition%20/%20setting%20the%20source'>Changing the definition / setting the source</a></li>
<ul class='toc'><li class='toc3'><a href='#-quant'>quant</a> </li>
<li class='toc3'><a href='#-condition'>condition</a> </li>
<li class='toc3'><a href='#-count'>count</a> </li>
<li class='toc3'><a href='#-reset'>reset</a> </li>
<li class='toc3'><a href='#-envir'>envir</a> </li>
<li class='toc3'><a href='#-set'>set</a> </li>
<li class='toc3'><a href='#-clear'>clear</a> </li>
<li class='toc3'><a href='#-endless'>endless</a> </li>
</ul><li class='toc2'><a href='#Tdef%20as%20stream%20reference'>Tdef as stream reference</a></li>
<ul class='toc'><li class='toc3'><a href='#-fork'>fork</a> </li>
<li class='toc3'><a href='#-embed'>embed</a> </li>
<li class='toc3'><a href='#-embedInStream'>embedInStream</a> </li>
</ul><li class='toc2'><a href='#Tdef%20as%20EventStreamPlayer'>Tdef as EventStreamPlayer</a></li>
<ul class='toc'><li class='toc3'><a href='#-play'>play</a> </li>
<li class='toc3'><a href='#-stop'>stop</a> </li>
<li class='toc3'><a href='#-player'>player</a> </li>
<li class='toc3'><a href='#-pause'>pause</a> <a href='#-resume'>resume</a> <a href='#-reset'>reset</a> </li>
<li class='toc3'><a href='#-isPlaying'>isPlaying</a> </li>
</ul><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='#-copy'>copy</a> </li>
<li class='toc3'><a href='#-gui'>gui</a> </li>
<li class='toc3'><a href='#-key'>key</a> </li>
<li class='toc3'><a href='#-prAdd'>prAdd</a> </li>
</ul></ul><li class='toc1'><a href='#examples'>Examples</a></li>
<ul class='toc'><li class='toc2'><a href='#Tdef%20as%20a%20Task%20player'>Tdef as a Task player</a></li>
<ul class='toc'></ul><li class='toc2'><a href='#Embed%20and%20fork:%20Tdef%20within%20other%20Tasks%20/%20Routines'>Embed and fork: Tdef within other Tasks / Routines</a></li>
<ul class='toc'></ul><li class='toc2'><a href='#Tdef%20as%20a%20time%20pattern'>Tdef as a time pattern</a></li>
<ul class='toc'></ul></ul></ul></div><div id='menubar'></div>
<div class='contents'>
<div class='header'>
<div id='label'>
<span id='folder'>Classes</span>
| <span id='categories'><a href='./../Browse.html#JITLib'>JITLib</a>&#8201;&gt;&#8201;<a href='./../Browse.html#JITLib>Patterns'>Patterns</a></span>
</div><h1>Tdef<span id='superclasses'> : <a href="../Classes/TaskProxy.html">TaskProxy</a> : <a href="../Classes/PatternProxy.html">PatternProxy</a> : <a href="../Classes/Pattern.html">Pattern</a> : <a href="../Classes/AbstractFunction.html">AbstractFunction</a> : <a href="../Classes/Object.html">Object</a></span>
</h1>
<div id='summary'>task reference definition</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/Patterns/Pdef.sc' title='/Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/Patterns/Pdef.sc'>Pdef.sc</a></div><div id='related'>See also: <a href="./../Classes/TaskProxy.html">TaskProxy</a>, <a href="./../Classes/Task.html">Task</a>, <a href="./../Classes/Routine.html">Routine</a></div>
</div>
<h2><a class='anchor' name='description'>Description</a></h2>
<p>Tdef registers tasks by key. All accesses to the registered tasks go through the Tdef class via that key. Registered tasks can be replaced with other tasks while playing. The old task and its replacement can automatically crossfade and the replacement time can be quantized.
<p>Tdef provides an interface to its superclass TaskProxy. Tdef keeps a reference to a task ( <strong>time pattern</strong> ) that can be replaced while playing. It continues playing when the old stream ended and a new stream is set and schedules the changes to the beat. One Tdef may be used in many tasks in different places. A change in the task definition Tdef propagates through all tasks.<textarea class='editor'>Tdef(key) //returns the instance
Tdef(key, func) //defines the task and returns the instance, like Pdef and Ndef.</textarea>
<p>Graphical overview over all current Tdefs: <a href="./../Classes/TdefAllGui.html">TdefAllGui</a>. Overview: <a href="./../Overviews/JITLib.html">JITLib</a><h3><a class='anchor' name='First%20Example'>First Example</a></h3>
<textarea class='editor'>Tdef(\x, { loop { 0.5.wait; "aaaaaaaaaaaaaazz".scramble.postln } }).play;
Tdef(\x, { loop { 0.125.wait; "aazz".scramble.postln } });
Tdef(\x, { loop { 0.5.wait; (note: 14.rand).play } });
Tdef(\x, { loop { 0.5.wait; (note: 14.rand + [0, 3, 6, 7].keep(4.rand)).play } });
Tdef(\x).stop;
Tdef(\x).play;
Tdef(\x).clear;</textarea>
<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3><a class='anchor' name='Creation'>Creation</a></h3>
<h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*new' href='./../Overviews/Methods.html#new'>new</a>(<span class='argstr'>key</span>, <span class='argstr'>item</span>)</h3>
<div class='method'>
<p>Store the task in a global dictionary under key, replacing its routine function with the new one.
<p>Using <strong>*new(key)</strong> you can access the pattern at that key (if none is given, a default task is created)</div><h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*default' href='./../Overviews/Methods.html#default'>default</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Default source, if none is given. The default task has a function that waits in 1.0 beat steps and does nothing.</div><h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*removeAll' href='./../Overviews/Methods.html#removeAll'>removeAll</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Remove all proxies from the global dictionary ( <a href="#*all">*all</a> )</div><h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*clear' href='./../Overviews/Methods.html#clear'>clear</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Clear all proxies, setting their source to silence.</div><h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*all' href='./../Overviews/Methods.html#all'>all</a></h3>
<h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*all' href='./../Overviews/Methods.html#all'>all</a> = value</h3>
<div class='method'>
<p>Set or return the environment ( <a href="./../Classes/IdentityDictionary.html">IdentityDictionary</a> ) that stores all instances.</div><h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*defaultQuant' href='./../Overviews/Methods.html#defaultQuant'>defaultQuant</a></h3>
<h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*defaultQuant' href='./../Overviews/Methods.html#defaultQuant'>defaultQuant</a> = value</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Set the default quantisation for new instances (default: 1.0). This can be an array [quant, phase, timingOffset, outset]</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='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*gui' href='./../Overviews/Methods.html#gui'>gui</a>(<span class='argstr'>numItems</span>, <span class='argstr'>bounds</span>, <span class='argstr'>preset</span>)</h3>
<div class='extmethod'>From extension in <a href='file:///Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/GUI/extJITgui.sc'>/Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/GUI/extJITgui.sc</a></div>
<h3 class='method-code'><span class='method-prefix'>Tdef.</span><a class='method-name' name='*hasGlobalDictionary' href='./../Overviews/Methods.html#hasGlobalDictionary'>hasGlobalDictionary</a></h3>
<h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3><a class='anchor' name='Changing%20the%20definition%20/%20setting%20the%20source'>Changing the definition / setting the source</a></h3>
<p>One Tdef may have many tasks in different places. A change in the task definition Tdef propagates through all tasks. The change does not have to be immediate - there is a scheme to schedule when the change becomes effective: a <strong>quant</strong> and <strong>clock</strong> (like elsewhere) and a <strong>condition</strong>.<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-quant' href='./../Overviews/Methods.html#quant'>quant</a></h3>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-quant' href='./../Overviews/Methods.html#quant'>quant</a> = <span class='argstr'>val</span></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Set the quantisation time for beat accurate scheduling.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>val<td class='argumentdesc'>
<p>can be an array <strong>[quant, phase, timingOffset, outset]</strong>, or just <strong>[quant, phase]</strong> etc.</table></div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-condition' href='./../Overviews/Methods.html#condition'>condition</a></h3>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-condition' href='./../Overviews/Methods.html#condition'>condition</a> = value</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Provide a condition under which the pattern is switched when a new one is inserted. The stream value and a count value is passed into the function.</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-count' href='./../Overviews/Methods.html#count'>count</a>(<span class='argstr'>n: 1</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Create and update condition that simply counts up to n and switches the pattern then</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-reset' href='./../Overviews/Methods.html#reset'>reset</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Switch the task immediately (stuck conditions can be subverted by this).</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-envir' href='./../Overviews/Methods.html#envir'>envir</a></h3>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-envir' href='./../Overviews/Methods.html#envir'>envir</a> = value</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Set the environment (an <a href="./../Classes/Event.html">Event</a>) for the Tdef. <strong>It is passed as first argument into the Task function</strong>.</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-set' href='./../Overviews/Methods.html#set'>set</a>( <span class='argstr'>... args</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Set arguments in the default event. If there is none, it is created and the task routine is rebuilt.</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-clear' href='./../Overviews/Methods.html#clear'>clear</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Set the source to nil</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-endless' href='./../Overviews/Methods.html#endless'>endless</a>(<span class='argstr'>default</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Returns a <a href="./../Classes/Prout.html">Prout</a> that plays the task endlessly, replacing <strong>nil</strong> with a <strong>default</strong> value 1. This allows to create streams that idle on until a new pattern is inserted.</div><h3><a class='anchor' name='Tdef%20as%20stream%20reference'>Tdef as stream reference</a></h3>
<p>A single Tdef may serve as a definition for multiple tasks. These methods show how to fork off separate routines from one instance. Even if they run in different contexts, their definition may still be changed.<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-fork' href='./../Overviews/Methods.html#fork'>fork</a>(<span class='argstr'>clock</span>, <span class='argstr'>quant</span>, <span class='argstr'>event</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Play an independent task in parallel.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>clock<td class='argumentdesc'>
<p>the clock on which to play the forked task<tr><td class='argumentname'>quant<td class='argumentdesc'>
<p>can be an array of [quant, phase, offset], or a <a href="./../Classes/Quant.html">Quant</a> value.<tr><td class='argumentname'>event<td class='argumentdesc'>
<p>an event to pass into the forked task</table></div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-embed' href='./../Overviews/Methods.html#embed'>embed</a>(<span class='argstr'>val</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Pass a value (typically an <a href="./../Classes/Event.html">Event</a>) into the task function, and embed the Tdef in the stream.</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-embedInStream' href='./../Overviews/Methods.html#embedInStream'>embedInStream</a>(<span class='argstr'>inval</span>, <span class='argstr'>embed: true</span>, <span class='argstr'>default</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>just like any pattern, embeds itself in stream</div><h3><a class='anchor' name='Tdef%20as%20EventStreamPlayer'>Tdef as EventStreamPlayer</a></h3>
<p>For live coding, each Tdef also may control one instance that plays one task. This is a <a href="./../Classes/PauseStream.html">PauseStream</a>, accessible in the instance variable <a href="#-player">-player</a>.<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-play' href='./../Overviews/Methods.html#play'>play</a>(<span class='argstr'>argClock</span>, <span class='argstr'>doReset: false</span>, <span class='argstr'>quant</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Starts the Tdef and creates a player.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>argClock<td class='argumentdesc'>
<p>a clock on which to play the Tdef<tr><td class='argumentname'>doReset<td class='argumentdesc'>
<p>a flag whether to reset the task if already playing<tr><td class='argumentname'>quant<td class='argumentdesc'>
<p>can be an array of [quant, phase, offset] or a <a href="./../Classes/Quant.html">Quant</a> value.</table></div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-stop' href='./../Overviews/Methods.html#stop'>stop</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Stops the player</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-player' href='./../Overviews/Methods.html#player'>player</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Return the current player (if the Tdef is simply used in other streams this is nil)</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-pause' href='./../Overviews/Methods.html#pause'>pause</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-resume' href='./../Overviews/Methods.html#resume'>resume</a>(<span class='argstr'>clock</span>, <span class='argstr'>quant</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-reset' href='./../Overviews/Methods.html#reset'>reset</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/PatternProxy.html'>PatternProxy</a></div>
<div class='method'>
<p>Perform this method on the player.</div><h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-isPlaying' href='./../Overviews/Methods.html#isPlaying'>isPlaying</a></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/TaskProxy.html'>TaskProxy</a></div>
<div class='method'>
<p>Returns true if player is running. If a Tdef is playing and its stream ends, it will schedule a stream for playing <strong>as soon as a new one is assigned to it</strong>. If it is stopped by <strong>stop</strong>, it won't.</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='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-copy' href='./../Overviews/Methods.html#copy'>copy</a>(<span class='argstr'>toKey</span>)</h3>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-gui' href='./../Overviews/Methods.html#gui'>gui</a>(<span class='argstr'>numItems</span>, <span class='argstr'>bounds</span>, <span class='argstr'>preset</span>)</h3>
<div class='extmethod'>From extension in <a href='file:///Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/GUI/extJITgui.sc'>/Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/GUI/extJITgui.sc</a></div>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-key' href='./../Overviews/Methods.html#key'>key</a></h3>
<h3 class='method-code'><span class='method-prefix'>.</span><a class='method-name' name='-prAdd' href='./../Overviews/Methods.html#prAdd'>prAdd</a>(<span class='argstr'>argKey</span>)</h3>
<h2><a class='anchor' name='examples'>Examples</a></h2>
<h3><a class='anchor' name='Tdef%20as%20a%20Task%20player'>Tdef as a Task player</a></h3>
<textarea class='editor'>Tdef(\x).play; // create an empty Tdef and play it.
Tdef(\x, { loop({ "ggggggggggggggggg9999ggg999ggg999gg".scramble.postln; 0.5.wait; }) });
Tdef(\x, { loop({ "---------////----------------------".scramble.postln; 0.25.wait; }) });
Tdef(\x, { loop({ thisThread.seconds.postln; 1.wait; }) });
Tdef(\x, { loop({ thisThread.seconds.postln; 1.01.wait; }) });
TempoClock.default.tempo = 2;
Tdef(\x, { "the end".postln });
Tdef(\x, { "one more".postln });
Tdef(\x, { 10.do({ "ten more".scramble.postln; 0.25.wait; }) });
Tdef(\x, { loop({ "lots more".scramble.postln; 0.25.wait; }) });
TempoClock.default.tempo = 1;
Tdef(\x).stop;
Tdef(\x).play;
Tdef(\x).clear;</textarea>
<textarea class='editor'>// sound example
(
// load a synthdef
s.boot;
SynthDef(\pdef_grainlet,
{ arg out=0, freq=440, sustain=0.05;
var env;
env = EnvGen.kr(Env.perc(0.01, sustain, 0.3), doneAction: Done.freeSelf);
Out.ar(out, SinOsc.ar(freq, 0, env))
}).add;
)
Tdef(\x).play;
(
Tdef(\x, {
loop({
s.sendMsg("/s_new", "pdef_grainlet", -1,0,0, \freq, rrand(600, 640));
0.1.wait;
})
})
)
(
Tdef(\x, {
var x;
x = Pseries(300, 20, 100).loop.asStream;
loop({
s.sendMsg("/s_new", "pdef_grainlet", -1,0,0, \freq, x.next);
0.05.wait;
})
})
)
(
Tdef(\x, {
var x;
x = Plazy({ Pseries(300 + 300.rand, 10 + 30.rand, 10 + 30.rand) }).loop.asStream;
loop({
s.sendMsg("/s_new", "pdef_grainlet", -1,0,0, \freq, x.next);
0.05.wait;
})
})
)
// metronome
Tdef(\y, { loop({ s.sendMsg("/s_new", "pdef_grainlet", -1,0,0, \freq, 1500); 1.wait; }) }).play;
// play ending stream once
(
Tdef(\x, {
var x, dt;
dt = [0.1, 0.125, 0.05].choose;
x = Plazy({ Pseries(1300 + 300.rand, 110 + 130.rand, 16) }).asStream;
x.do({ arg item;
s.sendMsg("/s_new", "pdef_grainlet", -1,0,0, \freq, item);
dt.wait;
})
})
)
// ... and so on ...
Tdef(\x).stop;
Tdef.removeAll;</textarea>
<h3><a class='anchor' name='Embed%20and%20fork:%20Tdef%20within%20other%20Tasks%20/%20Routines'>Embed and fork: Tdef within other Tasks / Routines</a></h3>
<textarea class='editor'>// embed plays tdefs in sequence within a task.
(
Tdef(\a, { "one".postln; 1.wait; "two".postln });
Tdef(\c, { var z; z = Synth(\default); 0.5.wait; z.release });
r = Task({
"counting...".postln;
2.wait;
Tdef(\a).embed;
1.wait;
Tdef(\c).embed;
"done.".postln;
});
)
r.play; // play a stream
Tdef(\c, { var z; z = Synth(\default, [\freq, 300]); 1.5.wait; z.release }); // change the def
r.reset;
r.play;
// of course Tdefs can be used in other Tdefs:
(
Tdef(\a, { 10.do { |i| (" a: " + i).postln; 0.3.wait; } });
Tdef(\b, { 15.do { |i| ("\t\t b: " + i).postln; 0.2.wait; } });
Tdef(\c, { 5.do { |i| ("\t\t\t\t c: " + i).postln; 0.5.wait; } });
Tdef(\d, {
"embed - sequence.".postln;
1.wait;
Tdef(\a).embed;
1.wait;
Tdef(\b).embed;
1.wait;
Tdef(\c).embed;
"done.".postln;
});
)
Tdef(\d).play;
// to start a tdef in its own separate thread, thus branching into parallel threads,
// one can use .fork, or .playOnce
(
Tdef(\a, { 10.do { |i| (" a: " + i).postln; 0.3.wait; } });
Tdef(\b, { 15.do { |i| ("\t\t b: " + i).postln; 0.2.wait; } });
Tdef(\c, { 5.do { |i| ("\t\t\t\t c: " + i).postln; 0.5.wait; } });
Tdef(\d, {
"fork - parallel.".postln;
1.wait;
Tdef(\a).fork;
1.wait;
Tdef(\b).fork;
1.wait;
Tdef(\c).fork;
"done.".postln;
});
)</textarea>
<h3><a class='anchor' name='Tdef%20as%20a%20time%20pattern'>Tdef as a time pattern</a></h3>
<p>Instead of using a <a href="./../Classes/Pdefn.html">Pdefn</a> for time values, it can be useful to use a Tdef. When changing its source, it keeps the stream of values synchronized to its clock.<textarea class='editor'>(
// load a synthdef
s.boot;
SynthDef("pdef_grainlet",
{ arg out=0, freq=440, sustain=0.05;
var env;
env = EnvGen.kr(Env.perc(0.01, sustain, 0.3), doneAction: Done.freeSelf);
Out.ar(out, SinOsc.ar(freq, 0, env))
}).add;
)
Tdef(\z, Pseq([1, 1, 1, 0.5, 0.5], inf));
(
Pset(\instrument, \pdef_grainlet,
Ppar([
Pbind(
\dur, Tdef(\z),
\note, Pseq([1, 3, 2, 1, 0], inf),
\x, Pfunc { TempoClock.default.elapsedBeats.postln } // posts the onset times
),
Pbind(
\dur, 4, // reference beat
\sustain, 0.1,
\note, 8
)
])
).play(quant:1);
)
Tdef(\z, Prand([1, 1, 0.23, 0.5, 0.5], inf)); // exchange time pattern
Tdef(\z, Pseq([1, 1, 1, 1], inf)); // pattern stays in sync.
Tdef(\z, Pseq([1, 1, 1, 0.5, 0.5], inf)); // but might be in different order.
// to avoid this, set quant to an appropriate value.</textarea>
<p><div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider/SuperCollider.app/Contents/Resources/HelpSource/Classes/Tdef.schelp'>/Applications/SuperCollider/SuperCollider.app/Contents/Resources/HelpSource/Classes/Tdef.schelp</a><br>link::Classes/Tdef::<br></div></div><script src='./../editor.js' type='text/javascript'></script>
</body></html>