net.beadsproject.beads.ugens
Class MultiWrapper

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.core.UGen
          extended by net.beadsproject.beads.core.UGenChain
              extended by net.beadsproject.beads.ugens.MultiWrapper
All Implemented Interfaces:
DataBeadReceiver

public class MultiWrapper
extends UGenChain
implements DataBeadReceiver

A generalized multi-channel wrapper for UGens. Can either be used to treat an existing array of UGens as one, big, multi-channel UGen, or to create a multi-channel UGen from newly created UGens.

In the simple case, it just wraps N one-channel UGens into one N-channel UGen.

Version:
0.9.5
Author:
Benito Crawford

Nested Class Summary
 
Nested classes/interfaces inherited from class net.beadsproject.beads.core.UGen
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
 
Field Summary
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
 
Constructor Summary
MultiWrapper(AudioContext context, int channels)
          Constructor for an multi-channel wrapper for 1-in/1-out UGens on each channel.
MultiWrapper(AudioContext context, int channels, int insPerChannel, int outsPerChannel)
          Constructor for an n-channel wrapper for UGens with a certain number inputs and a certain number outputs on each channel.
MultiWrapper(AudioContext context, UGen[] ugens, int insPerChannel, int outsPerChannel)
          Constructor for a multi-channel wrapper for an array of UGens that represent separate "channels".
 
Method Summary
 void addInput(int channelIndex, int channelUGenInput, UGen sourceUGen, int sourceOutput)
          A convenience method of adding inputs to specific channel UGens.
 UGen buildUGens(int channelIndex)
          Constructs and returns a UGen for each channel.
 int getChannels()
          Gets the number of channels.
 int getInsPerChannel()
          Gets the number of inputs per channel.
 int getOutsPerChannel()
          Gets the number of outs per channel.
 void messageReceived(Bead message)
          Forwards Beads to channel UGens.
 DataBeadReceiver sendData(DataBead db)
          Forwards a DataBead to all channel UGens.
 DataBeadReceiver sendData(int channel, DataBead db)
          Forwards a DataBead to a specific channel UGen.
 
Methods inherited from class net.beadsproject.beads.core.UGenChain
addToChainOutput, addToChainOutput, addToChainOutput, calculateBuffer, drawFromChainInput, drawFromChainInput, drawFromChainInput, postFrame, preFrame
 
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, getValue, getValueDouble, getValueDouble, initializeOuts, isTimerMode, isUpdated, noInputs, pause, printInBuffers, printInputList, printOutBuffers, removeAllConnections, removeConnection, removeDependent, setOutsToPause, setTimerMode, setValue, update, zeroIns, zeroOuts
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, kill, message, setKillListener, setName, start, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiWrapper

public MultiWrapper(AudioContext context,
                    int channels)
Constructor for an multi-channel wrapper for 1-in/1-out UGens on each channel. buildUGens(int) should be implemented to construct a UGen for each channel.

Parameters:
context - The audio context.
channels - The number of channels.

MultiWrapper

public MultiWrapper(AudioContext context,
                    int channels,
                    int insPerChannel,
                    int outsPerChannel)
Constructor for an n-channel wrapper for UGens with a certain number inputs and a certain number outputs on each channel. buildUGens(int) should be implemented to construct a UGen for each channel.

Parameters:
context - The audio context.
channels - The number of channels.
insPerChannel - The number of inputs per channel UGen.
outsPerChannel - The number of outputs per channel UGen.

MultiWrapper

public MultiWrapper(AudioContext context,
                    UGen[] ugens,
                    int insPerChannel,
                    int outsPerChannel)
Constructor for a multi-channel wrapper for an array of UGens that represent separate "channels".

Parameters:
context - The audio context.
ugens - The array of UGens to wrap.
insPerChannel - The number of inputs per channel.
outsPerChannel - The number of ouputs per channel.
Method Detail

buildUGens

public UGen buildUGens(int channelIndex)
Constructs and returns a UGen for each channel. If an array of UGens is not provided to MCWrapper at construction, this method should be overridden with code to create a UGen for each channel. To make the channel UGens modifiable, the UGen should implement DataBeadReceiver properly as this is the only way to change the channel UGens' parameters.

Parameters:
channelIndex - The index of the channel for which the UGen is being created.
Returns:
The new channel UGen.

addInput

public void addInput(int channelIndex,
                     int channelUGenInput,
                     UGen sourceUGen,
                     int sourceOutput)
A convenience method of adding inputs to specific channel UGens. Calling

addInput(c, i, sUGen, o) is equivalent to calling

addInput(c * insPerChannel + i, sUGen, o).

Parameters:
channelIndex - The channel to call addInput on.
channelUGenInput - The input index of the channel UGen.
sourceUGen - The source UGen.
sourceOutput - The output of the source UGen.

sendData

public DataBeadReceiver sendData(DataBead db)
Forwards a DataBead to all channel UGens. If the channel UGens are DataBeadReceivers, it calls DataBeadReceiver.sendData(DataBead); otherwise it calls Bead.message(Bead).

Specified by:
sendData in interface DataBeadReceiver
Parameters:
db - The DataBead.
Returns:
Typically, the object instance: this.

sendData

public DataBeadReceiver sendData(int channel,
                                 DataBead db)
Forwards a DataBead to a specific channel UGen. If the channel UGen is a DataBeadReceiver, it calls DataBeadReceiver.sendData(DataBead); otherwise it calls Bead.message(Bead).

Parameters:
channel - The index of the channel UGen to which to forward the DataBead.
db - The DataBead.

messageReceived

public void messageReceived(Bead message)
Forwards Beads to channel UGens. If message is a DataBead and the channel UGens are DataBeadReceivers, it calls DataBeadReceiver.sendData(DataBead); otherwise it calls Bead.message(Bead).

Overrides:
messageReceived in class Bead
Parameters:
message - the message

getChannels

public int getChannels()
Gets the number of channels.

Returns:
The number of channels.

getInsPerChannel

public int getInsPerChannel()
Gets the number of inputs per channel.

Returns:
The number of inputs per channel.

getOutsPerChannel

public int getOutsPerChannel()
Gets the number of outs per channel.

Returns:
The number of outs per channel.