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 the signal path is and it can be stated 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 call
activate()
on 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.
For a list of all UGens included with Minim, see the UGens package doc.Modifier and Type | Class and Description |
---|---|
static class |
UGen.InputType
This enum is used to specify the InputType of the UGenInput.
|
class |
UGen.UGenInput
A UGenInput represents parameter of the UGen that can be
controlled by other UGens by patching to it.
|
Modifier | Constructor and Description |
---|---|
protected |
UGen()
Constructor for a UGen.
|
Modifier and Type | Method and Description |
---|---|
protected UGen.UGenInput |
addAudio() |
protected UGen.UGenInput |
addControl() |
protected UGen.UGenInput |
addControl(float initialValue) |
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.
|
int |
channelCount()
Returns the number of channels this UGen has been configured to generate.
|
protected void |
channelCountChanged()
This method is only called when setChannelCount results in the channel count
of this UGen actually changing.
|
float[] |
getLastValues()
Return the last values generated by this UGen.
|
void |
patch(AudioOutput audioOutput)
Patch the output of this UGen to the provided AudioOuput.
|
UGen |
patch(UGen.UGenInput connectToInput)
Connect the output of this UGen to a specific UGenInput of a UGen.
|
UGen |
patch(UGen connectToUGen)
Send the output of this UGen to another UGen, UGenInput, or AudioOutput.
|
void |
printInputs()
Prints all inputs connected to this UGen (for debugging)
|
protected void |
removeInput(UGen input)
When a UGen is unpatched from this UGen, removeInput is called.
|
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 |
setChannelCount(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 audioOutput)
Unpatch this UGen from an AudioOutput or other UGen.
|
void |
unpatch(UGen fromUGen)
Remove this UGen as an input of fromUGen.
|
public final UGen patch(UGen connectToUGen)
connectToUGen
- The UGen to patch to.sine.patch( gain ).patch( out );
public final UGen patch(UGen.UGenInput connectToInput)
connectToInput
- The UGenInput to patch to.public final void patch(AudioOutput audioOutput)
audioOutput
- The AudioOutput you want to connect this UGen to.protected void addInput(UGen input)
input
- the UGen to add as an inputpublic final void unpatch(AudioOutput audioOutput)
audioOutput
- The AudioOutput this UGen should be disconnected from.public final void unpatch(UGen fromUGen)
fromUGen
- The UGen to unpatch from.protected void removeInput(UGen input)
input
- the UGen to remove as an input to this UGenpublic 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
- float, the sample rate this UGen should generate at.public void setChannelCount(int numberOfChannels)
numberOfChannels
- how many channels of audio you will be generating with this UGenpublic int channelCount()
protected void channelCountChanged()
public void printInputs()
protected UGen.UGenInput addControl()
protected UGen.UGenInput addControl(float initialValue)
protected UGen.UGenInput addAudio()