provided.player
Class SequencePlayer

java.lang.Object
  extended by provided.player.SequencePlayer

public class SequencePlayer
extends java.lang.Object

Sequence Player to create and play MIDI music sequences.


Field Summary
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  javax.sound.midi.Sequencer _sequencer
          MIDI sequencer object
private  javax.sound.midi.Synthesizer _synthesizer
          MIDI synthesizer object
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 Summary
SequencePlayer(int ticksPerQuarterNote, int instrument)
          Create a new SequencePlayer to create and play music.
 
Method Summary
 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.
 void play()
          Play the created 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
 void stop()
          Stop playing music and close resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

END_OF_TRACK

public static final int END_OF_TRACK
End of track marker

See Also:
Constant Field Values

_sequence

private javax.sound.midi.Sequence _sequence
Music sequence


_track

private javax.sound.midi.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


_sequencer

private javax.sound.midi.Sequencer _sequencer
MIDI sequencer object


_synthesizer

private javax.sound.midi.Synthesizer _synthesizer
MIDI synthesizer object


_offsets

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

Constructor Detail

SequencePlayer

public SequencePlayer(int ticksPerQuarterNote,
                      int instrument)
Create a new SequencePlayer to create and play music.

Parameters:
ticksPerQuarterNote - - tick definition
instrument - - MIDI instrument
Method Detail

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

addNote

public int addNote(Note note,
                   int start)
Add a note to the MIDI sequence with a default velocity of 64 for middle volume

Parameters:
note - - the note to schedule in the sequence
start - - the tick at which this note should start playing
Returns:
- the tick at which this note stops playing

addNote

public int addNote(Note note,
                   int start,
                   int velocity)
Add a note to the MIDI sequence.

Parameters:
note - - the note to schedule in the sequence
start - - the tick at which this note should start playing
velocity - - the volume (0-127)
Returns:
- the tick at which this note stops playing

play

public void play()
Play the created Sequence.


stop

public void stop()
Stop playing music and close resources.


getTicksPerDefaultNote

public int getTicksPerDefaultNote()
Accessor to get the current ticks per default note

Returns:
the _ticksPerDefaultNote

setTicksPerDefaultNote

public void setTicksPerDefaultNote(int ticksPerDefaultNote)
Accessor to set the current ticks per default note

Parameters:
ticksPerDefaultNote - the _ticksPerDefaultNote to set

getTempo

public int getTempo()
Accessor for the current tempo

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.

Parameters:
bpm - - beats per minute

getTicksPerQuarterNote

public int getTicksPerQuarterNote()
Accessor for the current number of ticks per quarter note.

Returns:
the number of ticks per quarter note