public abstract class UGen
extends java.lang.Object
osc.patch( filter ).patch( adsr ).patch( output );You can read this code left to right. It says that the output of an Oscil should be sent through a filter (perhaps a LowPass) and the output of the filter should be sent through an ADSR envelope, which should then be sent to an AudioOutput. It's incredibly clear what you signal path is and you can state it concisely.
UGens might also have UGenInputs. Oscil, for example, has a UGenInput called
frequency
. UGenInputs can be patched to, just like UGens, which
means you might have a line of code like this:
line.patch( osc.frequency )
This says that a Line UGen should control the value of the Oscil's frequency.
You may have created a Line that changes it's value from 440 to 880 over 2
seconds. The audible result, when you activate() the Line, is that the Oscil
will sweep upwards in frequency and then hold there until you activate the
Line again. All of this control happens on a sample-by-sample basis, which
means (hopefully) no clicks and pops.
Modifier and Type | Class and Description |
---|---|
static class |
UGen.InputType
This enum is used to specify the InputType of the UGenInput
|
class |
UGen.UGenInput
This inner class, UGenInput, is used to connect the output of other UGens
to this UGen
|
Constructor and Description |
---|
UGen()
Constructor for a UGen.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addInput(UGen input)
If you want to do something other than the default behavior when your
UGen is patched to, you can override this method in your derived class.
|
float[] |
getLastValues()
Return the last values generated by this UGen.
|
void |
patch(AudioOutput output)
Patch the output of this UGen to the provided AudioOuput.
|
UGen |
patch(UGen.UGenInput connectToInput)
Connect the output of this UGen to a specific input of connecToUGen.
|
UGen |
patch(UGen connectToUGen)
Connect the output of this UGen to the first input of connectToUGen.
|
void |
printInputs()
Prints all inputs connected to this UGen (for debugging)
|
protected void |
removeInput(UGen input)
If you need to do something specific when something is unpatched from
your UGen, you can override this method.
|
float |
sampleRate()
Returns the sample rate of this UGen.
|
protected void |
sampleRateChanged()
Override this method in your derived class to receive a notification when
the sample rate of your UGen has changed.
|
void |
setAudioChannelCount(int numberOfChannels)
Let this UGen know how many channels of audio you will be asking it for.
|
void |
setSampleRate(float newSampleRate)
Set the sample rate for this UGen.
|
void |
tick(float[] channels)
Generates one sample frame for this UGen.
|
protected abstract void |
uGenerate(float[] channels)
Implement this method when you extend UGen.
|
void |
unpatch(AudioOutput output)
Unpatch the output of this output from the provided AudioOutput.
|
void |
unpatch(UGen connectToUGen)
Remove this UGen as the input to the connectToUGen.
|
public final UGen patch(UGen connectToUGen)
connectToUGen
- The UGen to connect to.sine.patch( gain ).patch( out );
public final UGen patch(UGen.UGenInput connectToInput)
connectToInput
- protected void addInput(UGen input)
input
- public final void patch(AudioOutput output)
output
- The AudioOutput you want to connect this UGen to.public final void unpatch(AudioOutput output)
output
- The AudioOutput this UGen should be disconnected from.public final void unpatch(UGen connectToUGen)
connectToUGen
- protected void removeInput(UGen input)
input
- public final void tick(float[] channels)
channels
- An array that represents one sample frame. To generate a mono
signal, pass an array of length 1, if stereo an array of
length 2, and so on. How a UGen deals with multi-channel sound
will be implementation dependent.protected abstract void uGenerate(float[] channels)
getLastValues
method of your audio UGenInput to
retrieve the audio you want to modify, which you will then modify however
you need to, assigning the result to the values in channels
.channels
- an array representing one sample frame.public final float[] getLastValues()
public final float sampleRate()
protected void sampleRateChanged()
public final void setSampleRate(float newSampleRate)
newSampleRate
- the sample rate this UGen should generate at.public void setAudioChannelCount(int numberOfChannels)
numberOfChannels
- how many channels of audio you will be generating with this
UGenpublic void printInputs()