public class SequencePlayer2
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
SequencePlayer2.IPlayable
Interface that represents a playable entity.
|
Modifier and Type | Field and Description |
---|---|
private int |
_bpm
Tempo (beats per minute)
|
private int |
_instrument
MIDI Instrument
|
private static int[] |
_offsets
Half note steps from C in an octave
|
private javax.sound.midi.Sequence |
_sequence
Music sequence
|
private int |
_ticksPerDefaultNote
Default note duration
|
private int |
_ticksPerQuarterNote
Definition of a tick
|
private javax.sound.midi.Track |
_track
Track within music sequence
|
static int |
END_OF_TRACK
End of track marker
|
Constructor and Description |
---|
SequencePlayer2(int ticksPerQuarterNote,
int instrument)
Create a new SequencePlayer to create and play music.
|
Modifier and Type | Method and Description |
---|---|
int |
addNote(Note note,
int start)
Add a note to the MIDI sequence with a default velocity of 64 for middle volume
|
int |
addNote(Note note,
int start,
int velocity)
Add a note to the MIDI sequence.
|
int |
getTempo()
Accessor for the current tempo
|
int |
getTicksPerDefaultNote()
Accessor to get the current ticks per default note
|
int |
getTicksPerQuarterNote()
Accessor for the current number of ticks per quarter note.
|
boolean |
init(int ticksPerQuarterNote,
int instrument)
Initialize the SequencePlayer as per the supplied ticksPerQuarterNote and instrument
this SequencePlayer was instantiated with.
|
SequencePlayer2.IPlayable |
makePlayable(ISequencePlayerStatus statusCmd)
Factory method for an IPlayable object that can play the currently programmed music sequence.
|
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
|
public static final int END_OF_TRACK
private javax.sound.midi.Sequence _sequence
private javax.sound.midi.Track _track
private int _bpm
private int _ticksPerDefaultNote
private int _ticksPerQuarterNote
private int _instrument
private static final int[] _offsets
public SequencePlayer2(int ticksPerQuarterNote, int instrument)
ticksPerQuarterNote
- - tick definitioninstrument
- - MIDI instrumentpublic boolean init(int ticksPerQuarterNote, int instrument)
ticksPerQuarterNote
- - tick definitioninstrument
- - MIDI instrumentpublic int addNote(Note note, int start)
note
- - the note to schedule in the sequencestart
- - the tick at which this note should start playingpublic int addNote(Note note, int start, int velocity)
note
- - the note to schedule in the sequencestart
- - the tick at which this note should start playingvelocity
- - the volume (0-127)public SequencePlayer2.IPlayable makePlayable(ISequencePlayerStatus statusCmd)
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.public int getTicksPerDefaultNote()
public void setTicksPerDefaultNote(int ticksPerDefaultNote)
ticksPerDefaultNote
- the _ticksPerDefaultNote to setpublic int getTempo()
public void setTempo(int bpm)
bpm
- - beats per minutepublic int getTicksPerQuarterNote()