player
Class SequencePlayer

java.lang.Object
  extended by 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 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
private  javax.sound.midi.Sequencer sequencer
           
private  javax.sound.midi.Synthesizer synthesizer
           
 
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.
 java.lang.String getInstruments()
          Get a string containing all of the instruments supported by the SequencePlayer.
 int getTempo()
           
 int getTicksPerDefaultNote()
           
 int getTicksPerQuarterNote()
           
 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)
           
 void stop()
           
 
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


_offsets

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


sequencer

private javax.sound.midi.Sequencer sequencer

synthesizer

private javax.sound.midi.Synthesizer synthesizer
Constructor Detail

SequencePlayer

public SequencePlayer(int ticksPerQuarterNote,
                      int instrument)
               throws javax.sound.midi.InvalidMidiDataException,
                      javax.sound.midi.MidiUnavailableException
Create a new SequencePlayer to create and play music.

Parameters:
ticksPerQuarterNote - - tick definition
instrument - - MIDI instrument
Throws:
javax.sound.midi.InvalidMidiDataException - - thrown if MIDI isn't working
javax.sound.midi.MidiUnavailableException
Method Detail

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

getInstruments

public java.lang.String getInstruments()
Get a string containing all of the instruments supported by the SequencePlayer.

Returns:
a string of "number: name" mappings of instruments, one per line

play

public void play()
Play the created Sequence.


stop

public void stop()

getTicksPerDefaultNote

public int getTicksPerDefaultNote()
Returns:
the _ticksPerDefaultNote

setTicksPerDefaultNote

public void setTicksPerDefaultNote(int ticksPerDefaultNote)
Parameters:
ticksPerDefaultNote - the _ticksPerDefaultNote to set

getTempo

public int getTempo()
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()
Returns:
the number of ticks per quarter note