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 double
internalRepeat(double playTime)
Every repeat, either choose next MusicShape if acting sequentially or choose one using Behaviorstatic void
main(java.lang.String[] args)
Stick two MusicShapes into two Players and play the Players, printing output.double
start(double startTime)
open() Instrument and return startTimedouble
stop(double stopTime)
close() Instrument and return stopTimeMethods inherited from class com.softsynth.jmsl.SequentialCollection
getBehavior, print, setBehavior
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, timeStretch, transposition, waitForDone
Methods 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:
start
in interfaceComposable
- Overrides:
start
in 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:
stop
in interfaceComposable
- Overrides:
stop
in 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:
internalRepeat
in interfaceComposable
- Overrides:
internalRepeat
in 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.
-