net.beadsproject.beads.events
Class Pattern

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.events.Pattern
All Implemented Interfaces:
IntegerBead

public class Pattern
extends Bead
implements IntegerBead

A Pattern is a Bead that responds to integer events by generating other integer events and forwarding them to a BeadArray of listeners. Typically, Patterns are used with Clocks.

Patterns contain a list of events specified as key/value pairs of integers. A Pattern keeps an internal counter which is incremented internally. When the counter is incremented, if its new value is listed as a key, Pattern forwards the corresponding value to its listeners. Pattern responds to Bead messages that implement IntegerBead. An incoming integer causes Pattern's internal counter to increment if it is a multiple of hop. If the internal counter reaches loop, it returns to zero. In this way, Pattern can be quicly maniuplated to play back at different speeds and loop lengths in response to a regular Clock.


Constructor Summary
Pattern()
          Instantiates a new empty pattern.
 
Method Summary
 void addEvent(int key, int value)
          Adds an event consisting of a integer key and an integer value.
 void addListener(Bead listener)
          Adds a listener.
 void clear()
          Clears the pattern data.
 java.lang.Integer getEventAtIndex(int index)
          Gets the event at the given integer index.
 int getHop()
          Gets the hop size.
 int getInt()
          Gets the intger value.
 int getLoop()
          Gets the loop length.
 int getValue()
          Gets the current value.
 void messageReceived(Bead message)
          Handles a message.
 void removeEvent(int key)
          Removes the event with the given integer key.
 void removeListener(Bead listener)
          Removes a listener.
 void reset()
          Resets the pattern's current index to zero.
 void setHop(int hop)
          Sets the hop size.
 void setLoop(int loop)
          Sets the loop length and activates loop mode.
 void setNoLoop()
          Deactivates loop mode.
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, kill, message, pause, setKillListener, setName, start, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pattern

public Pattern()
Instantiates a new empty pattern.

Method Detail

reset

public void reset()
Resets the pattern's current index to zero.


addListener

public void addListener(Bead listener)
Adds a listener.

Parameters:
listener - the new listener.

removeListener

public void removeListener(Bead listener)
Removes a listener.

Parameters:
listener - the listener.

addEvent

public void addEvent(int key,
                     int value)
Adds an event consisting of a integer key and an integer value.

Parameters:
key - the key.
value - the value.

removeEvent

public void removeEvent(int key)
Removes the event with the given integer key.

Parameters:
key - the key.

clear

public void clear()
Clears the pattern data. Does not reset the Pattern.


messageReceived

public void messageReceived(Bead message)
Handles a message. The message argument must implement IntegerBead. Checks to see if it should do anything for the given integer, and forwards any resulting integer to its listeners.

Overrides:
messageReceived in class Bead
Parameters:
message - the message
See Also:
com.olliebown.beads.core.Bead#message(com.olliebown.beads.core.Bead)

getEventAtIndex

public java.lang.Integer getEventAtIndex(int index)
Gets the event at the given integer index.

Parameters:
index - the index.
Returns:
the event at this index, or null if no event exists.

getLoop

public int getLoop()
Gets the loop length.

Returns:
the loop length.

setLoop

public void setLoop(int loop)
Sets the loop length and activates loop mode.

Parameters:
loop - the loop length.

setNoLoop

public void setNoLoop()
Deactivates loop mode.


getHop

public int getHop()
Gets the hop size.

Returns:
the hop size.

setHop

public void setHop(int hop)
Sets the hop size.

Parameters:
hop - the hop size.

getInt

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

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

getValue

public int getValue()
Gets the current value.

Returns:
the current value.