javax.sound.midi
Class Sequence

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.sound.midi.Sequence

public class Sequence
extends Object sample code for java.lang.Object definition code for java.lang.Object

A Sequence is a data structure containing musical information (often an entire song or composition) that can be played back by a Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer object. Specifically, the Sequence contains timing information and one or more tracks. Each track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track consists of a series of MIDI events (such as note-ons, note-offs, program changes, and meta-events). The sequence's timing information specifies the type of unit that is used to time-stamp the events in the sequence.

A Sequence can be created from a MIDI file by reading the file into an input stream and invoking one of the getSequence methods of MidiSystem sample code for javax.sound.midi.MidiSystem definition code for javax.sound.midi.MidiSystem . A sequence can also be built from scratch by adding new Tracks to an empty Sequence, and adding MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent objects to these Tracks.

See Also:
Sequencer.setSequence(java.io.InputStream stream) sample code for javax.sound.midi.Sequencer.setSequence(java.io.InputStream) definition code for javax.sound.midi.Sequencer.setSequence(java.io.InputStream) , Sequencer.setSequence(Sequence sequence) sample code for javax.sound.midi.Sequencer.setSequence(javax.sound.midi.Sequence) definition code for javax.sound.midi.Sequencer.setSequence(javax.sound.midi.Sequence) , Track.add(MidiEvent) sample code for javax.sound.midi.Track.add(javax.sound.midi.MidiEvent) definition code for javax.sound.midi.Track.add(javax.sound.midi.MidiEvent) , MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat

Field Summary
protected  float divisionType sample code for javax.sound.midi.Sequence.divisionType definition code for javax.sound.midi.Sequence.divisionType
          The timing division type of the sequence.
static float PPQ sample code for javax.sound.midi.Sequence.PPQ definition code for javax.sound.midi.Sequence.PPQ
          The tempo-based timing type, for which the resolution is expressed in pulses (ticks) per quarter note.
protected  int resolution sample code for javax.sound.midi.Sequence.resolution definition code for javax.sound.midi.Sequence.resolution
          The timing resolution of the sequence.
static float SMPTE_24 sample code for javax.sound.midi.Sequence.SMPTE_24 definition code for javax.sound.midi.Sequence.SMPTE_24
          The SMPTE-based timing type with 24 frames per second (resolution is expressed in ticks per frame).
static float SMPTE_25 sample code for javax.sound.midi.Sequence.SMPTE_25 definition code for javax.sound.midi.Sequence.SMPTE_25
          The SMPTE-based timing type with 25 frames per second (resolution is expressed in ticks per frame).
static float SMPTE_30 sample code for javax.sound.midi.Sequence.SMPTE_30 definition code for javax.sound.midi.Sequence.SMPTE_30
          The SMPTE-based timing type with 30 frames per second (resolution is expressed in ticks per frame).
static float SMPTE_30DROP sample code for javax.sound.midi.Sequence.SMPTE_30DROP definition code for javax.sound.midi.Sequence.SMPTE_30DROP
          The SMPTE-based timing type with 29.97 frames per second (resolution is expressed in ticks per frame).
protected  Vector sample code for java.util.Vector definition code for java.util.Vector <Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track > tracks sample code for javax.sound.midi.Sequence.tracks definition code for javax.sound.midi.Sequence.tracks
          The MIDI tracks in this sequence.
 
Constructor Summary
Sequence sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) (float divisionType, int resolution)
          Constructs a new MIDI sequence with the specified timing division type and timing resolution.
Sequence sample code for javax.sound.midi.Sequence.Sequence(float, int, int) definition code for javax.sound.midi.Sequence.Sequence(float, int, int) (float divisionType, int resolution, int numTracks)
          Constructs a new MIDI sequence with the specified timing division type, timing resolution, and number of tracks.
 
Method Summary
 Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track createTrack sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack() ()
          Creates a new, initially empty track as part of this sequence.
 boolean deleteTrack sample code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) definition code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) (Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track  track)
          Removes the specified track from the sequence.
 float getDivisionType sample code for javax.sound.midi.Sequence.getDivisionType() definition code for javax.sound.midi.Sequence.getDivisionType() ()
          Obtains the timing division type for this sequence.
 long getMicrosecondLength sample code for javax.sound.midi.Sequence.getMicrosecondLength() definition code for javax.sound.midi.Sequence.getMicrosecondLength() ()
          Obtains the duration of this sequence, expressed in microseconds.
 Patch sample code for javax.sound.midi.Patch definition code for javax.sound.midi.Patch [] getPatchList sample code for javax.sound.midi.Sequence.getPatchList() definition code for javax.sound.midi.Sequence.getPatchList() ()
          Obtains a list of patches referenced in this sequence.
 int getResolution sample code for javax.sound.midi.Sequence.getResolution() definition code for javax.sound.midi.Sequence.getResolution() ()
          Obtains the timing resolution for this sequence.
 long getTickLength sample code for javax.sound.midi.Sequence.getTickLength() definition code for javax.sound.midi.Sequence.getTickLength() ()
          Obtains the duration of this sequence, expressed in MIDI ticks.
 Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track [] getTracks sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks() ()
          Obtains an array containing all the tracks in this sequence.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

PPQ sample code for javax.sound.midi.Sequence.PPQ

public static final float PPQ
The tempo-based timing type, for which the resolution is expressed in pulses (ticks) per quarter note.

See Also:
Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , Constant Field Values

SMPTE_24 sample code for javax.sound.midi.Sequence.SMPTE_24

public static final float SMPTE_24
The SMPTE-based timing type with 24 frames per second (resolution is expressed in ticks per frame).

See Also:
Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , Constant Field Values

SMPTE_25 sample code for javax.sound.midi.Sequence.SMPTE_25

public static final float SMPTE_25
The SMPTE-based timing type with 25 frames per second (resolution is expressed in ticks per frame).

See Also:
Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , Constant Field Values

SMPTE_30DROP sample code for javax.sound.midi.Sequence.SMPTE_30DROP

public static final float SMPTE_30DROP
The SMPTE-based timing type with 29.97 frames per second (resolution is expressed in ticks per frame).

See Also:
Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , Constant Field Values

SMPTE_30 sample code for javax.sound.midi.Sequence.SMPTE_30

public static final float SMPTE_30
The SMPTE-based timing type with 30 frames per second (resolution is expressed in ticks per frame).

See Also:
Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , Constant Field Values

divisionType sample code for javax.sound.midi.Sequence.divisionType

protected float divisionType
The timing division type of the sequence.

See Also:
PPQ sample code for javax.sound.midi.Sequence.PPQ definition code for javax.sound.midi.Sequence.PPQ , SMPTE_24 sample code for javax.sound.midi.Sequence.SMPTE_24 definition code for javax.sound.midi.Sequence.SMPTE_24 , SMPTE_25 sample code for javax.sound.midi.Sequence.SMPTE_25 definition code for javax.sound.midi.Sequence.SMPTE_25 , SMPTE_30DROP sample code for javax.sound.midi.Sequence.SMPTE_30DROP definition code for javax.sound.midi.Sequence.SMPTE_30DROP , SMPTE_30 sample code for javax.sound.midi.Sequence.SMPTE_30 definition code for javax.sound.midi.Sequence.SMPTE_30 , getDivisionType() sample code for javax.sound.midi.Sequence.getDivisionType() definition code for javax.sound.midi.Sequence.getDivisionType()

resolution sample code for javax.sound.midi.Sequence.resolution

protected int resolution
The timing resolution of the sequence.

See Also:
getResolution() sample code for javax.sound.midi.Sequence.getResolution() definition code for javax.sound.midi.Sequence.getResolution()

tracks sample code for javax.sound.midi.Sequence.tracks

protected Vector sample code for java.util.Vector definition code for java.util.Vector <Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track > tracks
The MIDI tracks in this sequence.

See Also:
getTracks() sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks()
Constructor Detail

Sequence sample code for javax.sound.midi.Sequence(float, int) definition code for javax.sound.midi.Sequence(float, int)

public Sequence(float divisionType,
                int resolution)
         throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException 
Constructs a new MIDI sequence with the specified timing division type and timing resolution. The division type must be one of the recognized MIDI timing types. For tempo-based timing, divisionType is PPQ (pulses per quarter note) and the resolution is specified in ticks per beat. For SMTPE timing, divisionType specifies the number of frames per second and the resolution is specified in ticks per frame. The sequence will contain no initial tracks. Tracks may be added to or removed from the sequence using createTrack() sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack() and deleteTrack(javax.sound.midi.Track) sample code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) definition code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) .

Parameters:
divisionType - the timing division type (PPQ or one of the SMPTE types)
resolution - the timing resolution
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if divisionType is not valid
See Also:
PPQ sample code for javax.sound.midi.Sequence.PPQ definition code for javax.sound.midi.Sequence.PPQ , SMPTE_24 sample code for javax.sound.midi.Sequence.SMPTE_24 definition code for javax.sound.midi.Sequence.SMPTE_24 , SMPTE_25 sample code for javax.sound.midi.Sequence.SMPTE_25 definition code for javax.sound.midi.Sequence.SMPTE_25 , SMPTE_30DROP sample code for javax.sound.midi.Sequence.SMPTE_30DROP definition code for javax.sound.midi.Sequence.SMPTE_30DROP , SMPTE_30 sample code for javax.sound.midi.Sequence.SMPTE_30 definition code for javax.sound.midi.Sequence.SMPTE_30 , getDivisionType() sample code for javax.sound.midi.Sequence.getDivisionType() definition code for javax.sound.midi.Sequence.getDivisionType() , getResolution() sample code for javax.sound.midi.Sequence.getResolution() definition code for javax.sound.midi.Sequence.getResolution() , getTracks() sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks()

Sequence sample code for javax.sound.midi.Sequence(float, int, int) definition code for javax.sound.midi.Sequence(float, int, int)

public Sequence(float divisionType,
                int resolution,
                int numTracks)
         throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException 
Constructs a new MIDI sequence with the specified timing division type, timing resolution, and number of tracks. The division type must be one of the recognized MIDI timing types. For tempo-based timing, divisionType is PPQ (pulses per quarter note) and the resolution is specified in ticks per beat. For SMTPE timing, divisionType specifies the number of frames per second and the resolution is specified in ticks per frame. The sequence will be initialized with the number of tracks specified by numTracks. These tracks are initially empty (i.e. they contain only the meta-event End of Track). The tracks may be retrieved for editing using the getTracks() sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks() method. Additional tracks may be added, or existing tracks removed, using createTrack() sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack() and deleteTrack(javax.sound.midi.Track) sample code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) definition code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) .

Parameters:
divisionType - the timing division type (PPQ or one of the SMPTE types)
resolution - the timing resolution
numTracks - the initial number of tracks in the sequence.
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if divisionType is not valid
See Also:
PPQ sample code for javax.sound.midi.Sequence.PPQ definition code for javax.sound.midi.Sequence.PPQ , SMPTE_24 sample code for javax.sound.midi.Sequence.SMPTE_24 definition code for javax.sound.midi.Sequence.SMPTE_24 , SMPTE_25 sample code for javax.sound.midi.Sequence.SMPTE_25 definition code for javax.sound.midi.Sequence.SMPTE_25 , SMPTE_30DROP sample code for javax.sound.midi.Sequence.SMPTE_30DROP definition code for javax.sound.midi.Sequence.SMPTE_30DROP , SMPTE_30 sample code for javax.sound.midi.Sequence.SMPTE_30 definition code for javax.sound.midi.Sequence.SMPTE_30 , getDivisionType() sample code for javax.sound.midi.Sequence.getDivisionType() definition code for javax.sound.midi.Sequence.getDivisionType() , getResolution() sample code for javax.sound.midi.Sequence.getResolution() definition code for javax.sound.midi.Sequence.getResolution()
Method Detail

getDivisionType sample code for javax.sound.midi.Sequence.getDivisionType() definition code for javax.sound.midi.Sequence.getDivisionType()

public float getDivisionType()
Obtains the timing division type for this sequence.

Returns:
the division type (PPQ or one of the SMPTE types)
See Also:
PPQ sample code for javax.sound.midi.Sequence.PPQ definition code for javax.sound.midi.Sequence.PPQ , SMPTE_24 sample code for javax.sound.midi.Sequence.SMPTE_24 definition code for javax.sound.midi.Sequence.SMPTE_24 , SMPTE_25 sample code for javax.sound.midi.Sequence.SMPTE_25 definition code for javax.sound.midi.Sequence.SMPTE_25 , SMPTE_30DROP sample code for javax.sound.midi.Sequence.SMPTE_30DROP definition code for javax.sound.midi.Sequence.SMPTE_30DROP , SMPTE_30 sample code for javax.sound.midi.Sequence.SMPTE_30 definition code for javax.sound.midi.Sequence.SMPTE_30 , Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , MidiFileFormat.getDivisionType() sample code for javax.sound.midi.MidiFileFormat.getDivisionType() definition code for javax.sound.midi.MidiFileFormat.getDivisionType()

getResolution sample code for javax.sound.midi.Sequence.getResolution() definition code for javax.sound.midi.Sequence.getResolution()

public int getResolution()
Obtains the timing resolution for this sequence. If the sequence's division type is PPQ, the resolution is specified in ticks per beat. For SMTPE timing, the resolution is specified in ticks per frame.

Returns:
the number of ticks per beat (PPQ) or per frame (SMPTE)
See Also:
getDivisionType() sample code for javax.sound.midi.Sequence.getDivisionType() definition code for javax.sound.midi.Sequence.getDivisionType() , Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , MidiFileFormat.getResolution() sample code for javax.sound.midi.MidiFileFormat.getResolution() definition code for javax.sound.midi.MidiFileFormat.getResolution()

createTrack sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack()

public Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track  createTrack()
Creates a new, initially empty track as part of this sequence. The track initially contains the meta-event End of Track. The newly created track is returned. All tracks in the sequence may be retrieved using getTracks() sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks() . Tracks may be removed from the sequence using deleteTrack(javax.sound.midi.Track) sample code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) definition code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) .

Returns:
the newly created track

deleteTrack sample code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) definition code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track)

public boolean deleteTrack(Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track  track)
Removes the specified track from the sequence.

Parameters:
track - the track to remove
Returns:
true if the track existed in the track and was removed, otherwise false.
See Also:
createTrack() sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack() , getTracks() sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks()

getTracks sample code for javax.sound.midi.Sequence.getTracks() definition code for javax.sound.midi.Sequence.getTracks()

public Track sample code for javax.sound.midi.Track definition code for javax.sound.midi.Track [] getTracks()
Obtains an array containing all the tracks in this sequence. If the sequence contains no tracks, an array of length 0 is returned.

Returns:
the array of tracks
See Also:
createTrack() sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack() , deleteTrack(javax.sound.midi.Track) sample code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track) definition code for javax.sound.midi.Sequence.deleteTrack(javax.sound.midi.Track)

getMicrosecondLength sample code for javax.sound.midi.Sequence.getMicrosecondLength() definition code for javax.sound.midi.Sequence.getMicrosecondLength()

public long getMicrosecondLength()
Obtains the duration of this sequence, expressed in microseconds.

Returns:
this sequence's duration in microseconds.

getTickLength sample code for javax.sound.midi.Sequence.getTickLength() definition code for javax.sound.midi.Sequence.getTickLength()

public long getTickLength()
Obtains the duration of this sequence, expressed in MIDI ticks.

Returns:
this sequence's length in ticks
See Also:
getMicrosecondLength() sample code for javax.sound.midi.Sequence.getMicrosecondLength() definition code for javax.sound.midi.Sequence.getMicrosecondLength()

getPatchList sample code for javax.sound.midi.Sequence.getPatchList() definition code for javax.sound.midi.Sequence.getPatchList()

public Patch sample code for javax.sound.midi.Patch definition code for javax.sound.midi.Patch [] getPatchList()
Obtains a list of patches referenced in this sequence. This patch list may be used to load the required Instrument sample code for javax.sound.midi.Instrument definition code for javax.sound.midi.Instrument objects into a Synthesizer sample code for javax.sound.midi.Synthesizer definition code for javax.sound.midi.Synthesizer .

Returns:
an array of Patch sample code for javax.sound.midi.Patch definition code for javax.sound.midi.Patch objects used in this sequence
See Also:
Synthesizer.loadInstruments(Soundbank, Patch[]) sample code for javax.sound.midi.Synthesizer.loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[]) definition code for javax.sound.midi.Synthesizer.loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])