sclang: ServerShmInterface - try to avoid multiple destructor calls
[supercollider.git] / HelpSource / Classes / DemandEnvGen.schelp
blobf7b37ec8fdbd5e65471fe5dafc6a7a79a608ce08
1 class:: DemandEnvGen
2 summary:: Demand rate envelope generator
3 related:: Classes/Demand, Classes/Duty, Classes/TDuty
4 categories::  UGens>Demand, UGens>Envelopes
6 Description::
7 Plays back break point envelope contours (levels, times, shapes) given by demand ugens. The next values are called when the next node is reached.
9 classmethods::
10 private:: categories
12 method::ar, kr
14 argument::level
16 A demand UGen or any other UGen returning level values. If this ends, the
18 code::doneAction::  is evaluated.
21 argument::dur
23 A demand UGen or any other UGen returning time values. If this ends, the
25 code::doneAction::  is evaluated.
28 argument::shape
30 A demand UGen or any other UGen: the number given is the shape
31 number according to link::Classes/Env::.
34 argument::curve
36 A demand UGen or any other UGen returning curve values. if shape is 5, this is the
37 curve factor.
39 The possible values are:
40 table::
41 ## 0 || flat segments
42 ## 1 || linear segments, the default
43 ## 2 || natural exponential growth and decay. In this case, the levels must all be nonzero and the have the same sign.
44 ## 3 || sinusoidal S shaped segments.
45 ## 4 || sinusoidal segments shaped like the sides of a Welch window.
46 ## a Float || a curvature value for all segments.
47 ## An Array of Floats || curvature values for each segments.
50 argument::gate
52 If gate is x ≥ 1, the UGen runs.
55 If gate is 0 > x > 1, the UGen is released at the next
56 level (doneAction).
59 If gate is x < 0, the UGen is sampled and held.
62 argument::reset
64 If reset crosses from non-positive to positive, the UGen is reset
65 at the next level. If it is > 1, it is reset immediately.
68 argument::levelScale
70 demand ugen returning level scaling values
73 argument::levelBias
75 demand ugen returning level offset values
78 argument::timeScale
80 demand ugen returning time scaling values
83 argument::doneAction
85 A doneAction that is evaluated when level or duration stream
86 ends. See link::Reference/UGen-doneActions::  for more detail.
89 Examples::
91 code::
92 // frequency envelope with random times
94         {
95                 var freq;
96                 freq = DemandEnvGen.ar(
97                                 Dseq([204, 400, 201, 502, 300, 200], inf),
98                                 Drand([1.01, 0.2, 0.1, 2], inf) * MouseY.kr(0.01, 3, 1),
99                                 7 // cubic interpolation
100                         );
101                 SinOsc.ar(freq * [1, 1.01]) * 0.1
103         }.play;
106 // frequency modulation
108         {
109                 var freq, list;
110                 list = { exprand(200, 1000.0) } ! 32;
111                 freq = DemandEnvGen.ar(
112                                 { Dseq(list.scramble, inf) } ! 2,
113                                 SampleDur.ir * MouseY.kr(1, 3000, 1),
114                                 5, // curve interpoaltion
115                                 MouseX.kr(-0.01, -4) // curve must be negative for fast interpol.
116                         );
117                 SinOsc.ar(freq) * 0.1
119         }.play;
123 //  gate
124 // mouse x on right side of screen toggles gate
126         {
127                 var freq;
128                 freq = DemandEnvGen.kr(
129                                 Dwhite(300, 1000, inf).round(100),
130                                 0.1,
131                                 5, 0.3, // curve: 0.3
132                                 MouseX.kr > 0.5,
133                                 1
134                         );
135                 SinOsc.ar(freq * [1, 1.21]) * 0.1
137         }.play;
140 // sample and hold (0.5 > gate > 0)
141 // mouse x on right side of screen toggles gate
142 // mouse y scales frequency
144         {
145                 var freq;
146                 freq = DemandEnvGen.kr(
147                                 Dwhite(300, 1000, inf).round(100),
148                                 0.1,
149                                 5, 0.3,
150                                 MouseX.kr > 0.5 + 0.1
151                         );
152                 SinOsc.ar(freq * [1, 1.21]) * 0.1
154         }.play;
157 // gate
158 // mouse x on right side of screen toggles gate
159 // mouse button does soft reset
161         {
162                 var freq;
163                 freq = DemandEnvGen.kr(
164                                 Dseq([Dseries(400, 200, 5), 500, 800, 530, 4000, 900], 2),
165                                 Dseq([0.2, 0.1, 0.2, 0.3, 0.1], inf),
166                                 Dseq([1, 0, 0, 6, 1, 1, 0, 2], inf), // shapes
167                                 0,
168                                 MouseX.kr > 0.5, // gate
169                                 MouseButton.kr > 0.5, // reset
170                                 doneAction:0
171                         );
172                 SinOsc.ar(freq * [1, 1.001]) * 0.1
174         }.play;
178 //  gate
179 // mouse x on right side of screen toggles sample and hold
180 // mouse button does hard reset
182         {
183                 var freq;
184                 freq = DemandEnvGen.kr(
185                                 Dseq([Dseries(400, 200, 5), 500, 800, 530, 4000, 900], 2),
186                                 0.1,
187                                 3, 0,
188                                 MouseX.kr > 0.5 - 0.1, // gate: sample and hold
189                                 MouseButton.kr > 0.5 * 2, // hard reset
190                                 doneAction: 0
191                         );
192                 SinOsc.ar(freq * [1, 1.001]) * 0.1
194         }.play;
201 // short sequence with doneAction, linear
203         {
204                 var freq;
205                 freq = DemandEnvGen.kr(
206                                 Dseq([1300, 500, 800, 300, 400], 1),
207                                 0.2,
208                                 1,
209                                 doneAction:2
210                         );
211                 SinOsc.ar(freq * [1, 1.01]) * 0.1
213         }.play;
216 // short sequence with doneAction, step
218         {
219                 var freq;
220                 freq = DemandEnvGen.kr(
221                                 Dseq([1300, 500, 800, 300, 400], 1),
222                                 0.2,
223                                 0,
224                                 doneAction:2
225                         );
226                 SinOsc.ar(freq * [1, 1.01]) * 0.1
228         }.play;
233 // a linear ramp
235         {
236                 var freq;
237                 freq = DemandEnvGen.kr(
238                                 Dseq([300, 800], 1),
239                                 1,
240                                 1
241                         );
242                 SinOsc.ar(freq * [1, 1.01]) * 0.1
244         }.play;
249 // random gate:  release. gate low level > 0.
250 // only end points are kept as release levels
252         {
253                 var freq;
254                 freq = DemandEnvGen.kr(
255                                 Dseq([500, 800], inf),
256                                 0.03,
257                                 1,0, // linear
258                                 ToggleFF.kr(Dust.kr(5)) + 0.1 // gate
261                         );
262                 SinOsc.ar(freq * [1, 1.01]) * 0.1
264         }.play;
267 // random gate: sample and hold. gate low level = 0.
269         {
270                 var freq;
271                 freq = DemandEnvGen.kr(
272                                 Dseq([500, 800, 600], inf),
273                                 0.03,
274                                 1,0, // linear
275                                 ToggleFF.kr(Dust.kr(5)), // gate
276                                 0 // reset
278                         );
279                 SinOsc.ar(freq * [1, 1.01]) * 0.1
281         }.play;
287 // lfnoise1
289         {
290                         DemandEnvGen.ar(
291                                 Dwhite(-0.1, 0.1, inf),
292                                 SampleDur.ir * MouseY.kr(0.5, 20),
293                                 5,
294                                 -4
295                         );
298         }.play;
301 // lfbrownnoise
303         {
304                         DemandEnvGen.ar(
305                                 Dbrown(-0.1, 0.1, 0.1, inf),
306                                 SampleDur.ir * MouseY.kr(1, 100, 1)
307                         );
310         }.play;
318 Server.internal.boot;
320 // hardsyncing a saw
322         {
324                         DemandEnvGen.ar(
325                                 Dseq([Dseries(-0.1, 0.01, 20)], inf),
326                                 SampleDur.ir * MouseY.kr(1, 100, 1),
327                                 1, 0,
328                                 K2A.ar(1),
329                                 Impulse.ar(MouseX.kr(1, SampleRate.ir * MouseX.kr(0.002, 1, 1), 1), 0, 1.5)
331                         )
334         }.scope;
338 // softsyncing a saw
340         {
342                         DemandEnvGen.ar(
343                                 Dseq([Dseries(-0.1, 0.01, 20)], inf),
344                                 SampleDur.ir * MouseY.kr(1, 100, 1),
345                                 1, 0,
346                                 K2A.ar(1),
347                                 Impulse.ar(MouseX.kr(1, SampleRate.ir * MouseX.kr(0.002, 1, 1), 1)) + [0, 0.3]
349                         )
352         }.scope;
357 // hardsyncing a saw, som random elements
359         {
361                         DemandEnvGen.ar(
362                                 Dseq([Dseries(-0.1, 0.01, 20), Dseries(-0.1, 0.01, 20), Dwhite(-0.1, 0.1, 5)], inf),
363                                 SampleDur.ir * MouseY.kr(1, 100, 1),
364                                 3, 0,
365                                 1,
366                                 Impulse.ar(MouseX.kr(1, SampleRate.ir * MouseX.kr(0.002, 1, 1), 1), 0, 1.5)
368                         )
371         }.scope;
374 // softsyncing a saw, som random elements
376         {
378                         DemandEnvGen.ar(
379                                 Dseq([Dseries(-0.1, 0.01, 20), Dseries(-0.1, 0.01, 20), Dwhite(-0.1, 0.1, 5)], inf),
380                                 SampleDur.ir * MouseY.kr(1, 100, 1),
381                                 1, 0, // linear interpolation
382                                 1,
383                                 Impulse.ar(MouseX.kr(1, SampleRate.ir * MouseX.kr(0.002, 1, 1), 1))
385                         )
388         }.scope;
392 // multichannel expansion
393 // mouse x on right side of screen toggles gate
394 // mouse y controls speed
397         {
398                 var freq;
399                 freq = DemandEnvGen.kr(
400                                 { Dseq([300, 800, Drand([1000, 460, 300], 1), 400], inf) + 3.0.rand } ! 2,
401                                 MouseY.kr(0.001, 2, 1),
402                                 5, -4,
403                                 MouseX.kr > 0.5
404                         );
405                 SinOsc.ar(freq) * 0.1
407         }.play;