FileDocCategorySizeDatePackage
Sequence.javaAPI DocJava SE 5 API10234Fri Aug 26 14:57:50 BST 2005javax.sound.midi

Sequence

public class Sequence extends Object
A Sequence is a data structure containing musical information (often an entire song or composition) that can be played back by a {@link Sequencer} object. Specifically, the Sequence contains timing information and one or more tracks. Each {@link Track 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 {@link MidiSystem}. A sequence can also be built from scratch by adding new Tracks to an empty Sequence, and adding {@link MidiEvent} objects to these Tracks.

see
Sequencer#setSequence(java.io.InputStream stream)
see
Sequencer#setSequence(Sequence sequence)
see
Track#add(MidiEvent)
see
MidiFileFormat
version
1.27, 04/05/05
author
Kara Kytle

Fields Summary
public static final float
PPQ
The tempo-based timing type, for which the resolution is expressed in pulses (ticks) per quarter note.
public static final float
SMPTE_24
The SMPTE-based timing type with 24 frames per second (resolution is expressed in ticks per frame).
public static final float
SMPTE_25
The SMPTE-based timing type with 25 frames per second (resolution is expressed in ticks per frame).
public static final float
SMPTE_30DROP
The SMPTE-based timing type with 29.97 frames per second (resolution is expressed in ticks per frame).
public static final float
SMPTE_30
The SMPTE-based timing type with 30 frames per second (resolution is expressed in ticks per frame).
protected float
divisionType
The timing division type of the sequence.
protected int
resolution
The timing resolution of the sequence.
protected Vector
tracks
The MIDI tracks in this sequence.
Constructors Summary
public Sequence(float divisionType, int resolution)
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 {@link #createTrack} and {@link #deleteTrack}.

param
divisionType the timing division type (PPQ or one of the SMPTE types)
param
resolution the timing resolution
throws
InvalidMidiDataException if divisionType is not valid
see
#PPQ
see
#SMPTE_24
see
#SMPTE_25
see
#SMPTE_30DROP
see
#SMPTE_30
see
#getDivisionType
see
#getResolution
see
#getTracks



                                                                                                                                              
           

	if (divisionType == PPQ)
	    this.divisionType = PPQ;
	else if (divisionType == SMPTE_24)
	    this.divisionType = SMPTE_24;
	else if (divisionType == SMPTE_25)
	    this.divisionType = SMPTE_25;
	else if (divisionType == SMPTE_30DROP)
	    this.divisionType = SMPTE_30DROP;
	else if (divisionType == SMPTE_30)
	    this.divisionType = SMPTE_30;
	else throw new InvalidMidiDataException("Unsupported division type: " + divisionType);

	this.resolution = resolution;
    
public Sequence(float divisionType, int resolution, int numTracks)
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 {@link #getTracks} method. Additional tracks may be added, or existing tracks removed, using {@link #createTrack} and {@link #deleteTrack}.

param
divisionType the timing division type (PPQ or one of the SMPTE types)
param
resolution the timing resolution
param
numTracks the initial number of tracks in the sequence.
throws
InvalidMidiDataException if divisionType is not valid
see
#PPQ
see
#SMPTE_24
see
#SMPTE_25
see
#SMPTE_30DROP
see
#SMPTE_30
see
#getDivisionType
see
#getResolution


	if (divisionType == PPQ)
	    this.divisionType = PPQ;
	else if (divisionType == SMPTE_24)
	    this.divisionType = SMPTE_24;
	else if (divisionType == SMPTE_25)
	    this.divisionType = SMPTE_25;
	else if (divisionType == SMPTE_30DROP)
	    this.divisionType = SMPTE_30DROP;
	else if (divisionType == SMPTE_30)
	    this.divisionType = SMPTE_30;
	else throw new InvalidMidiDataException("Unsupported division type: " + divisionType);

	this.resolution = resolution;

	for (int i = 0; i < numTracks; i++) {
	    tracks.addElement(new Track());
	}
    
Methods Summary
public javax.sound.midi.TrackcreateTrack()
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 {@link #getTracks}. Tracks may be removed from the sequence using {@link #deleteTrack}.

return
the newly created track


	Track track = new Track();
	tracks.addElement(track);

	return track;
    
public booleandeleteTrack(javax.sound.midi.Track track)
Removes the specified track from the sequence.

param
track the track to remove
return
true if the track existed in the track and was removed, otherwise false.
see
#createTrack
see
#getTracks


	synchronized(tracks) {

	    return tracks.removeElement(track);
	}
    
public floatgetDivisionType()
Obtains the timing division type for this sequence.

return
the division type (PPQ or one of the SMPTE types)
see
#PPQ
see
#SMPTE_24
see
#SMPTE_25
see
#SMPTE_30DROP
see
#SMPTE_30
see
#Sequence(float, int)
see
MidiFileFormat#getDivisionType()

	return divisionType;
    
public longgetMicrosecondLength()
Obtains the duration of this sequence, expressed in microseconds.

return
this sequence's duration in microseconds.


    	return com.sun.media.sound.MidiUtils.tick2microsecond(this, getTickLength(), null);
    
public javax.sound.midi.Patch[]getPatchList()
Obtains a list of patches referenced in this sequence. This patch list may be used to load the required {@link Instrument} objects into a {@link Synthesizer}.

return
an array of {@link Patch} objects used in this sequence
see
Synthesizer#loadInstruments(Soundbank, Patch[])


	// $$kk: 04.09.99: need to implement!!
	return new Patch[0];
    
public intgetResolution()
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.

return
the number of ticks per beat (PPQ) or per frame (SMPTE)
see
#getDivisionType
see
#Sequence(float, int)
see
MidiFileFormat#getResolution()

	return resolution;
    
public longgetTickLength()
Obtains the duration of this sequence, expressed in MIDI ticks.

return
this sequence's length in ticks
see
#getMicrosecondLength


	long length = 0;

	synchronized(tracks) {

	    for(int i=0; i<tracks.size(); i++ ) {
		long temp = ((Track)tracks.elementAt(i)).ticks();
		if( temp>length ) {
		    length = temp;
		}
	    }
	    return length;
	}
    
public 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.

return
the array of tracks
see
#createTrack
see
#deleteTrack


	return (Track[]) tracks.toArray(new Track[tracks.size()]);