Module hw06

Class ASequencePlayer

java.lang.Object
provided.abcMusic.player.impl.ASequencePlayer
All Implemented Interfaces:
ISequencePlayer
Direct Known Subclasses:
SequencePlayer, SequencePlayer2

public abstract class ASequencePlayer extends Object implements ISequencePlayer
Common aspects of all sequence player implementations.
Author:
swong
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Tempo (beats per minute)
    private int
    MIDI Instrument
    private static int[]
    Half note steps from C in an octave
    private Sequence
    Music sequence
    private int
    Default note duration
    private int
    Definition of a tick
    private Track
    Track within music sequence
    protected ILogger
    Logger for this and subclasses to use
    private static int
    The offset of the ticks from zero to reduce the "repeated first note" problem.

    Fields inherited from interface provided.abcMusic.player.ISequencePlayer

    END_OF_TRACK
  • Constructor Summary

    Constructors
    Constructor
    Description
    ASequencePlayer​(int ticksPerQuarterNote, int instrument)
    Create a new abstract SequencePlayer to create and play music.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    addNote​(Note note, int startTick)
    Add a note to the MIDI sequence with a default velocity of 64 for middle volume
    int
    addNote​(Note note, int startTick, int velocity)
    Add a note to the MIDI sequence.
    protected Sequence
    Internal accessor for the Sequence object
    int
    Accessor for the current tempo
    int
    Accessor to get the current ticks per default note
    int
    Accessor for the current number of ticks per quarter note.
    protected void
    initBase​(int ticksPerQuarterNote, int instrument)
    Base initialization that sets the internal ticks per quarter note and instrument.
    protected boolean
    Initial the internal Sequence and Track.
    void
    setTempo​(int bpm)
    Set the tempo - can't change the tempo in the middle of a sequence, the last tempo set will be used for the whole sequence.
    void
    setTicksPerDefaultNote​(int ticksPerDefaultNote)
    Accessor to set the current ticks per default note

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface provided.abcMusic.player.ISequencePlayer

    init, play, stop
  • Field Details

    • logger

      protected ILogger logger
      Logger for this and subclasses to use
    • TICK_OFFSET

      private static final int TICK_OFFSET
      The offset of the ticks from zero to reduce the "repeated first note" problem.
      See Also:
      Constant Field Values
    • _offsets

      private static final int[] _offsets
      Half note steps from C in an octave
    • _track

      private Track _track
      Track within music sequence
    • _bpm

      private int _bpm
      Tempo (beats per minute)
    • _ticksPerDefaultNote

      private int _ticksPerDefaultNote
      Default note duration
    • _ticksPerQuarterNote

      private int _ticksPerQuarterNote
      Definition of a tick
    • _instrument

      private int _instrument
      MIDI Instrument
    • _sequence

      private Sequence _sequence
      Music sequence
  • Constructor Details

    • ASequencePlayer

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

    • initBase

      protected void initBase(int ticksPerQuarterNote, int instrument)
      Base initialization that sets the internal ticks per quarter note and instrument. Also zeroes out the beaths per minute, sets the internal ticks per default note to the ticks per quarter note and sets the internal MIDI track to null.
      Parameters:
      ticksPerQuarterNote - - tick definition
      instrument - - MIDI instrument
    • initTrack

      protected boolean initTrack()
      Initial the internal Sequence and Track.
      Returns:
      True if successful, false otherwise.
    • addNote

      public int addNote(Note note, int startTick)
      Add a note to the MIDI sequence with a default velocity of 64 for middle volume
      Specified by:
      addNote in interface ISequencePlayer
      Parameters:
      note - - the note to schedule in the sequence
      startTick - - the tick at which this note should start playing
      Returns:
      - the tick at which this note stops playing
    • getTicksPerDefaultNote

      public int getTicksPerDefaultNote()
      Accessor to get the current ticks per default note
      Specified by:
      getTicksPerDefaultNote in interface ISequencePlayer
      Returns:
      the _ticksPerDefaultNote
    • setTicksPerDefaultNote

      public void setTicksPerDefaultNote(int ticksPerDefaultNote)
      Accessor to set the current ticks per default note
      Specified by:
      setTicksPerDefaultNote in interface ISequencePlayer
      Parameters:
      ticksPerDefaultNote - the _ticksPerDefaultNote to set
    • getTempo

      public int getTempo()
      Accessor for the current tempo
      Specified by:
      getTempo in interface ISequencePlayer
      Returns:
      the tempo (in beats per minute)
    • setTempo

      public void setTempo(int bpm)
      Set the tempo - can't change the tempo in the middle of a sequence, the last tempo set will be used for the whole sequence.
      Specified by:
      setTempo in interface ISequencePlayer
      Parameters:
      bpm - - beats per minute
    • getTicksPerQuarterNote

      public int getTicksPerQuarterNote()
      Accessor for the current number of ticks per quarter note.
      Specified by:
      getTicksPerQuarterNote in interface ISequencePlayer
      Returns:
      the number of ticks per quarter note
    • getSequence

      protected Sequence getSequence()
      Internal accessor for the Sequence object
      Returns:
      The internal Sequence object
    • addNote

      public int addNote(Note note, int startTick, int velocity)
      Add a note to the MIDI sequence.
      Specified by:
      addNote in interface ISequencePlayer
      Parameters:
      note - - the note to schedule in the sequence
      startTick - - the tick at which this note should start playing
      velocity - - the volume (0-127)
      Returns:
      - the tick at which this note stops playing