public abstract class UGen extends Bead
AudioContext
used to construct the UGen. Any UGen output can be connected to any other UGen input, using addInput(int, UGen, int)
(or use addInput(UGen)
to connect all outputs of one UGen to all inputs of another). UGens are constructed using an
AudioContext to determine the correct buffer size for audio processing. By connecting a UGen's output to another
UGen's input the source UGen is automatically added to a call chain that propagates
through subsequent UGens from the root UGen of the AudioContext. UGens that
do not have outputs (such as Clock
) can be added
manually to the call chain using addDependent(UGen)
from any UGen
that is part of the call chain (such as the root UGen of the AudioContext
).
UGen inherits the
Bead.start()
, Bead.kill()
and Bead.pause(boolean)
behaviour, and messaging system from
Bead
. Importantly, when UGens are paused, they cease audio processing, and when they are killed, they are automatically removed from any audio chains. This allows for very easy removal of elements from the call chain.
The method calculateBuffer()
must be implemented by subclasses of UGen that actually do something. Each UGen has two 2D arrays of floats, bufIn
, bufOut
, holding the current input and output audio buffers (this is stored in the form float[numChannels][bufferSize]). The goal of a calculateBuffer()
method, therefore, is to fill bufOut
with appropriate data for the current audio frame. Examples can be found in the source code of classes in the net.beadsproject.beads.ugens
package.Modifier and Type | Class and Description |
---|---|
protected static class |
UGen.OutputInitializationRegime
Used to determine how a UGen sets its outputs up before calculateBuffer() is called.
|
protected static class |
UGen.OutputPauseRegime |
Modifier and Type | Field and Description |
---|---|
protected int |
bufferSize
The buffer size.
|
protected float[][] |
bufIn
The buffer used internally to store input data.
|
protected float[][] |
bufOut
The buffer that will be grabbed by other UGens connected to this one.
|
protected AudioContext |
context
The AudioContext used by this buffer.
|
protected int |
ins
The number of inputs.
|
protected UGen.OutputInitializationRegime |
outputInitializationRegime |
protected UGen.OutputPauseRegime |
outputPauseRegime |
protected int |
outs
The number of outputs.
|
Constructor and Description |
---|
UGen(AudioContext context)
Create a new UGen from the given AudioContext but with no inputs or
outputs.
|
UGen(AudioContext context,
int outs)
Create a new UGen from the given AudioContext with no inputs and the
given number of outputs.
|
UGen(AudioContext context,
int ins,
int outs)
Create a new UGen from the given AudioContext with the given number of
inputs and outputs.
|
Modifier and Type | Method and Description |
---|---|
void |
addDependent(UGen dependent)
Adds a UGen to this UGen's dependency list, causing the dependent UGen to
get updated when this one does.
|
void |
addInput(int inputIndex,
UGen sourceUGen,
int sourceOutputIndex)
Connect a specific output from another UGen to a specific input of this
UGen.
|
void |
addInput(UGen sourceUGen)
Connect another UGen's outputs to the inputs of this UGen.
|
abstract void |
calculateBuffer()
Called by the signal chain to update this UGen's ouput data.
|
void |
clearDependents()
Clears the list of dependent UGens.
|
void |
clearInputConnections()
Clear all of this UGen's input connections.
|
boolean |
containsInput(UGen ugen)
Checks if this UGen has the given UGen plugged into it.
|
void |
crossfadeInput(UGen source,
UGen destination,
float crossoverTime)
Performs a crossfade from one UGen (which must already be connected) to another.
|
java.util.Set<UGen> |
getConnectedInputs()
Returns a flat Set (i.e.
|
AudioContext |
getContext()
Gets the AudioContext used by this UGen.
|
java.util.Map<java.lang.String,UGen> |
getEnvelopes()
Gets the envelopes controlling this UGen (using Reflection).
|
int |
getIns()
Gets the number of inputs.
|
int |
getNumberOfConnectedUGens(int index)
Gets the number of UGens connected at the specified input index of
this UGen.
|
int |
getNumberOfDependents()
Gets the number of dependent UGens.
|
float[] |
getOutBuffer(int i)
Gets an entire output buffer from a specific channel at a given time step.
|
int |
getOuts()
Gets the number of outputs.
|
long |
getTimeTakenLastUpdate() |
float |
getValue()
Gets the value of the buffer, assuming that the buffer only has one value.
|
float |
getValue(int i,
int j)
Gets a specific specified value from the output buffer, with indices i (channel)
and j (offset into buffer).
|
double |
getValueDouble()
Gets the value as a double.
|
double |
getValueDouble(int i,
int j)
Gets the value as a double.
|
protected void |
initializeOuts() |
boolean |
isTimerMode() |
boolean |
isUpdated()
Checks if this UGen has been updated in the current timeStep.
|
boolean |
noInputs()
Determines whether this UGen has no UGens connected to its inputs.
|
void |
pause(boolean paused)
Pauses/un-pauses the current UGen.
|
void |
printInBuffers()
Prints the contents of the input buffers to System.out.
|
void |
printInputList()
Prints a list of UGens connected to this UGen's inputs to System.out.
|
void |
printOutBuffers()
Prints the contents of the output buffers to System.out.
|
void |
removeAllConnections(UGen sourceUGen)
Disconnects the specified UGen from this UGen at all inputs.
|
boolean |
removeConnection(int inputChannel,
UGen sourceUGen,
int sourceOutputChannel)
Disconnects the connection from the specified UGen to this one.
|
void |
removeDependent(UGen dependent)
Removes the specified UGen from this UGen's dependency list.
|
protected void |
setOutsToPause() |
void |
setTimerMode(boolean timerMode) |
void |
setValue(float value)
Sets the value of
bufOut . |
void |
update()
Updates the UGen.
|
void |
zeroIns()
Sets the input buffers to zero.
|
void |
zeroOuts()
Sets the output buffers to zero.
|
getKillListener, getName, isDeleted, isPaused, kill, message, messageReceived, setKillListener, setName, start, toString
protected AudioContext context
protected int ins
protected int outs
protected float[][] bufIn
protected float[][] bufOut
protected int bufferSize
AudioContext
.protected UGen.OutputInitializationRegime outputInitializationRegime
protected UGen.OutputPauseRegime outputPauseRegime
public UGen(AudioContext context)
context
- AudioContext to use.public UGen(AudioContext context, int outs)
context
- AudioContext to use.outs
- number of outputs.public UGen(AudioContext context, int ins, int outs)
context
- AudioContext to use.ins
- number of inputs.outs
- number of outputs.public AudioContext getContext()
public int getIns()
public int getOuts()
public void zeroOuts()
public void zeroIns()
protected void setOutsToPause()
protected void initializeOuts()
public void update()
AudioContext
) then this method does nothing. If the UGen does update, it
will firstly propagate the update()
call up the call chain using pullInputs()
, and secondly, call its own calculateBuffer()
method.public void printInputList()
public void addInput(UGen sourceUGen)
sourceUGen
- the UGen to connect to this UGen.public void addInput(int inputIndex, UGen sourceUGen, int sourceOutputIndex)
inputIndex
- the input of this UGen to connect to.sourceUGen
- the UGen to connect to this UGen.sourceOutputIndex
- the output of the connecting UGen with which to make the
connection.public void crossfadeInput(UGen source, UGen destination, float crossoverTime)
source
- the UGen to crossfade away from (assumed to already be connected), will be disconnected once cross-fade is over.destination
- the UGen to crossfade towards.crossoverTime
- the time taken.public void addDependent(UGen dependent)
Clock
to the call chain. As will UGens in the regular call chain, if a dependent UGen gets killed, this UGen will remove it from its dependency list.dependent
- the dependent UGen.public void removeDependent(UGen dependent)
dependent
- UGen to remove.public void clearDependents()
public int getNumberOfConnectedUGens(int index)
index
- index of input to inspect.public int getNumberOfDependents()
public boolean containsInput(UGen ugen)
ugen
- the UGen to test.public java.util.Set<UGen> getConnectedInputs()
public java.util.Map<java.lang.String,UGen> getEnvelopes()
public void removeAllConnections(UGen sourceUGen)
sourceUGen
- the UGen to disconnect.public boolean removeConnection(int inputChannel, UGen sourceUGen, int sourceOutputChannel)
inputChannel
- The channel of this UGen to check.sourceUGen
- The UGen to disconnect.sourceOutputChannel
- The channel of the source UGen.public void clearInputConnections()
public void printInBuffers()
public void printOutBuffers()
public boolean noInputs()
public abstract void calculateBuffer()
bufIn
and putting data
into bufOut
in some way. bufIn
and bufOut
are 2D arrays of floats of the form float[numChannels][bufferSize]. The length of the buffers is given by
bufferSize
, and the number of channels of the input and output buffers are given by ins
and outs
respectively.public float getValue(int i, int j)
i
- channel index.j
- buffer frame index.public float[] getOutBuffer(int i)
i
- the output channel.public float getValue()
Static
type UGens. It is equivalent to getValue(0, 0)
.public double getValueDouble(int i, int j)
i
- channel index.j
- buffer frame index.public double getValueDouble()
Static
type UGens. It is equivalent to getValue(0, 0)
.public void setValue(float value)
bufOut
. This is mainly a convenience method for use with Static
and Envelope
type UGens.value
- the new value.public boolean isUpdated()
public void pause(boolean paused)
pause
in class Bead
paused
- is true if paused.Bead.pause(boolean)
public boolean isTimerMode()
public void setTimerMode(boolean timerMode)
public long getTimeTakenLastUpdate()