Class 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.
  • Constructor Details

    • 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 Details

    • 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.