com.softsynth.jmsl
Class SequentialCollection

java.lang.Object
  extended by com.softsynth.jmsl.MusicJob
      extended by com.softsynth.jmsl.ParallelCollection
          extended by com.softsynth.jmsl.SequentialCollection
All Implemented Interfaces:
Composable, Playable, java.lang.Runnable
Direct Known Subclasses:
Player, ScoreCollection

public class SequentialCollection
extends ParallelCollection

A sequential collection launches each of its Composable children in sequence. Can alternatively use a user-defined behavior function to choose which child to launch every repeat (see Behavior). If behavior function returns null child, it signals finish(), so even a colleciton with 10000 repeat count will terminate early if child returned is null. If Behavior itself is null, collection acts strictly sequentially. Can switch back and forth between these modes.

Example of building a SequentialCollection with two stock MusicJobs. The collection will act behaviorally using UniformRandomBehavior which chooses a child randomly upon each of 5 repeats.

                SequentialCollection seqCol = new SequentialCollection(new MusicJob(), new MusicJob());
                seqCol.setBehavior(new UniformRandomBehavior());
                seqCol.setRepeats(5);
                seqCol.launch(JMSL.now());

  1. startDelay
  2. start()
  3. startPlayables.play() optional
  4. startPause
  5. internalRepeat(), launches all children sequentially, or launches one chosen with behavior
  6. repeat()
  7. repeatPlayables.play() optional
  8. repeatPause (loop back to repeat() for getRepeats() times)
  9. stopDelay
  10. stopPlayables.play() optional
  11. stop()


Field Summary
 
Fields inherited from class com.softsynth.jmsl.MusicJob
repeatCount
 
Constructor Summary
SequentialCollection()
          Simple constructor.
SequentialCollection(Composable child1)
          Conveniant constructor which automatically adds one Composable child to the sequential hierarchy.
SequentialCollection(Composable child1, Composable child2)
          Conveniant constructor which automatically adds two Composable children to the sequential hierarchy.
SequentialCollection(Composable child1, Composable child2, Composable child3)
          Conveniant constructor which automatically adds three Composable children to the sequential hierarchy.
SequentialCollection(Composable child1, Composable child2, Composable child3, Composable child4)
          Conveniant constructor which automatically adds four Composable children to the sequential hierarchy.
 
Method Summary
 Behavior getBehavior()
          Retrieve the class that chooses a child to launch.
 double internalRepeat(double playTime)
          Every repeat, either choose next child if acting sequentially (ie getBehavior() == null) or choose one using Behavior.
static void main(java.lang.String[] args)
           
 void print()
           
 void setBehavior(Behavior b)
          Plug in a class satisfying the Behavior interface, which chooses which child to launch every repeat.
 
Methods inherited from class com.softsynth.jmsl.ParallelCollection
get, halt, printHierarchy, set
 
Methods inherited from class com.softsynth.jmsl.MusicJob
add, addPlayLurker, addRepeatPlayable, addStartPlayable, addStopPlayable, advanceCurrentTime, contains, elements, finish, finishAll, getChild, getChildren, getCurrentTime, getDataTranslator, getDuration, getInstrument, getName, getParent, getPlayLurkers, getRepeatCount, getRepeatPause, getRepeats, getStartDelay, getStartPause, getStartTime, getStopDelay, getTimeStretch, getTransposition, indexOf, insert, isRunning, launch, launch, play, play, printHierarchy, remove, remove, removeAll, removeAllPlayLurkers, removeAllRepeatPlayables, removeAllStartPlayables, removeAllStopPlayables, removePlayLurker, removeRepeatPlayable, removeStartPlayable, removeStopPlayable, repeat, run, setCurrentTime, setDataTranslator, setDuration, setInstrument, setName, setParent, setRepeatPause, setRepeats, setStartDelay, setStartPause, setStartTime, setStopDelay, setTimeStretch, setTransposition, size, start, stop, timeStretch, transposition, waitForDone
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequentialCollection

public SequentialCollection()
Simple constructor. Builds a SequentialCollection with no children, and initializes its Behavior to UniformRandomBehavior (although it defaults to sequential behavior). Use add(Composable) to add children.


SequentialCollection

public SequentialCollection(Composable child1)
Conveniant constructor which automatically adds one Composable child to the sequential hierarchy.


SequentialCollection

public SequentialCollection(Composable child1,
                            Composable child2)
Conveniant constructor which automatically adds two Composable children to the sequential hierarchy.


SequentialCollection

public SequentialCollection(Composable child1,
                            Composable child2,
                            Composable child3)
Conveniant constructor which automatically adds three Composable children to the sequential hierarchy.


SequentialCollection

public SequentialCollection(Composable child1,
                            Composable child2,
                            Composable child3,
                            Composable child4)
Conveniant constructor which automatically adds four Composable children to the sequential hierarchy.

Method Detail

setBehavior

public void setBehavior(Behavior b)
Plug in a class satisfying the Behavior interface, which chooses which child to launch every repeat. If behavior returns null child, finish() is called.


getBehavior

public Behavior getBehavior()
Retrieve the class that chooses a child to launch. If Behavior is null, collection executes sequentially.

Returns:
Behavior used to choose children.

internalRepeat

public double internalRepeat(double playTime)
                      throws java.lang.InterruptedException
Every repeat, either choose next child if acting sequentially (ie getBehavior() == null) or choose one using Behavior. If Behavior returns null child, finish()

Specified by:
internalRepeat in interface Composable
Overrides:
internalRepeat in class ParallelCollection
Returns:
time of completion
Throws:
java.lang.InterruptedException - if the thread running this Composable is interrupted.

print

public void print()
Overrides:
print in class ParallelCollection

main

public static void main(java.lang.String[] args)