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=
"1038.25">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0000ee}
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 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
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: #bf0000}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
; min-height: 14.0px}
20 p
.p11
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; min-height: 12.0px}
21 p
.p12
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #007300}
22 p
.p13
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0000bf}
23 p
.p14
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
; min-height: 17.0px}
24 p
.p15
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000; min-height: 12.0px}
25 p
.p16
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0000ee}
26 p
.p17
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0000bf; min-height: 12.0px}
27 span
.s1
{font: 18.0px Helvetica
}
28 span
.s2
{font: 9.0px Monaco
}
29 span
.s3
{color: #000000}
30 span
.s4
{text-decoration: underline
}
31 span
.s5
{color: #0000bf}
32 span
.s6
{text-decoration: underline
; color: #0000bf}
33 span
.s7
{color: #1034f0}
34 span
.s8
{color: #007300}
35 span
.s9
{color: #bf0000}
36 span
.s10
{color: #606060}
37 span
.Apple-tab-span
{white-space:pre
}
41 <p class=
"p1"><span class=
"s1"><b>Pdef
<span class=
"Apple-tab-span"> </span></b></span><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span><b>stream reference definition
</b></p>
42 <p class=
"p2"><br></p>
43 <p class=
"p3"><span class=
"s3"><b>Inherits from:
<span class=
"Apple-converted-space"> </span></b> <a href=
"../../../Core/Object.html"><span class=
"s4">Object
</span></a> :
<a href=
"../../../Core/Kernel/AbstractFunction.html"><span class=
"s4">AbstractFunction
</span></a> :
<a href=
"../../../Streams-Patterns-Events/Patterns/Pattern.html"><span class=
"s4">Pattern
</span></a> :
<a href=
"PatternProxy.html"><span class=
"s4">PatternProxy
</span></a> :
<a href=
"TaskProxy.html"><span class=
"s4">TaskProxy
</span></a> :
<a href=
"EventPatternProxy.html"><span class=
"s4">EventPatternProxy
</span></a></span></p>
44 <p class=
"p4"><br></p>
45 <p class=
"p1">Pdef is a class that provides an interface to its superclass
<a href=
"EventPatternProxy.html"><span class=
"s5">EventPatternProxy
</span></a>, keeping a reference to a stream that can be replaced while playing. One pattern may be used in many streams in different places. A change in the pattern definition propagates through all streams.
</p>
46 <p class=
"p4"><br></p>
47 <p class=
"p1"><b>Pdef(key)
</b> returns the instance
<span class=
"Apple-converted-space"> </span></p>
48 <p class=
"p1"><b>Pdef(key, pat)
</b> stores the pattern and returns the instance, like
<a href=
"Tdef.html"><span class=
"s5">Tdef
</span></a> and
<a href=
"../nodeproxy/Ndef.html"><span class=
"s5">Ndef
</span></a>.
</p>
49 <p class=
"p4"><br></p>
50 <p class=
"p1">It can be used to store event Patterns globally. Changes in this global library have immediate effect.
</p>
51 <p class=
"p4"><br></p>
52 <p class=
"p1">For
<b>non-event patterns
</b> <a href=
"Pdefn.html"><span class=
"s6">Pdefn
</span></a> is used instead.
</p>
53 <p class=
"p5">For another use of Pdef see also
<a href=
"../tutorials/recursive_phrasing.html"><span class=
"s5">recursive_phrasing
</span></a></p>
54 <p class=
"p1">Graphical overview over all current Pdefs:
<a href=
"../extras/PdefAllGui.html"><span class=
"s5">PdefAllGui
</span></a></p>
55 <p class=
"p1">Overview:
<a href=
"../JITLib.html"><span class=
"s7">JITLib
</span></a></p>
56 <p class=
"p4"><br></p>
57 <p class=
"p4"><br></p>
58 <p class=
"p6"><b>First Example
</b></p>
59 <p class=
"p4"><br></p>
60 <p class=
"p7"><span class=
"Apple-tab-span"> </span>s.boot;
</p>
61 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
62 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\note
</span>,
<span class=
"s5">Pbrown
</span>(
0,
6,
0.1,
<span class=
"s5">inf
</span>)));
</p>
63 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).quant =
0;
<span class=
"s9">// no waiting.
</span></p>
64 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pbindf
</span>(
<span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>),
<span class=
"s8">\dur
</span>,
0.03).play;
</p>
65 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pbindf
</span>(
<span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>),
<span class=
"s8">\dur
</span>,
0.1,
<span class=
"s8">\ctranspose
</span>,
15).play;
</p>
66 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pbindf
</span>(
<span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>),
<span class=
"s8">\dur
</span>,
0.3,
<span class=
"s8">\ctranspose
</span>,
2).play;
</p>
67 <p class=
"p8"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>// now change the definition
</p>
68 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\note
</span>,
<span class=
"s5">Pseq
</span>([
0,
3,
5,
7,
9,
11],
<span class=
"s5">inf
</span>)));
</p>
69 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\freq
</span>,
<span class=
"s5">Pseq
</span>([
1000,
1923,
245.2,
1718] /
1.2 +
0.1,
<span class=
"s5">inf
</span>)));
</p>
70 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
71 <p class=
"p4"><br></p>
72 <p class=
"p4"><br></p>
73 <p class=
"p9"><b>Creation / Class Methods
</b></p>
74 <p class=
"p10"><br></p>
75 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>*new(key, pattern)
</b></p>
76 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Store the pattern in a global dictionary under key, replacing its pattern with the new one.
</p>
77 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>If the pattern is a
<b>function
</b>, Pdef creates a
<a href=
"../../../Streams-Patterns-Events/Patterns/PlazyEnvir.html"><span class=
"s5">PlazyEnvir
</span></a> internall that dynamically creates the pattern returned from the function, applying the arguments from the inevent.
</p>
78 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
79 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>*new(key)
</b></p>
80 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Access the pattern at that key (if none is given, a default silent event is created)
</p>
81 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
82 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>*default
</b></p>
83 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Default source, if none is given. The default is an Event.silent of
1.0 beat duration.
</p>
84 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
85 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>*removeAll
</b></p>
86 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Remove all proxies from the global dictionary (*
<b>all
</b>)
</p>
87 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
88 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>*clear
</b></p>
89 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Clear all proxies, setting their source to silence.
</p>
90 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
91 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>*all
</b></p>
92 <p class=
"p5"><b><span class=
"Apple-tab-span"> </span>*all_(envir)
</b></p>
93 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set or return the environment (
<a href=
"../../../Collections/IdentityDictionary.html"><span class=
"s5">IdentityDictionary
</span></a>) that stores all Pdefs.
</p>
94 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
95 <p class=
"p10"><br></p>
96 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
97 <p class=
"p6"><b>Changing the definition / setting the source
</b></p>
98 <p class=
"p1">One pattern may have many streams in different places. A change in the pattern definition Pdef propagates through all streams. The change does not have to be immediate - there is a scheme to schedule when the change becomes effective: a
<b>quant
</b> and
<b>clock
</b> (like elsewhere) and a
<b>condition
</b>.
</p>
99 <p class=
"p10"><br></p>
100 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
101 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>quant_(beats)
</b></p>
102 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set the quantisation time for beat accurate scheduling.
<span class=
"Apple-converted-space"> </span></p>
103 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>quant can be an array
<b>[quant, phase, timingOffset, outset]
</b>, or just
<b>[quant, phase]
</b>etc.
</p>
104 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
105 <p class=
"p5"><span class=
"Apple-tab-span"> </span>*
<b>defaultQuant_(beats)
</b></p>
106 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set the default quantisation for new instances (default:
1.0)
</p>
107 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>This can be an array
<span class=
"Apple-converted-space"> </span>[quant, phase, timingOffset, outset]
</p>
108 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
109 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>condition_(func)
</b></p>
110 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Provide a condition under which the pattern is switched when a new one is inserted.
</p>
111 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>The stream value and a count value is passed into the function.
</p>
112 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
113 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>count(n)
</b></p>
114 <p class=
"p5"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Create and update condition that simply counts up to n and switches the pattern then
</p>
115 <p class=
"p10"><br></p>
116 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>reset
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
117 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Switch the pattern immediately (stuck conditions can be subverted by this).
</p>
118 <p class=
"p10"><br></p>
119 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>fadeTime_(beats)
</b></p>
120 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>When the synthdefs that are used contain an \amp control, the patterns are replaced by crossfading the previous with the new over this time (in beats)
</p>
121 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
122 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>envir_(event)
</b></p>
123 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set the event for the Pdef. It is used to filter the incoming stream before it is
<span class=
"Apple-converted-space"> </span>passed to the source pattern.
<span class=
"Apple-converted-space"> </span>This is similar to
<a href=
"../nodeproxy/NodeProxy.html"><span class=
"s5">NodeProxy
</span></a>-nodeMap. When set for the first time, the pattern is rebuilt.
</p>
124 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
125 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>set(key, val, key2, val2, ...)
</b></p>
126 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set arguments in the default event. If there is none, it is created and the pattern is rebuilt.
</p>
127 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
128 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>map(key, pdefKey, key, pdefKey ...)
</b></p>
129 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Map Pdefn to the keys in the event.
</p>
130 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
131 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>clear
</b></p>
132 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set the source to nil
</p>
133 <p class=
"p10"><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>
134 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>endless
</b></p>
135 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Returns a Prout that plays the proxy endlessly, replacing
<b>nil
</b> with a
<b>default
</b> value (silent event). This allows to create streams that idle on until a new pattern is inserted.
</p>
136 <p class=
"p10"><br></p>
137 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
138 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
139 <p class=
"p10"><br></p>
140 <p class=
"p9"><b>Pdef as stream reference
</b></p>
141 <p class=
"p1">A single Pdef may serve as a definition for multiple streams. These methods show how to fork off separate streams from one instance. Even if they run in different contexts, their definition may still be changed.
<span class=
"Apple-tab-span"> </span></p>
142 <p class=
"p4"><span class=
"Apple-tab-span"> </span></p>
143 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>fork(clock, quant, event)
</b></p>
144 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Play an independent stream in parallel.
</p>
145 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>quant
</b>can be an array of [quant, phase, offset], or a
<a href=
"../../../Scheduling/Quant.html"><span class=
"s5">Quant
</span></a> value.
</p>
146 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
147 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>embed(val)
</b><span class=
"Apple-tab-span"> </span></p>
148 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Pass a value (typically an
<b>event
</b>) into the pattern inval, and embed the Pdef in the stream.
</p>
149 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
150 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>embedInStream(inval)
</b></p>
151 <p class=
"p5"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>just like any pattern, embeds itself in stream
</p>
152 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
153 <p class=
"p10"><br></p>
154 <p class=
"p10"><br></p>
155 <p class=
"p9"><b>Pdef as EventStreamPlayer
</b></p>
156 <p class=
"p1">For live coding, each Pdef also may control one instance that plays one stream off it. This is an EventStreamPlayer, accessible in the instance variable
<b>player
</b>.
</p>
157 <p class=
"p10"><br></p>
158 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>play(clock, protoEvent, quant)
</b></p>
159 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Starts the Pdef and creates a player.
<span class=
"Apple-converted-space"> </span></p>
160 <p class=
"p5"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>quant
</b>can be an array of [quant, phase, offset] or a
<a href=
"../../../Scheduling/Quant.html"><span class=
"s5">Quant
</span></a> value.
</p>
161 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
162 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>stop
</b></p>
163 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Stops the player
</p>
164 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
165 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>player
</b><span class=
"Apple-tab-span"> </span></p>
166 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Return the current player (if the Pdef is simply used in other streams this is nil)
</p>
167 <p class=
"p10"><br></p>
168 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>pause / resume / reset / mute / unmute
</b></p>
169 <p class=
"p5"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Perform this method on the player.
</p>
170 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
171 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>isPlaying
</b><span class=
"Apple-converted-space"> </span></p>
172 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Returns true if player is running. If a Pdef is playing and its stream ends, it will schedule a stream for playing
<b> as soon as a new one is assigned to it
</b>. If it is stopped by
<b>stop
</b>, it won't.
</p>
173 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
174 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
175 <p class=
"p10"><span class=
"Apple-tab-span"> </span></p>
176 <p class=
"p11"><br></p>
177 <p class=
"p10"><br></p>
178 <p class=
"p9"><b>Example: Pdef as stream reference
</b></p>
179 <p class=
"p10"><br></p>
180 <p class=
"p11"><br></p>
181 <p class=
"p11"><br></p>
183 <p class=
"p7"><span class=
"s5">SynthDef
</span>(
<span class=
"s10">"Pdefhelp"</span>, {
<span class=
"s5">arg
</span> out, freq, sustain=
1, amp=
1, pan;
</p>
184 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">var
</span> env, u=
1;
</p>
185 <p class=
"p7"><span class=
"Apple-tab-span"> </span>env =
<span class=
"s5">EnvGen
</span>.kr(
<span class=
"s5">Env
</span>.perc(
0.03, sustain),
1, doneAction:
2);
</p>
186 <p class=
"p7"><span class=
"Apple-tab-span"> </span>3.do {
<span class=
"s5">var
</span> d; d = exprand(
0.01,
1); u =
<span class=
"s5">SinOsc
</span>.ar(d *
300, u, rrand(
0.1,
1.2) * d,
1) };
</p>
187 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s5">Out
</span>.ar(out,
<span class=
"s5">Pan2
</span>.ar(
<span class=
"s5">SinOsc
</span>.ar(u +
1 * freq,
0, amp * env), pan));
</p>
188 <p class=
"p2"><br></p>
189 <p class=
"p7">}).store;
</p>
191 <p class=
"p7">s.boot;
</p>
192 <p class=
"p2"><br></p>
193 <p class=
"p12"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\metronom
<span class=
"s3">,
</span><span class=
"s5">Pbind
</span><span class=
"s3">(
</span>\instrument
<span class=
"s3">,
</span>\Pdefhelp
<span class=
"s3">,
</span>\dur
<span class=
"s3">,
1,
</span>\degree
<span class=
"s3">,
16,
</span>\legato
<span class=
"s3">,
0.1)).play;
</span></p>
194 <p class=
"p2"><br></p>
195 <p class=
"p7">x =
<span class=
"s5">Pseq
</span>([
<span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>),
<span class=
"s5">Pdef
</span>(
<span class=
"s8">\b
</span>),
<span class=
"s5">Pdef
</span>(
<span class=
"s8">\c
</span>)],
<span class=
"s5">inf
</span>).play;
</p>
196 <p class=
"p2"><br></p>
197 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
5,
4,
3])));
</p>
198 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\b
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.125,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
7,
8,
7,
8])));
</p>
199 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\c
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
1,
2],
2)));
</p>
200 <p class=
"p2"><br></p>
201 <p class=
"p2"><br></p>
202 <p class=
"p2"><br></p>
203 <p class=
"p2"><br></p>
204 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\c
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
4,
3,
1,
2]*
3)));
</p>
205 <p class=
"p2"><br></p>
206 <p class=
"p2"><br></p>
207 <p class=
"p8">// infinite loops are scheduled (to ths clock's next beat by default) and released:
</p>
208 <p class=
"p2"><br></p>
209 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.753,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
5,
4,
3,
2],
<span class=
"s5">inf
</span>)));
</p>
210 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.125,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
5,
4,
3] +
1,
1)));
</p>
211 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
5,
4,
3] -
4,
1)));
</p>
212 <p class=
"p2"><br></p>
213 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.125,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
5] -
1,
1)));
</p>
214 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.753,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pshuf
</span>(#[
0,
5,
4,
3,
2],
<span class=
"s5">inf
</span>)));
</p>
215 <p class=
"p2"><br></p>
216 <p class=
"p7">x.stop;
</p>
217 <p class=
"p12"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\metronom
<span class=
"s3">).stop;
</span></p>
218 <p class=
"p2"><br></p>
219 <p class=
"p8">// Pdef can be used in multiple patterns:
</p>
220 <p class=
"p2"><br></p>
222 <p class=
"p7">x =
<span class=
"s5">Ppar
</span>([
</p>
223 <p class=
"p13"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span>Pn
<span class=
"s3">(
</span>Pdef
<span class=
"s3">(
</span><span class=
"s8">\a
</span><span class=
"s3">),
</span>inf
<span class=
"s3">),
</span></p>
224 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\gtranspose
</span>,
<span class=
"s5">Pstutter
</span>(
8,
<span class=
"s5">Pseq
</span>(#[
0,
2,
0,
3],
<span class=
"s5">inf
</span>))
</p>
225 <p class=
"p7"><span class=
"Apple-tab-span"> </span>),
</p>
226 <p class=
"p13"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span>Pn
<span class=
"s3">(
</span>Pdef
<span class=
"s3">(
</span><span class=
"s8">\a
</span><span class=
"s3">),
</span>inf
<span class=
"s3">),
</span></p>
227 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\gtranspose
</span>,
<span class=
"s5">Pstutter
</span>(
8,
<span class=
"s5">Pseq
</span>(#[
7,
4,
0,
3],
<span class=
"s5">inf
</span>)),
<span class=
"Apple-converted-space"> </span></p>
228 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\dur
</span>,
0.6</p>
229 <p class=
"p7"><span class=
"Apple-tab-span"> </span>),
</p>
230 <p class=
"p13"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span>Pn
<span class=
"s3">(
</span>Pdef
<span class=
"s3">(
</span><span class=
"s8">\a
</span><span class=
"s3">),
</span>inf
<span class=
"s3">),
</span></p>
231 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
5,
4,
3,
2,
3,
2],
1)
</p>
232 <p class=
"p7"><span class=
"Apple-tab-span"> </span>)
</p>
233 <p class=
"p7">]).play;
</p>
235 <p class=
"p2"><br></p>
236 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.1,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
1,
0,
1,
2],
<span class=
"s5">inf
</span>)));
</p>
237 <p class=
"p2"><br></p>
238 <p class=
"p12"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\a
<span class=
"s3">,
</span><span class=
"s5">Pbind
</span><span class=
"s3">(
</span>\instrument
<span class=
"s3">,
</span>\Pdefhelp
<span class=
"s3">,
</span>\dur
<span class=
"s3">,
0.2,
</span>\degree
<span class=
"s3">,
</span><span class=
"s5">Pseq
</span><span class=
"s3">([
0,
4],
</span><span class=
"s5">inf
</span><span class=
"s3">)));
</span></p>
239 <p class=
"p2"><br></p>
240 <p class=
"p12"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\a
<span class=
"s3">,
</span><span class=
"s5">Pbind
</span><span class=
"s3">(
</span>\instrument
<span class=
"s3">,
</span>\Pdefhelp
<span class=
"s3">,
</span>\dur
<span class=
"s3">,
1,
</span>\degree
<span class=
"s3">,
</span><span class=
"s5">Pseq
</span><span class=
"s3">([
0,
4],
</span><span class=
"s5">inf
</span><span class=
"s3">)));
</span></p>
241 <p class=
"p2"><br></p>
242 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.2,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
0,
4,
<span class=
"s5">Prand
</span>([
6,
8b],
2)],
<span class=
"s5">inf
</span>)));
</p>
243 <p class=
"p2"><br></p>
244 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.1,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>(#[
0,
1b,
1,
2b,
2,
3,
4b,
4,
5],
<span class=
"s5">inf
</span>)));
</p>
245 <p class=
"p2"><br></p>
246 <p class=
"p8">// using a fade time, the above changes are crossfaded
</p>
247 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>).fadeTime =
2;
</p>
248 <p class=
"p2"><br></p>
249 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\Pdefhelp
</span>,
<span class=
"s8">\dur
</span>,
0.2,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
0,
4,
<span class=
"s5">Prand
</span>([
6,
8b],
2)],
<span class=
"s5">inf
</span>)));
</p>
250 <p class=
"p2"><br></p>
251 <p class=
"p8">// ...
</p>
252 <p class=
"p2"><br></p>
253 <p class=
"p8"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span><span class=
"s8">\a
</span><span class=
"s3">).set(
</span><span class=
"s8">\detune
</span><span class=
"s3">, -
50);
</span>// set environment
</p>
254 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\a
</span>).set(
<span class=
"s8">\detune
</span>,
0);
</p>
255 <p class=
"p2"><br></p>
256 <p class=
"p7">x.stop;
</p>
257 <p class=
"p2"><br></p>
258 <p class=
"p14"><br></p>
259 <p class=
"p9"><b>Example: Pdef as EventStreamPlayer
</b></p>
260 <p class=
"p15"><br></p>
261 <p class=
"p2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
263 <p class=
"p8">// load a synthdef
</p>
264 <p class=
"p7">s.boot;
</p>
265 <p class=
"p13">SynthDef
<span class=
"s3">(
</span><span class=
"s10">"gpdef"</span><span class=
"s3">,
<span class=
"Apple-converted-space"> </span></span></p>
266 <p class=
"p7"><span class=
"Apple-tab-span"> </span>{
<span class=
"s5">arg
</span> out=
0, freq=
440, sustain=
0.05, amp=
0.1, pan;
</p>
267 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">var
</span> env;
</p>
268 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>env =
<span class=
"s5">EnvGen
</span>.kr(
<span class=
"s5">Env
</span>.perc(
0.01, sustain), doneAction:
2) * amp;
</p>
269 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">Out
</span>.ar(out,
<span class=
"s5">Pan2
</span>.ar(
<span class=
"s5">SinOsc
</span>.ar(freq,
0, env), pan))
</p>
270 <p class=
"p7"><span class=
"Apple-tab-span"> </span>}).store;
</p>
272 <p class=
"p2"><br></p>
273 <p class=
"p2"><br></p>
274 <p class=
"p8"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span><span class=
"s8">\x
</span><span class=
"s3">);
</span>// creates a Pdef with a default pattern.
</p>
275 <p class=
"p2"><br></p>
276 <p class=
"p2"><br></p>
277 <p class=
"p8"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span><span class=
"s8">\x
</span><span class=
"s3">).play;
</span>// play it. A silent resting pattern is used.
</p>
278 <p class=
"p8"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span><span class=
"s8">\y
</span><span class=
"s3">).play;
</span>// play a second one (automatically instantiated)
</p>
279 <p class=
"p2"><br></p>
280 <p class=
"p2"><br></p>
281 <p class=
"p8">// assign various patterns to it:
</p>
282 <p class=
"p2"><br></p>
283 <p class=
"p12"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\x
<span class=
"s3">,
</span><span class=
"s5">Pbind
</span><span class=
"s3">(
</span>\dur
<span class=
"s3">,
0.25,
</span>\instrument
<span class=
"s3">,
</span>\gpdef
<span class=
"s3">));
<span class=
"Apple-converted-space"> </span></span></p>
284 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5b,
6],
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
285 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5b,
6]+
1,
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
286 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5b,
6]-
1,
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
287 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5b]-
2,
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
288 <p class=
"p2"><br></p>
289 <p class=
"p8">// using fadeTime:
</p>
290 <p class=
"p2"><br></p>
291 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>).fadeTime =
8.0;
</p>
292 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.125,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5b,
6]+
4.rand,
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
293 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5b,
6]-
2,
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
294 <p class=
"p2"><br></p>
296 <p class=
"p13">Pdef
<span class=
"s3">(
</span><span class=
"s8">\x
</span><span class=
"s3">,
</span>Pbind
<span class=
"s3">(
</span></p>
297 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\dur
</span>,
1 /
6,
<span class=
"Apple-converted-space"> </span></p>
298 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
<span class=
"s5">Prand
</span>([
8,
2,
3,
9,
10],
1) -
5,
6]+
1,
<span class=
"s5">inf
</span>),
<span class=
"Apple-converted-space"> </span></p>
299 <p class=
"p12"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s3">,
</span>\gpdef
</p>
300 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>)
</p>
301 <p class=
"p7"><span class=
"Apple-tab-span"> </span>);
</p>
304 <p class=
"p13">Pdef
<span class=
"s3">(
</span><span class=
"s8">\x
</span><span class=
"s3">,
</span>Pbind
<span class=
"s3">(
</span></p>
305 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\dur
</span>,
0.25,
<span class=
"Apple-converted-space"> </span></p>
306 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
<span class=
"s5">Prand
</span>([
8,
2,
3,
9,
10],
1),
6],
<span class=
"s5">inf
</span>),
<span class=
"Apple-converted-space"> </span></p>
307 <p class=
"p12"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s3">,
</span>\gpdef
<span class=
"s3">)
</span></p>
308 <p class=
"p7"><span class=
"Apple-tab-span"> </span>);
</p>
310 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).stop;
</p>
311 <p class=
"p2"><br></p>
312 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).play;
</p>
313 <p class=
"p2"><br></p>
314 <p class=
"p8">// tempo change
</p>
315 <p class=
"p7"><span class=
"s5">TempoClock
</span>.default.tempo =
1.3;
</p>
316 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
4,
5,
6]+
1,
<span class=
"s5">inf
</span>),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
317 <p class=
"p2"><br></p>
318 <p class=
"p8">// drop in ending patterns
</p>
319 <p class=
"p2"><br></p>
320 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3, [
7,
4],
5,
6]-
2),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
321 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.125,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3, [
7,
4],
5,
4]-
3),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
322 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.35,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3, [
7,
4],
5,
4,
3]-
3),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
323 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pshuf
</span>([
3, [
7,
4],
5,
6]-
2),
<span class=
"s8">\instrument
</span>,
<span class=
"s8">\gpdef
</span>));
</p>
324 <p class=
"p2"><br></p>
325 <p class=
"p2"><br></p>
326 <p class=
"p8">// clear all.
</p>
327 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).clear;
<span class=
"Apple-converted-space"> </span></p>
328 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>).clear;
<span class=
"Apple-converted-space"> </span></p>
329 <p class=
"p7"><span class=
"s5">TempoClock
</span>.default.tempo =
1.0;
</p>
330 <p class=
"p2"><br></p>
331 <p class=
"p2"><br></p>
332 <p class=
"p8">// GUI example: see also
<span class=
"Apple-converted-space"> </span></p>
333 <p class=
"p16"><span class=
"s4"><a href=
"../extras/PdefAllGui.html">PdefAllGui
</a></span><span class=
"s3">(
18);
</span></p>
334 <p class=
"p2"><br></p>
335 <p class=
"p2"><br></p>
336 <p class=
"p2"><br></p>
337 <p class=
"p9"><b>Example: Recursion
</b></p>
338 <p class=
"p4"><br></p>
339 <p class=
"p1">Pdefs can be used recursively under the condition that the stream call structure allows it.
</p>
340 <p class=
"p1">a structure like the following works:
</p>
341 <p class=
"p4"><br></p>
342 <p class=
"p2"><br></p>
343 <p class=
"p12"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\x
<span class=
"s3">,
</span><span class=
"s5">Pseq
</span><span class=
"s3">([
</span><span class=
"s5">Pbind
</span><span class=
"s3">(
</span>\instrument
<span class=
"s3">,
</span>\gpdef
<span class=
"s3">),
</span><span class=
"s5">Pdef
</span><span class=
"s3">(
</span>\x
<span class=
"s3">)],
</span><span class=
"s5">inf
</span><span class=
"s3">));
<span class=
"Apple-converted-space"> </span></span></p>
344 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).play;
</p>
345 <p class=
"p4"><br></p>
346 <p class=
"p1">but the following would crash, because .embedInStream is called recursively with no limit:
</p>
347 <p class=
"p4"><br></p>
348 <p class=
"p8">// Pdef(\y, Pseq([Pdef(\y), Pbind(\instrument, \gpdef)], inf));
</p>
349 <p class=
"p4"><br></p>
350 <p class=
"p4"><br></p>
351 <p class=
"p9"><b>Example: Quantizing and outset
</b></p>
352 <p class=
"p4"><br></p>
353 <p class=
"p1">When quantizing to a larger number of beats, the changes become very slow if one has to wait for the next beat. Providing an
<b>outset
</b> quant value is a way to make the change so that it appears as if it had been done at the previous grid point already. The stream is fast forwarded to the current position relative to the quant grid.
</p>
354 <p class=
"p1">Providing a number larger than zero, the next possible quant point is used as outset.
</p>
355 <p class=
"p4"><br></p>
356 <p class=
"p1">For example, if quant is
32, and one has just missed the first beat when changing the pattern,
</p>
357 <p class=
"p1">one has to wait for
32 beats until the change happens. Using an outset of
1, it is assumed that you had already
</p>
358 <p class=
"p1">changed the pattern at the first beat, the stream is fast forwarded to the time it would be at now if you had done so. The new pattern is inserted at the next beat (outset=
1).
</p>
359 <p class=
"p4"><br></p>
360 <p class=
"p1"><b>quant can be: [quant, phase, timingOffset, outset]
</b></p>
361 <p class=
"p4"><br></p>
362 <p class=
"p1"><b>Note:
</b> This fast forwarding might create a cpu peak if the pattern is very complex/fast or
</p>
363 <p class=
"p1">quant is very long. This is hard to avoid, so it simply has to be taken into account.
</p>
364 <p class=
"p4"><br></p>
365 <p class=
"p2"><br></p>
366 <p class=
"p8">// examples
</p>
368 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).quant_([
8,
0,
0,
1]);
</p>
369 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>).quant_([
8,
0.5,
0,
1]);
<span class=
"s9">// phase: half a beat
</span></p>
370 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).play;
</p>
371 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>).play;
</p>
373 <p class=
"p2"><br></p>
374 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7)+
2,
<span class=
"s5">inf
</span>)));
</p>
375 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7)-
2,
<span class=
"s5">inf
</span>)));
</p>
376 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7)+
2,
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
0.5));
</p>
377 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7).scramble-
2,
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\legato
</span>,
0.3));
</p>
378 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>)));
</p>
379 <p class=
"p2"><br></p>
380 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
1,
5,
6,
7,
0,
3,
2,
4 ],
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
1));
</p>
381 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
0,
2,
2,
4,
0,
4,
0,
4 ],
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
1));
</p>
382 <p class=
"p2"><br></p>
383 <p class=
"p8"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span><span class=
"s8">\x
</span><span class=
"s3">).quant_([
8,
1/
3,
0,
1]);
</span>// phase:
1/
6 beat relative to y
</p>
384 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
1,
1,
1,
7,
0,
2,
2,
4 ],
<span class=
"s5">inf
</span>),
<span class=
"s8">\legato
</span>,
0.1));
</p>
385 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>([
3,
3,
3,
4b ],
<span class=
"s5">inf
</span>),
<span class=
"s8">\legato
</span>,
0.1));
</p>
386 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\y
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7).scramble-
4,
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
0.25,
<span class=
"s8">\legato
</span>,
0.3));
</p>
387 <p class=
"p2"><br></p>
388 <p class=
"p4"><br></p>
389 <p class=
"p2"><br></p>
390 <p class=
"p2"><br></p>
391 <p class=
"p8">// some testing
</p>
393 <p class=
"p8"><span class=
"s5">var
</span><span class=
"s3"> quant = #[
8,
0,
0,
1];
</span>// quantise to
8 beats, no phase, insert quant to
1 beat
</p>
394 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).quant_(quant);
</p>
395 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).play;
</p>
396 <p class=
"p7"><span class=
"s5">Routine
</span> { loop {
8.do {
<span class=
"s5">|i|
</span> (
<span class=
"s10">"uhr:"</span>+i).postln;
1.wait } } }.play(quant:quant);
</p>
397 <p class=
"p7"><span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>)).play(quant:quant);
</p>
399 <p class=
"p2"><br></p>
400 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7)+
2,
<span class=
"s5">inf
</span>)).trace(
<span class=
"s8">\degree
</span>));
</p>
401 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>) + [
0,
3]).trace(
<span class=
"s8">\degree
</span>));
</p>
402 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>) + [
0,
6],
<span class=
"s8">\dur
</span>,
0.5).trace(
<span class=
"s8">\degree
</span>));
</p>
403 <p class=
"p2"><br></p>
404 <p class=
"p2"><br></p>
405 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).fadeTime =
8;
</p>
406 <p class=
"p2"><br></p>
407 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>)).trace(
<span class=
"s8">\degree
</span>));
</p>
408 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7).reverse,
<span class=
"s5">inf
</span>) + [
0,
6],
<span class=
"s8">\dur
</span>,
0.5));
</p>
409 <p class=
"p2"><br></p>
410 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).fadeTime =
<span class=
"s5">nil
</span>;
</p>
411 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).quant =
1;
</p>
412 <p class=
"p2"><br></p>
413 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>)).trace(
<span class=
"s8">\degree
</span>));
</p>
414 <p class=
"p2"><br></p>
415 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).quant =
8;
</p>
416 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7),
<span class=
"s5">inf
</span>)).trace(
<span class=
"s8">\degree
</span>));
</p>
417 <p class=
"p4"><br></p>
418 <p class=
"p4"><br></p>
419 <p class=
"p4"><br></p>
420 <p class=
"p9"><b>Example: Update condition
</b></p>
421 <p class=
"p4"><br></p>
422 <p class=
"p1">In order to be able to switch to a new pattern under a certain condition, the instance variable
</p>
423 <p class=
"p1"><b><i>condition
</i></b> can be set to a function that returns a boolean. Value and a count index are passed to the function.
</p>
424 <p class=
"p1">The condition is always valid for the
<b><i>next pattern
</i></b> inserted. For stuck conditions, the
<b>reset
</b> message can be used.
</p>
425 <p class=
"p4"><br></p>
426 <p class=
"p1">As counting up (such as
<i>"every nth event, a swap can happen"</i>) is a common task, there is a method for this,
</p>
427 <p class=
"p1">called
<b>count(n).
</b></p>
428 <p class=
"p4"><br></p>
429 <p class=
"p2"><br></p>
430 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).play;
</p>
431 <p class=
"p8"><span class=
"s5">Pdef
</span><span class=
"s3">(
</span><span class=
"s8">\x
</span><span class=
"s3">).quant =
0;
</span>// we don't want quant here.
</p>
432 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.5),
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
0.3)).condition_({
<span class=
"s5">|val, i|
</span> i.postln %
6 ==
0 });
</p>
433 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7) +
5.rand,
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
0.3)).condition_({
<span class=
"s5">|val, i|
</span> (i %
8).postln ==
0 });
</p>
434 <p class=
"p2"><br></p>
435 <p class=
"p8">// the above is equivalent to:
</p>
436 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>,
<span class=
"s5">Pbind
</span>(
<span class=
"s8">\degree
</span>,
<span class=
"s5">Pseq
</span>((
0.
.7) +
5.rand,
<span class=
"s5">inf
</span>),
<span class=
"s8">\dur
</span>,
0.3)).count(
8);
</p>
437 <p class=
"p2"><br></p>
438 <p class=
"p8">// the value that is sent in is the event, so decisions can be made dependent on the event's fields
</p>
439 <p class=
"p2"><br></p>
440 <p class=
"p2"><br></p>
441 <p class=
"p2"><br></p>
442 <p class=
"p1"><b>reset
</b></p>
443 <p class=
"p17"><span class=
"Apple-converted-space"> </span></p>
444 <p class=
"p8">// reset to change immediately:
</p>
445 <p class=
"p7"><span class=
"s5">Pdef
</span>(
<span class=
"s8">\x
</span>).reset;
</p>
446 <p class=
"p2"><br></p>
447 <p class=
"p2"><br></p>
448 <p class=
"p2"><br></p>
449 <p class=
"p2"><br></p>
450 <p class=
"p2"><br></p>
451 <p class=
"p4"><br></p>
452 <p class=
"p4"><br></p>