com.softsynth.jmsl
Class Player

java.lang.Object
  extended by com.softsynth.jmsl.MusicJob
      extended by com.softsynth.jmsl.ParallelCollection
          extended by com.softsynth.jmsl.SequentialCollection
              extended by 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:

 // 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:
  1. Use the constructor public Player(Instrument) which automatically plugs in the specified Instrument
  2. Use a default instrument initially with the constructor public Player() and then call setInstrument(Instrument)
  3. Use a default instrument with the constructor public Player() and then call getInstrument().setInterpreter(Interpreter)
Any PlayLurkers registered with the MusicShapes will be notified. If the Instrument has a DimensionNameSpace, Player will use a DimensionNameSpacetranslator to translate the double[] from the MusicShape before it hands it to the Instrument.


Field Summary
 
Fields inherited from class com.softsynth.jmsl.MusicJob
repeatCount
 
Constructor Summary
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
 double internalRepeat(double playTime)
          Every repeat, either choose next MusicShape if acting sequentially or choose one using Behavior
static 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 startTime
 double stop(double stopTime)
          close() Instrument and return stopTime
 
Methods 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, 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, timeStretch, transposition, waitForDone
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Player

public Player(Instrument ins)
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 Detail

start

public double start(double startTime)
             throws java.lang.InterruptedException
open() Instrument and return startTime

Specified by:
start in interface Composable
Overrides:
start in class MusicJob
Returns:
endTime
Throws:
java.lang.InterruptedException - thrown if Thread.interrupt() called.

stop

public double stop(double stopTime)
            throws java.lang.InterruptedException
close() Instrument and return stopTime

Specified by:
stop in interface Composable
Overrides:
stop in class MusicJob
Returns:
endTime
Throws:
java.lang.InterruptedException - thrown if Thread.interrupt() called.

internalRepeat

public double internalRepeat(double playTime)
                      throws java.lang.InterruptedException
Every repeat, either choose next MusicShape if acting sequentially or choose one using Behavior

Specified by:
internalRepeat in interface Composable
Overrides:
internalRepeat in class SequentialCollection
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.