net.beadsproject.beads.ugens
Class Clock

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.core.UGen
          extended by net.beadsproject.beads.ugens.Clock
All Implemented Interfaces:
IntegerBead

public class Clock
extends UGen
implements IntegerBead

A sample rate Clock. A Clock generates timing data at two levels: ticks and beats. It notifies an BeadArray of listeners at each tick. These listeners can query the Clock to find out the current tick count, if it is on a beat, and the current beat count. The rate of ticking of the Clock is controlled by an interval envelope.

Author:
ollie

Field Summary
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outs
 
Constructor Summary
Clock(AudioContext context)
          Instantiates a new Clock with a static interval of 1000ms.
Clock(AudioContext context, float interval)
          Instantiates a new Clock with the given static interval in milliseconds.
Clock(AudioContext context, UGen env)
          Instantiates a new Clock with the given interval enveliope.
 
Method Summary
 void addMessageListener(Bead newListener)
          Adds a new message listener.
 void calculateBuffer()
          Called by the signal chain to update this UGen's ouput data.
 int getBeatCount()
          Gets the current beat count.
 int getCount()
          Gets the tick count.
 int getInt()
          Gets the intger value.
 UGen getIntervalEnvelope()
          Gets the interval envelope.
 int getTicksPerBeat()
          Gets the ticks per beat.
 boolean isBeat()
          Checks if the current tick is on a beat.
 boolean isBeat(int mod)
          Checks if the Clock is on a beat at the given modulo level.
 boolean isClicking()
          Checks if the Clock is set to make an audible click.
 void removeMessageListener(Bead newListener)
          Removes the given message listener.
 void reset()
          Resets the Clock immediately.
 void setClick(boolean click)
          Starts/stops the audible click.
 void setCount(int count)
          Sets the tick count.
 void setIntervalEnvelope(UGen intervalEnvelope)
          Sets the interval envelope.
 void setTicksPerBeat(int ticksPerBeat)
          Sets the ticks per beat.
 
Methods inherited from class net.beadsproject.beads.core.UGen
addDependent, addInput, addInput, clearInputConnections, getContext, getIns, getNumberOfConnectedUGens, getOuts, getValue, getValue, noInputs, pause, printInputList, printOutBuffers, removeAllConnections, removeDependent, setValue, 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
 

Constructor Detail

Clock

public Clock(AudioContext context)
Instantiates a new Clock with a static interval of 1000ms.

Parameters:
context - the AudioContext.

Clock

public Clock(AudioContext context,
             float interval)
Instantiates a new Clock with the given static interval in milliseconds.

Parameters:
context - the AudioContext.
interval - the interval in milliseconds.

Clock

public Clock(AudioContext context,
             UGen env)
Instantiates a new Clock with the given interval enveliope.

Parameters:
context - the AudioContext.
env - the interval envelope.
Method Detail

isClicking

public boolean isClicking()
Checks if the Clock is set to make an audible click.

Returns:
true if clicking.

setClick

public void setClick(boolean click)
Starts/stops the audible click.

Parameters:
click - true for audible click.

addMessageListener

public void addMessageListener(Bead newListener)
Adds a new message listener.

Parameters:
newListener - the new message listener.

removeMessageListener

public void removeMessageListener(Bead newListener)
Removes the given message listener.

Parameters:
newListener - the listener being removed.

reset

public void reset()
Resets the Clock immediately.


getCount

public int getCount()
Gets the tick count.

Returns:
the tick count.

setCount

public void setCount(int count)
Sets the tick count.

Parameters:
count - the new tick count.

setIntervalEnvelope

public void setIntervalEnvelope(UGen intervalEnvelope)
Sets the interval envelope.

Parameters:
intervalEnvelope - the new interval envelope.

getIntervalEnvelope

public UGen getIntervalEnvelope()
Gets the interval envelope.

Returns:
the interval envelope.

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

getInt

public int getInt()
Description copied from interface: IntegerBead
Gets the intger value.

Specified by:
getInt in interface IntegerBead
Returns:
the integer value.

getTicksPerBeat

public int getTicksPerBeat()
Gets the ticks per beat.

Returns:
the ticks per beat.

setTicksPerBeat

public void setTicksPerBeat(int ticksPerBeat)
Sets the ticks per beat.

Parameters:
ticksPerBeat - the new ticks per beat.

isBeat

public boolean isBeat()
Checks if the current tick is on a beat.

Returns:
true if the current tick is a beat.

isBeat

public boolean isBeat(int mod)
Checks if the Clock is on a beat at the given modulo level.

Parameters:
mod - the modulo.
Returns:
true if the clock is on a beat, and the current beat count is a multiple of mod.

getBeatCount

public int getBeatCount()
Gets the current beat count.

Returns:
the current beat count.