2 summary:: Abstract superclass of all unit generators
3 categories:: UGens, Server>Abstractions
4 related:: Browse#UGens, Guides/Tour_of_UGens, Guides/UGens-and-Synths
8 UGens represent calculations with signals. They are the basic building blocks of synth definitions on the server, and are used to generate or process both audio and control signals. The many subclasses of UGen are the client-side representations of unit generators, and are used to specify their parameters when constructing synth definitions (see link::Classes/SynthDef::).
10 subsection:: Interface
11 All UGens respond to one or more of the following class methods:
13 ## code:: ar(arg1, arg2, ... ) ::
14 ## code:: kr(arg1, arg2, ... ) ::
15 ## code:: ir(arg1, arg2, ... ) ::
18 They return a new instance of UGen that calculates at audio/control rate or at initialization only (ir). Some UGens, like link::Classes/Rand::, use the code::*new:: method instead. These methods are implemented in subclasses, where argument names and their meaning depend on the case.
20 If any argument is an array, they return an array of UGens ( see: link::Guides/Multichannel-Expansion:: ). If the combination of rates between arguments and ugen are not allowed, calling the methods will throw an error. This method adds the UGen to the current SynthDef, so it only fully works inside a UGen function.
22 { Blip.ar(Blip.kr(4, 5, 500, 60), 59, 0.1) }.play;
25 subsection:: Documentation of mul and add arguments
27 A great number of UGens take arguments for code::mul:: and code::add:: in their code::*ar:: and code::*kr:: methods. Because these arguments are so ubiquitous, they are not general documented in the individual help files.
28 Mul and add simply refer to a constant or signal by which to multiply the output of the UGen, and a constant or signal to add to the output of the UGen. (mul happens before add.) They thus correspond in many cases to scaling the amplitude of the UGen signal in the case of mul, and adding a constant or DC offset in the case of add.
29 In most cases the defaults for mul and add are 1 and 0 respectively, and they are commonly implemented using a automatically generated link::Classes/MulAdd:: UGen for efficiency. See also the code::range:: and code::madd:: methods below.
34 method:: buildSynthDef
35 Returns:: the SynthDef in which the UGen is situated.
38 { UGen.buildSynthDef.dump; Silent.ar }.play;
41 subsection:: Internally used class methods
44 These methods are responsible for multichannel expansion. They call code::*new1(rate, ...args):: for each parallel combination. Most code::*ar/*kr:: methods delegate to link::#*multiNewList::.
46 The first argument is rate, then the rest of the arguments. code::(rate, ...args)::
49 See link::#*multiNew::.
51 An array where the first argument is rate, then the rest of the arguments. code::([rate, ...args])::
54 This method returns a single instance of the UGen, not multichannel expanded. It is called inside multiNewList, whenever a new single instance is needed.
56 method:: methodSelectorForRate
58 A link::Classes/Symbol::, code:: \audio, \control, \scalar ::
60 An appropriate message selector ( link::Classes/Symbol:: like code:: \ar, \kr, \ir :: ) for the given rate.
62 method:: replaceZeroesWithSilence
64 A new link::Classes/Array::, where every zero is replaced by a link::Classes/Silent:: UGen.
66 This is required internally sometimes for UGens like link::Classes/Out::.
70 subsection:: Convenience Methods
74 Displays the output of this UGen in an individual link::Classes/Stethoscope:: window.
76 The name of the window
84 Server.default = s = Server.internal.boot; // scope works only for internal server
86 { Ringz.ar(PinkNoise.ar([0.1, 0.2]).scope(\pink), 2000, 1, 0.25) }.play; // multichannel works
87 s.scope; // can still separately scope the output of the server
89 Server.default = s = Server.local.boot; // switch back to local server.
94 Polls the output of this UGen every interval seconds, and posts the result.
99 A symbol to label the output
103 The default trig is 10, which converts to 10 triggers per second (or every 0.1 seconds). See link::Classes/Poll:: for more info on polling.
105 { SinOsc.ar(LFNoise0.ar(2).range(420, 460).poll(label: \LFNoise), 0, 0.2) }.play;
107 // multichannel polling:
110 var freqs = SinOsc.ar([0.2, 0.3]).range(420, 460);
111 freqs.poll(label: [\freq1, \freq2]);
112 SinOsc.ar(freqs, 0, 0.2);
120 Like code::poll::, only that code::dpoll:: is used for Demand ugens. See link::Classes/Poll:: for more info on polling.
124 Scales the output of this UGen to be within the range of code::lo:: and code::hi::.
126 Note that code::range:: expects the default output range, and thus should not be used in conjunction with mul and add arguments.
128 { SinOsc.ar(SinOsc.ar(0.3).range(440, 660), 0, 0.5) * 0.1 }.play;
133 Maps the output of this UGen exponentially to be within the range of code::lo:: and code::hi:: using a link::Classes/LinExp:: UGen.
135 code::lo:: and code::hi:: should both be non-zero and have the same sign. Note that code::exprange:: expects the default output range, and thus should not be used in conjunction with mul and add arguments.
137 { SinOsc.ar(SinOsc.ar(0.3).exprange(440, 6600), 0, 0.5) * 0.1 }.play;
142 Scales the output of this UGen to be between code::(0..mul):: range (default 1).
144 Note that code::unipolar:: expects the default output range, and thus should not be used in conjunction with mul and add arguments.
146 { SinOsc.ar(300, 0, 0.5) * SinOsc.kr(2).unipolar * 0.1 }.play;
151 Scales the output of this UGen to be between code::(-mul..mul):: range (default 1).
153 Note that code::bipolar:: expects the default output range, and thus should not be used in conjunction with mul and add arguments.
155 { SinOsc.ar(500 + LFPulse.ar(4).bipolar(40), 0, 0.5) * 0.1 }.play;
159 Wraps the receiver in a link::Classes/Clip:: UGen, clipping its output at code::lo:: and code::hi::.
162 Wraps the receiver in a link::Classes/Fold:: UGen, folding its output at code::lo:: and code::hi::.
165 Wraps the receiver in a link::Classes/Wrap:: UGen, wrapping its output at code::lo:: and code::hi::.
168 Wraps the receiver in a link::Classes/Lag:: UGen, smoothing its output by code::t1:: seconds lagtime. If a second argument is given, it wraps it in a link::Classes/LagUD:: UGen.
171 Wraps the receiver in a link::Classes/Lag2:: UGen, smoothing its output by code::t1:: seconds lagtime. If a second argument is given, it wraps it in a link::Classes/Lag2UD:: UGen.
174 Wraps the receiver in a link::Classes/Lag3:: UGen, smoothing its output by code::t1:: seconds lagtime. If a second argument is given, it wraps it in a link::Classes/Lag3UD:: UGen.
177 Wraps the receiver in a link::Classes/LagUD:: UGen, smoothing its output by code::lagtimeU:: and code::lagtimeD::.
180 Wraps the receiver in a link::Classes/Lag2UD:: UGen, smoothing its output by code::lagtimeU:: and code::lagtimeD::.
183 Wraps the receiver in a link::Classes/Lag3UD:: UGen, smoothing its output by code::lagtimeU:: and code::lagtimeD::.
186 Wraps the receiver in a link::Classes/VarLag:: UGen, smoothing its output by code::time:: seconds.
189 Wraps the receiver in a link::Classes/Slew:: UGen, limiting the slope of its output.
193 Wraps the receiver in a link::Classes/DegreeToKey:: UGen.
197 Wraps the receiver in a code::min:: link::Classes/BinaryOpUGen::, such that the lesser of the receiver's output and the Nyquist frequency is output. This can be useful to prevent aliasing.
200 Wraps the receiver so that a linear input range is mapped to a linear output range.
203 The clip argument can be one of the four:
205 ## code::nil:: || do not clip at outMin or outMax
206 ## code::\minmax:: || clip at outMin or outMax
207 ## code::\min:: || clip at outMin
208 ## code::\max:: || clip at outMax
212 { Line.ar(-1, 5, 0.1).linlin(0, 3, -1, 1) }.plot(0.1);
214 // modulate some values
216 { Line.ar(-1, 5, 0.1).lincurve(SinOsc.ar(100), SinOsc.ar(130) + 3, -1, 1, clip: nil) }
217 .plot(0.1, minval: -15, maxval: 5)
223 Wraps the receiver so that a linear inputrange is mapped to an exponential output range.
225 outMin and outMax must be nonzero and of the same sign. For clip argument, see code::linlin:: above.
227 { Line.ar(-1, 5, 0.1).linexp(0, 3, 0.01, 1) }.plot(0.1);
232 Wraps the receiver so that an exponential inputrange is mapped to a linear output range.
234 inMin and inMax must be nonzero and of the same sign. For clip argument, see code::linlin:: above.
236 { Line.ar(1, 5, 0.1).explin(1, 3, -1, 1) }.plot(0.1);
241 Wraps the receiver so that an exponential inputrange is mapped to an exponential output range.
243 outMin, outMax, inMin and inMax must be nonzero and of the same sign. For clip argument, see code::linlin:: above.
245 { Line.ar(1, 5, 0.1).expexp(1, 3, 0.01, 1) }.plot(0.1);
250 Wraps the receiver so that a linear inputrange is mapped to a curve-like exponential output range.
252 outMin and outMax may be zero and of the different sign. For clip argument, see code::linlin:: above.
254 { Line.ar(-1, 5, 0.1).lincurve(0, 3, -1, 1, curve: -4) }.plot(0.1);
256 // modulate the curve. Unlike with numbers and CurveSpec, the curve absolute value
257 // should not be much smaller than 0.5.
258 { SinOsc.ar(100).lincurve(-1, 1, -1, 1, XLine.kr(-3, -100, 0.1)) * 0.1 }.plot(0.1);
262 Wraps the receiver so that a curve-like exponential inputrange is mapped to a linear output range.
264 inMin and inMax may be zero and of the different sign. For clip argument, see code::linlin:: above.
266 { Line.ar(-1, 5, 0.1).curvelin(0, 3, -1, 1, curve: -4) }.plot(0.1);
270 Limits the receiver range to one of the four clip modes, see code::linlin:: above.
272 method:: checkBadValues
273 Wraps the receiver in a link::Classes/CheckBadValues:: UGen with the corresponding code::id:: and code::post:: flag.
276 Outputs trueUGen when the receiver outputs 1, falseUGen when the receiver outputs 0. If the receiver outputs a value between 0 and 1, a mixture of both will be played.
278 This is implemented as: code::(this * (trueUGen - falseUGen)) + falseUGen)::
280 Note that both trueUGen and falseUGen will be calculated regardless of whether they are output, so this may not be the most efficient approach.
282 // note different syntax in these two examples
283 { if( LFNoise1.kr(1.0, 0.5, 0.5) , SinOsc.ar, Saw.ar ) * 0.1 }.play;
285 { Trig1.ar(Dust.ar(3), 0.2).lag(0.1).if(FSinOsc.ar(440), FSinOsc.ar(880)) * 0.1 }.play;
289 Dynamic geometry support. Returns code::Point(this, y)::.
292 { (SinOsc.ar(1001) @ SinOsc.ar(1207)).rho }.scope;
296 Complex math support. Returns code::Complex(this, 0.0)::.
299 Posts a list of the arguments for this UGen and their values.
302 subsection:: Other Instance Methods
304 The following methods and instance variables are largely used in the construction of synth definitions, synth descriptions (see link::Classes/SynthDesc::), UGen class definitions, etc., and are usually not needed for general use.
305 Users should not attempt to set any of these values in general code.
308 The SynthDef which contains the UGen.
311 The array of inputs to the UGen.
314 The output rate of the UGen which is one of the link::Classes/Symbol::s code::\audio::, or code::\control::.
317 Returns:: A symbol indicating the signal range of the receiver. Either code::\bipolar:: or code::\unipolar::.
320 Returns:: The number of output channels.
322 For a UGen, this will always be 1, but link::Classes/Array:: also implements this method, so multichannel expansion is supported. See link::Guides/Multichannel-Expansion::.
325 Returns:: The number of inputs for this UGen.
328 Returns:: The number of outputs for this UGen.
331 Returns:: The Class name of the receiver as a link::Classes/String::.
334 Wraps the receiver in a link::Classes/MulAdd:: UGen.
336 This is for the most part only used in UGen class definitions in order to allow efficient implementation of code::mul:: and code::add:: arguments.
338 method:: isValidUGenInput
342 Returns:: the receiver
344 This method is implemented in a number of classes in order to allow objects like link::Classes/Node::s, link::Classes/Bus::ses, and link::Classes/Buffer::s to be passed directly as UGen inputs and link::Classes/Synth:: args.
347 Returns:: the receiver.
349 Thus UGen-dup effectively returns a reference to the original and is a convenient way to copy a mono signal to multiple channels.
351 { SinOsc.ar(Rand(200, 4000), 0, 0.2).dup }.plot // this is the same UGen
353 Function-dup evaluates that function multiple times, thus potentially returning distinct UGens.
355 { { SinOsc.ar(Rand(200, 4000), 0, 0.2) }.dup }.plot // these are different UGens
359 subsection:: Internally used instance methods
361 method:: methodSelectorForRate
362 See link::#*methodSelectorForRate::
365 By default, this method stores the inputs (e.g. the arguments to code::*ar:: and code::*kr::) in the UGen.
367 This may be overridden to do other initialisations, as long as the inputs are set correctly.