javax.sound.midi
Class Track

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

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

A MIDI track is an independent stream of MIDI events (time-stamped MIDI data) that can be stored along with other tracks in a standard MIDI file. The MIDI specification allows only 16 channels of MIDI data, but tracks are a way to get around this limitation. A MIDI file can contain any number of tracks, each containing its own stream of up to 16 channels of MIDI data.

A Track occupies a middle level in the hierarchy of data played by a Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer : sequencers play sequences, which contain tracks, which contain MIDI events. A sequencer may provide controls that mute or solo individual tracks.

The timing information and resolution for a track is controlled by and stored in the sequence containing the track. A given Track is considered to belong to the particular Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence that maintains its timing. For this reason, a new (empty) track is created by calling the Sequence.createTrack() sample code for javax.sound.midi.Sequence.createTrack() definition code for javax.sound.midi.Sequence.createTrack() method, rather than by directly invoking a Track constructor.

The Track class provides methods to edit the track by adding or removing MidiEvent objects from it. These operations keep the event list in the correct time order. Methods are also included to obtain the track's size, in terms of either the number of events it contains or its duration in ticks.

See Also:
Sequencer.setTrackMute(int, boolean) sample code for javax.sound.midi.Sequencer.setTrackMute(int, boolean) definition code for javax.sound.midi.Sequencer.setTrackMute(int, boolean) , Sequencer.setTrackSolo(int, boolean) sample code for javax.sound.midi.Sequencer.setTrackSolo(int, boolean) definition code for javax.sound.midi.Sequencer.setTrackSolo(int, boolean)

Method Summary
 boolean add sample code for javax.sound.midi.Track.add(javax.sound.midi.MidiEvent) definition code for javax.sound.midi.Track.add(javax.sound.midi.MidiEvent) (MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent  event)
          Adds a new event to the track.
 MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent get sample code for javax.sound.midi.Track.get(int) definition code for javax.sound.midi.Track.get(int) (int index)
          Obtains the event at the specified index.
 boolean remove sample code for javax.sound.midi.Track.remove(javax.sound.midi.MidiEvent) definition code for javax.sound.midi.Track.remove(javax.sound.midi.MidiEvent) (MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent  event)
          Removes the specified event from the track.
 int size sample code for javax.sound.midi.Track.size() definition code for javax.sound.midi.Track.size() ()
          Obtains the number of events in this track.
 long ticks sample code for javax.sound.midi.Track.ticks() definition code for javax.sound.midi.Track.ticks() ()
          Obtains the length of the track, expressed in MIDI ticks.
 
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)
 

Method Detail

add sample code for javax.sound.midi.Track.add(javax.sound.midi.MidiEvent) definition code for javax.sound.midi.Track.add(javax.sound.midi.MidiEvent)

public boolean add(MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent  event)
Adds a new event to the track. However, if the event is already contained in the track, it is not added again. The list of events is kept in time order, meaning that this event inserted at the appropriate place in the list, not necessarily at the end.

Parameters:
event - the event to add
Returns:
true if the event did not already exist in the track and was added, otherwise false

remove sample code for javax.sound.midi.Track.remove(javax.sound.midi.MidiEvent) definition code for javax.sound.midi.Track.remove(javax.sound.midi.MidiEvent)

public boolean remove(MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent  event)
Removes the specified event from the track.

Parameters:
event - the event to remove
Returns:
true if the event existed in the track and was removed, otherwise false

get sample code for javax.sound.midi.Track.get(int) definition code for javax.sound.midi.Track.get(int)

public MidiEvent sample code for javax.sound.midi.MidiEvent definition code for javax.sound.midi.MidiEvent  get(int index)
              throws ArrayIndexOutOfBoundsException sample code for java.lang.ArrayIndexOutOfBoundsException definition code for java.lang.ArrayIndexOutOfBoundsException 
Obtains the event at the specified index.

Parameters:
index - the location of the desired event in the event vector
Throws:
ArrayIndexOutOfBoundsException - if the specified index is negative or not less than the current size of this track.
ArrayIndexOutOfBoundsException sample code for java.lang.ArrayIndexOutOfBoundsException definition code for java.lang.ArrayIndexOutOfBoundsException
See Also:
size() sample code for javax.sound.midi.Track.size() definition code for javax.sound.midi.Track.size()

size sample code for javax.sound.midi.Track.size() definition code for javax.sound.midi.Track.size()

public int size()
Obtains the number of events in this track.

Returns:
the size of the track's event vector

ticks sample code for javax.sound.midi.Track.ticks() definition code for javax.sound.midi.Track.ticks()

public long ticks()
Obtains the length of the track, expressed in MIDI ticks. (The duration of a tick in seconds is determined by the timing resolution of the Sequence containing this track, and also by the tempo of the music as set by the sequencer.)

Returns:
the duration, in ticks
See Also:
Sequence.Sequence(float, int) sample code for javax.sound.midi.Sequence.Sequence(float, int) definition code for javax.sound.midi.Sequence.Sequence(float, int) , Sequencer.setTempoInBPM(float) sample code for javax.sound.midi.Sequencer.setTempoInBPM(float) definition code for javax.sound.midi.Sequencer.setTempoInBPM(float) , Sequencer.getTickPosition() sample code for javax.sound.midi.Sequencer.getTickPosition() definition code for javax.sound.midi.Sequencer.getTickPosition()