Package com.softsynth.jmsl
Class Player
java.lang.Object
com.softsynth.jmsl.MusicJob
com.softsynth.jmsl.ParallelCollection
com.softsynth.jmsl.SequentialCollection
com.softsynth.jmsl.Player
- All Implemented Interfaces:
Composable,Playable,java.lang.Runnable
public class Player extends SequentialCollection
A Player has a sequence of MusicShapes and one Instrument to interpret MusicShape data. Since it is
a SequentialCollection, it can execute these shapes in sequence or choose using a behavior.
Example:
Note that a given MusicShape can be added to more than one Player. Each Player's Instrument may interpret the MusicShape independently.
You can set up a Player with custom Instruments and Interpreters three ways:
Example:
// Stick two simple shapes into a Player and play the Player - printing output
public static void main(String args[]) {
// build a MusicShape
MusicShape s1 = new MusicShape(4);
s1.add(1.0, 10, 20, 30);
s1.add(1.0, 11, 20, 30);
// build another one
MusicShape s2 = new MusicShape(4);
s2.add(0.5, 100, 20, 30);
s2.add(0.5, 101, 20, 30);
s2.add(0.5, 102, 20, 30);
s2.add(0.5, 103, 20, 30);
// Build a Player and add these two MusicShapes
Player p = new Player();
p.add(s1);
p.add(s2);
p.setRepeats(10);
// Plug in a Playable that prints a message every time the Player repeats
p.addRepeatPlayable(new MessagePrinter("repeats"));
// Use default behavior: choose a new child randomly every repeat
p.setBehavior(new UniformRandomBehavior());
// go!
p.launch(JMSL.now());
}
Note that a given MusicShape can be added to more than one Player. Each Player's Instrument may interpret the MusicShape independently.
You can set up a Player with custom Instruments and Interpreters three ways:
- Use the constructor public Player(Instrument) which automatically plugs in the specified Instrument
- Use a default instrument initially with the constructor public Player() and then call setInstrument(Instrument)
- Use a default instrument with the constructor public Player() and then call getInstrument().setInterpreter(Interpreter)
-
Field Summary
Fields inherited from class com.softsynth.jmsl.MusicJob
repeatCount -
Constructor Summary
Constructors Constructor Description Player()Construct a Player with a default Instrument.Player(Instrument ins)Construct a Player with an instrument to use to play all its children -
Method Summary
Modifier and Type Method Description doubleinternalRepeat(double playTime)Every repeat, either choose next MusicShape if acting sequentially or choose one using Behaviorstatic voidmain(java.lang.String[] args)Stick two MusicShapes into two Players and play the Players, printing output.doublestart(double startTime)open() Instrument and return startTimedoublestop(double stopTime)close() Instrument and return stopTimeMethods inherited from class com.softsynth.jmsl.SequentialCollection
getBehavior, print, setBehaviorMethods inherited from class com.softsynth.jmsl.ParallelCollection
get, halt, printHierarchy, setMethods 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, timeStretch, transposition, waitForDoneMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Player
Construct a Player with an instrument to use to play all its children -
Player
public Player()Construct a Player with a default Instrument. Can setInstrument() later
-
-
Method Details
-
start
public double start(double startTime) throws java.lang.InterruptedExceptionopen() Instrument and return startTime- Specified by:
startin interfaceComposable- Overrides:
startin classMusicJob- Returns:
- endTime
- Throws:
java.lang.InterruptedException- thrown if Thread.interrupt() called.
-
stop
public double stop(double stopTime) throws java.lang.InterruptedExceptionclose() Instrument and return stopTime- Specified by:
stopin interfaceComposable- Overrides:
stopin classMusicJob- Returns:
- endTime
- Throws:
java.lang.InterruptedException- thrown if Thread.interrupt() called.
-
internalRepeat
public double internalRepeat(double playTime) throws java.lang.InterruptedExceptionEvery repeat, either choose next MusicShape if acting sequentially or choose one using Behavior- Specified by:
internalRepeatin interfaceComposable- Overrides:
internalRepeatin classSequentialCollection- Returns:
- time of completion
- Throws:
java.lang.InterruptedException- if the thread running this Composable is interrupted
-
main
public static void main(java.lang.String[] args)Stick two MusicShapes into two Players and play the Players, printing output. Same MusicShapes interpreted differently.
-