Class Track
public class Track extends Object
A Track
occupies a middle level in the hierarchy of data played by a 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
that maintains its timing. For this reason, a new (empty) track is created by calling the 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.
Method Summary
Modifier and Type | Method | Description |
---|---|---|
boolean |
add |
Adds a new event to the track. |
MidiEvent |
get |
Obtains the event at the specified index. |
boolean |
remove |
Removes the specified event from the track. |
int |
size() |
Obtains the number of events in this track. |
long |
ticks() |
Obtains the length of the track, expressed in MIDI ticks. |
Method Details
add
public boolean add(MidiEvent event)
- Parameters:
-
event
- the event to add - Returns:
-
true
if the event did not already exist in the track and was added, otherwisefalse
remove
public boolean remove(MidiEvent event)
- Parameters:
-
event
- the event to remove - Returns:
-
true
if the event existed in the track and was removed, otherwisefalse
get
public MidiEvent get(int index) throws ArrayIndexOutOfBoundsException
- Parameters:
-
index
- the location of the desired event in the event vector - Returns:
- the event at the specified index
- Throws:
-
ArrayIndexOutOfBoundsException
- if the specified index is negative or not less than the current size of this track - See Also:
size
public int size()
- Returns:
- the size of the track's event vector
ticks
public long ticks()
Sequence
containing this track, and also by the tempo of the music as set by the sequencer.)- Returns:
- the duration, in ticks
- See Also:
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/sound/midi/Track.html