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:
java.io.Serializable

public class Pattern
extends Bead
implements java.io.Serializable

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.

See Also:
Serialized Form

Nested Class Summary
static class Pattern.ContinuousPlayMode
           
 
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.
 Pattern.ContinuousPlayMode getContinuousPlayMode()
           
 java.util.ArrayList<java.lang.Integer> getEventAtIndex(int index)
           
 java.util.ArrayList<java.lang.Integer> getEventAtStep(int index)
          Gets the event at the given integer index.
 java.util.Set<java.lang.Integer> getEvents()
           
 int getHop()
          Gets the hop size.
 int getLastIndex()
           
 int getLoop()
          Gets the loop length.
 void messageReceived(Bead message)
          Handles a message.
 void removeEvent(int key, int value)
          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 setContinuousPlayMode(Pattern.ContinuousPlayMode continuousPlayMode)
           
 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.

getContinuousPlayMode

public Pattern.ContinuousPlayMode getContinuousPlayMode()

setContinuousPlayMode

public void setContinuousPlayMode(Pattern.ContinuousPlayMode continuousPlayMode)

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,
                        int value)
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:
Bead.message(Bead)

getEventAtStep

public java.util.ArrayList<java.lang.Integer> getEventAtStep(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.

getEventAtIndex

public java.util.ArrayList<java.lang.Integer> getEventAtIndex(int index)

getLastIndex

public int getLastIndex()

getEvents

public java.util.Set<java.lang.Integer> getEvents()

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.