java.lang.Object
provided.abcMusic.player.impl.ASequencePlayer
provided.abcMusic.player.impl.SequencePlayer2
- All Implemented Interfaces:
ISequencePlayer
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface that represents a playable entity. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ArrayList<SequencePlayer2.IPlayable>
The queue of of currently playing songsstatic int
End of track markerFields inherited from class provided.abcMusic.player.impl.ASequencePlayer
logger
-
Constructor Summary
ConstructorsConstructorDescriptionSequencePlayer2(int ticksPerQuarterNote, int instrument)
Create a new SequencePlayer to create and play music. -
Method Summary
Modifier and TypeMethodDescriptionboolean
init(int ticksPerQuarterNote, int instrument)
Initialize the SequencePlayer as per the supplied ticksPerQuarterNote and instrument this SequencePlayer was instantiated with.makePlayable(ISequencePlayerStatus statusCmd)
Factory method for an IPlayable object that can play the currently programmed music sequence.void
play(ISequencePlayerStatus statusCmd)
Plays the currently loaded song and adds it to the internal queue of IPlayablesvoid
stop()
Stop the first playable in the internal queue if there is any.Methods inherited from class provided.abcMusic.player.impl.ASequencePlayer
addNote, addNote, getSequence, getTempo, getTicksPerDefaultNote, getTicksPerQuarterNote, initBase, initTrack, setTempo, setTicksPerDefaultNote
-
Field Details
-
END_OF_TRACK
public static final int END_OF_TRACKEnd of track marker- See Also:
- Constant Field Values
-
_playableQueue
The queue of of currently playing songs
-
-
Constructor Details
-
SequencePlayer2
public SequencePlayer2(int ticksPerQuarterNote, int instrument)Create a new SequencePlayer to create and play music.- Parameters:
ticksPerQuarterNote
- - tick definitioninstrument
- - 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 definitioninstrument
- - MIDI instrument- Returns:
- - true if properly initialized, false otherwise
-
makePlayable
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
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.
-