Package com.softsynth.jmsl
Class SequentialCollection
java.lang.Object
com.softsynth.jmsl.MusicJob
com.softsynth.jmsl.ParallelCollection
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.
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());
- startDelay
- start()
- startPlayables.play() optional
- startPause
- internalRepeat(), launches all children sequentially, or launches one chosen with behavior
- repeat()
- repeatPlayables.play() optional
- repeatPause (loop back to repeat() for getRepeats() times)
- stopDelay
- stopPlayables.play() optional
- stop()
-
Field Summary
Fields inherited from class com.softsynth.jmsl.MusicJob
repeatCount
-
Constructor Summary
Constructors Constructor Description 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
Modifier and Type Method Description 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, getRepeatPlayables, getRepeats, getStartDelay, getStartPause, getStartPlayables, getStartTime, getStopDelay, getStopPlayables, 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 Details
-
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
Conveniant constructor which automatically adds one Composable child to the sequential hierarchy. -
SequentialCollection
Conveniant constructor which automatically adds two Composable children to the sequential hierarchy. -
SequentialCollection
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 Details
-
setBehavior
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
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.InterruptedExceptionEvery 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 interfaceComposable
- Overrides:
internalRepeat
in classParallelCollection
- Returns:
- time of completion
- Throws:
java.lang.InterruptedException
- if the thread running this Composable is interrupted.
-
print
public void print()- Overrides:
print
in classParallelCollection
-
main
public static void main(java.lang.String[] args)
-