net.beadsproject.beads.ugens
Class Envelope

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.core.UGen
          extended by net.beadsproject.beads.ugens.Envelope

public class Envelope
extends UGen

An Envelope generates a sequence of timed transitions (segments) between values as an audio signal. New segments are added to a running Envelope using variations of the method addSegment. With the method addSegment(float, float, float, Bead) a Bead can be provided which gets triggered when the segment has reached its destination. At any point in time, the Envelope maintains a current value. New segments define transitions from that current value to a destination value over a given duration. Instead of a linear transition, a curved transition can be used. The curve is defined as the mapping of the range [0,1] from y=x to y=x^p with a given exponent p.

Author:
ollie

Nested Class Summary
 class Envelope.Segment
          The nested class Segment.
 
Nested classes/interfaces inherited from class net.beadsproject.beads.core.UGen
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
 
Field Summary
protected  float[] myBufOut
          The real output buffer.
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
 
Constructor Summary
Envelope(AudioContext context)
          Instantiates a new Envelope with start value 0.
Envelope(AudioContext context, float value)
          Instantiates a new Envelope with the specified start value.
 
Method Summary
 Envelope addSegment(float endValue, float duration)
          Adds a new Segment.
 Envelope addSegment(float endValue, float duration, Bead trigger)
          Adds a new Segment.
 Envelope addSegment(float endValue, float duration, float curvature)
          Adds a new Segment.
 Envelope addSegment(float endValue, float duration, float curvature, Bead trigger)
          Adds a new Segment.
 Envelope addSegments(java.util.List<Envelope.Segment> segments)
          Adds the specified List of Segments.
 void calculateBuffer()
          Called by the signal chain to update this UGen's ouput data.
 Envelope clear()
          Clears the list of Segments.
 float getCurrentValue()
          Gets the current 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).
 boolean isLocked()
          Checks whether the Envelope is locked.
 Envelope lock(boolean lock)
          Locks/unlocks the Envelope.
 void setValue(float value)
          Clears the list of Segments and sets the current value of the Envelope immediately.
 
Methods inherited from class net.beadsproject.beads.core.UGen
addDependent, addInput, addInput, clearDependents, clearInputConnections, containsInput, crossfadeInput, getConnectedInputs, getContext, getEnvelopes, getIns, getNumberOfConnectedUGens, getNumberOfDependents, getOutBuffer, getOuts, getTimeTakenLastUpdate, getValue, getValueDouble, getValueDouble, initializeOuts, isTimerMode, isUpdated, noInputs, pause, printInBuffers, printInputList, printOutBuffers, removeAllConnections, removeConnection, removeDependent, setOutsToPause, setTimerMode, update, zeroIns, zeroOuts
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, kill, message, messageReceived, setKillListener, setName, start, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myBufOut

protected float[] myBufOut
The real output buffer.

Constructor Detail

Envelope

public Envelope(AudioContext context)
Instantiates a new Envelope with start value 0.

Parameters:
context - the AudioContext.

Envelope

public Envelope(AudioContext context,
                float value)
Instantiates a new Envelope with the specified start value.

Parameters:
context - the AudioContext.
value - the start value.
Method Detail

lock

public Envelope lock(boolean lock)
Locks/unlocks the Envelope.


isLocked

public boolean isLocked()
Checks whether the Envelope is locked.

Returns:
true if the Envelope is locked.

addSegment

public Envelope addSegment(float endValue,
                           float duration,
                           float curvature)
Adds a new Segment.

Parameters:
endValue - the destination value.
duration - the duration.
curvature - the exponent of the curve.

addSegment

public Envelope addSegment(float endValue,
                           float duration,
                           float curvature,
                           Bead trigger)
Adds a new Segment.

Parameters:
endValue - the destination value.
duration - the duration.
curvature - the exponent of the curve.
trigger - the trigger.

addSegment

public Envelope addSegment(float endValue,
                           float duration)
Adds a new Segment.

Parameters:
endValue - the destination value.
duration - the duration.

addSegment

public Envelope addSegment(float endValue,
                           float duration,
                           Bead trigger)
Adds a new Segment.

Parameters:
endValue - the destination value.
duration - the duration.
trigger - the trigger.

addSegments

public Envelope addSegments(java.util.List<Envelope.Segment> segments)
Adds the specified List of Segments.

Parameters:
segments - the Segments.

setValue

public void setValue(float value)
Clears the list of Segments and sets the current value of the Envelope immediately.

Overrides:
setValue in class UGen
Parameters:
value - the new value.
See Also:
setValue(float)

clear

public Envelope clear()
Clears the list of Segments.


getCurrentValue

public float getCurrentValue()
Gets the current value.

Returns:
the current value.

calculateBuffer

public void calculateBuffer()
Description copied from class: UGen
Called by the signal chain to update this UGen's ouput data. Subclassses of UGen should implement the UGen's DSP perform routine here. In general this involves grabbing data from UGen.bufIn and putting data into UGen.bufOut in some way. UGen.bufIn and UGen.bufOut are 2D arrays of floats of the form float[numChannels][bufferSize]. The length of the buffers is given by UGen.bufferSize, and the number of channels of the input and output buffers are given by UGen.ins and UGen.outs respectively.

Specified by:
calculateBuffer in class UGen

getValue

public float getValue(int i,
                      int j)
Description copied from class: UGen
Gets a specific specified value from the output buffer, with indices i (channel) and j (offset into buffer).

Overrides:
getValue in class UGen
Parameters:
i - channel index.
j - buffer frame index.
Returns:
value of specified sample.