APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.sound.midi

public final Class Track

extends Object
Class Inheritance
Imports
java.util.ArrayList, .HashSet, com.sun.media.sound.MidiUtils

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: 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.

Authors
Kara Kytle, Florian Bomers
See Also
Sequencer#setTrackMute, Sequencer#setTrackSolo

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final MidiEvent
private final ArrayList<MidiEvent>
eventsList

The list containing the events.

private final HashSet<MidiEvent>
set

Use a hashset to detect duplicate events in add(MidiEvent).

Constructor Summary

AccessConstructor and Description
pack-priv
Track()

Package-private constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the event did not already exist in the track and was added, otherwise false
add
(MidiEvent
the event to add
event
)

Adds a new event to the track.

public MidiEvent

Returns:

the event at the specified index
get
(int
the location of the desired event in the event vector
index
)

Obtains the event at the specified index.

public boolean

Returns:

true if the event existed in the track and was removed, otherwise false
remove
(MidiEvent
the event to remove
event
)

Removes the specified event from the track.

public int

Returns:

the size of the track's event vector
size
()

Obtains the number of events in this track.

public long

Returns:

the duration, in ticks
ticks
()

Obtains the length of the track, expressed in MIDI ticks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

eotEventback to summary
private final MidiEvent eotEvent
eventsListback to summary
private final ArrayList<MidiEvent> eventsList

The list containing the events.

setback to summary
private final HashSet<MidiEvent> set

Use a hashset to detect duplicate events in add(MidiEvent).

Constructor Detail

Trackback to summary
pack-priv Track()

Package-private constructor. Constructs a new, empty Track object, which initially contains one event, the meta-event End of Track.

Method Detail

addback to summary
public boolean add(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:MidiEvent

the event to add

Returns:boolean

true if the event did not already exist in the track and was added, otherwise false

getback to summary
public MidiEvent get(int index) throws ArrayIndexOutOfBoundsException

Obtains the event at the specified index.

Parameters
index:int

the location of the desired event in the event vector

Returns:MidiEvent

the event at the specified index

Exceptions
ArrayIndexOutOfBoundsException:
if the specified index is negative or not less than the current size of this track
See Also
size
removeback to summary
public boolean remove(MidiEvent event)

Removes the specified event from the track.

Parameters
event:MidiEvent

the event to remove

Returns:boolean

true if the event existed in the track and was removed, otherwise false

sizeback to summary
public int size()

Obtains the number of events in this track.

Returns:int

the size of the track's event vector

ticksback to summary
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:long

the duration, in ticks

See Also
Sequence#Sequence(float, int), Sequencer#setTempoInBPM(float), Sequencer#getTickPosition()
javax.sound.midi back to summary

private Class Track.ImmutableEndOfTrack

extends MetaMessage
Class Inheritance

Field Summary

Inherited from javax.sound.midi.MetaMessage:
META

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
setMessage(int type, byte[] data, int length)

Overrides javax.sound.midi.MetaMessage.setMessage.

Sets the message parameters for a MetaMessage.

Inherited from javax.sound.midi.MetaMessage:
clonegetDatagetType

Constructor Detail

ImmutableEndOfTrackback to summary
private ImmutableEndOfTrack()

Method Detail

setMessageback to summary
public void setMessage(int type, byte[] data, int length) throws InvalidMidiDataException

Overrides javax.sound.midi.MetaMessage.setMessage.

Doc from javax.sound.midi.MetaMessage.setMessage.

Sets the message parameters for a MetaMessage. Since only one status byte value, 0xFF, is allowed for meta-messages, it does not need to be specified here. Calls to getStatus return 0xFF for all meta-messages.

The type argument should be a valid value for the byte that follows the status byte in the MetaMessage. The data argument should contain all the subsequent bytes of the MetaMessage. In other words, the byte that specifies the type of MetaMessage is not considered a data byte.

Annotations
@Override
Exceptions
InvalidMidiDataException:
if the parameter values do not specify a valid MIDI meta message