provided.music
Class ToggleDecoratorSeqList

java.lang.Object
  extended by provided.music.ToggleDecoratorSeqList
All Implemented Interfaces:
IPhrase, ISeqList
Direct Known Subclasses:
FineToggleDecoratorSeqList

public class ToggleDecoratorSeqList
extends java.lang.Object
implements ISeqList

Multiple Decorator ISeqList where the active decoree (the "target") is toggled (cycled, actually) through all the available decorees. This is arguably a State Design Pattern where each decoree is considered to be another state of the system. This is used to implement repeats where the first time through, the notes are linked back to a repeat start (decoree #0) but the next time through, the next note is the one after the repeat (decoree #1).

Author:
swong

Field Summary
private  ISeqList[] decorees
          The decoree/target ISeqList list.
private  int targetIdx
          The index of the current target decoree
 
Constructor Summary
ToggleDecoratorSeqList()
          Constructor that is used when the decoree is not known at construction time.
ToggleDecoratorSeqList(ISeqList... decorees)
          Constructor used to set the decorees to a known values at construction time.
 
Method Summary
 java.lang.Object execute(IPhraseVisitor algo, java.lang.Object... params)
          Simply delegates the call to the decoree.
 ISeqList getTargetDecoree()
          Accessor for the current target (active) decoree
 void setDecoree(int idx, ISeqList decoree)
          Setter methods used to set the decoree.
 void setDecorees(ISeqList... decorees)
           
 void setTargetToDecoree(int targetIdx)
          Used to explicitly set the target (active) decoree if needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decorees

private ISeqList[] decorees
The decoree/target ISeqList list. An MTSeqList by default.


targetIdx

private int targetIdx
The index of the current target decoree

Constructor Detail

ToggleDecoratorSeqList

public ToggleDecoratorSeqList(ISeqList... decorees)
Constructor used to set the decorees to a known values at construction time.

Parameters:
decorees - vararg list of ISeqList decorees

ToggleDecoratorSeqList

public ToggleDecoratorSeqList()
Constructor that is used when the decoree is not known at construction time. Creates a 2-decoree object only. For more, use the other constructor with default values for decorees.

Method Detail

setDecorees

public void setDecorees(ISeqList... decorees)

setDecoree

public void setDecoree(int idx,
                       ISeqList decoree)
Setter methods used to set the decoree.

Parameters:
decoree - The new decoree ISeqList.

setTargetToDecoree

public void setTargetToDecoree(int targetIdx)
Used to explicitly set the target (active) decoree if needed.

Parameters:
targetIdx - the index of the target decoree

getTargetDecoree

public ISeqList getTargetDecoree()
Accessor for the current target (active) decoree

Returns:
The current target (active) decoree

execute

public java.lang.Object execute(IPhraseVisitor algo,
                                java.lang.Object... params)
Simply delegates the call to the decoree. The target decoree is advanced to the next decoree, or cycled back to the #0 decoree if the current target is the last one.

Specified by:
execute in interface IPhrase
Parameters:
algo - The visitor to execute
params - The input parameters supplied to the algo when its appropriate case is called.
Returns:
The return value from executing the appropriate case on the visitor.