Module hw06

Class SequencePlayer2

java.lang.Object
provided.abcMusic.player.impl.ASequencePlayer
provided.abcMusic.player.impl.SequencePlayer2
All Implemented Interfaces:
ISequencePlayer

public class SequencePlayer2 extends ASequencePlayer
An advanced sequence player to create and play MIDI music sequences. Differs from SequencePlayer in that this class has a factory method that creates an SequencePlayer2.IPlayable object that can be individually and asynchronously started and stopped. This enables more control over the playing process, including managing multiple, simultaneously playing songs. The play() and stop() methods are overridden to automatically create IPlayables and hold them in an internal queue.
  • Field Details

  • Constructor Details

    • SequencePlayer2

      public SequencePlayer2(int ticksPerQuarterNote, int instrument)
      Create a new SequencePlayer to create and play music.
      Parameters:
      ticksPerQuarterNote - - tick definition
      instrument - - MIDI instrument
  • Method Details

    • init

      public boolean init(int ticksPerQuarterNote, int instrument)
      Initialize the SequencePlayer as per the supplied ticksPerQuarterNote and instrument this SequencePlayer was instantiated with. This method is called by the constructor to initialize the player upon instantiation and can be called again to reinitialize the SequencePlayer.
      Parameters:
      ticksPerQuarterNote - - tick definition
      instrument - - MIDI instrument
      Returns:
      - true if properly initialized, false otherwise
    • makePlayable

      public SequencePlayer2.IPlayable makePlayable(ISequencePlayerStatus statusCmd)
      Factory method for an IPlayable object that can play the currently programmed music sequence.
      Parameters:
      statusCmd - The finished() method of this command is called when the track finishes being played, i.e. a normal termination. There is no notification if play is forcibly stopped.
      Returns:
      An IPlayable object associated with the currently programmed music sequence.
    • play

      public void play(ISequencePlayerStatus statusCmd)
      Plays the currently loaded song and adds it to the internal queue of IPlayables
      Parameters:
      statusCmd - The command to run when the currently song finishes playing.
    • stop

      public void stop()
      Stop the first playable in the internal queue if there is any.