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

public Class MetaMessage

extends MidiMessage
Class Inheritance
Known Direct Subclasses
javax.sound.midi.Track.ImmutableEndOfTrack

A MetaMessage is a MidiMessage that is not meaningful to synthesizers, but that can be stored in a MIDI file and interpreted by a sequencer program. (See the discussion in the MidiMessage class description.) The Standard MIDI Files specification defines various types of meta-events, such as sequence number, lyric, cue point, and set tempo. There are also meta-events for such information as lyrics, copyrights, tempo indications, time and key signatures, markers, etc. For more information, see the Standard MIDI Files 1.0 specification, which is part of the Complete MIDI 1.0 Detailed Specification published by the MIDI Manufacturer's Association (http://www.midi.org).

When data is being transported using MIDI wire protocol, a ShortMessage with the status value 0xFF represents a system reset message. In MIDI files, this same status value denotes a MetaMessage. The types of meta-message are distinguished from each other by the first byte that follows the status byte 0xFF. The subsequent bytes are data bytes. As with system exclusive messages, there are an arbitrary number of data bytes, depending on the type of MetaMessage.

Authors
David Rivas, Kara Kytle
See Also
MetaEventListener

Field Summary

Modifier and TypeField and Description
private int
dataLength

The length of the actual message in the data array.

private static final long
public static final int
META

Status byte for MetaMessage (0xFF, or 255), which is used in MIDI files.

Inherited from javax.sound.midi.MidiMessage:
datalength

Constructor Summary

AccessConstructor and Description
public
MetaMessage()

Constructs a new MetaMessage.

public
MetaMessage(int
meta-message type (must be less than 128)
type
,
byte[]
the data bytes in the MIDI message
data
,
int
an amount of bytes in the data byte array; it should be non-negative and less than or equal to data.length
length
)

Constructs a new MetaMessage and sets the message parameters.

protected
MetaMessage(byte[]
an array of bytes containing the complete message. The message data may be changed using the setMessage method.
data
)

Constructs a new MetaMessage.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a clone of this instance
clone
()

Implements abstract javax.sound.midi.MidiMessage.clone.

Creates a new object of the same class and with the same contents as this object.

public byte[]

Returns:

array containing the meta message data
getData
()

Obtains a copy of the data for the meta message.

public int

Returns:

an integer representing the MetaMessage type
getType
()

Obtains the type of the MetaMessage.

private int
getVarIntLength(long value)

public void
setMessage(int
meta-message type (must be less than 128)
type
,
byte[]
the data bytes in the MIDI message
data
,
int
the number of bytes in the data byte array
length
)

Sets the message parameters for a MetaMessage.

private void
writeVarInt(byte[] data, int off, long value)

Inherited from javax.sound.midi.MidiMessage:
getLengthgetMessagegetStatussetMessage

Field Detail

dataLengthback to summary
private int dataLength

The length of the actual message in the data array. This is used to determine how many bytes of the data array is the message, and how many are the status byte, the type byte, and the variable-length-int describing the length of the message.

maskback to summary
private static final long mask
METAback to summary
public static final int META

Status byte for MetaMessage (0xFF, or 255), which is used in MIDI files. It has the same value as ShortMessage#SYSTEM_RESET, which is used in the real-time "MIDI wire" protocol.

See Also
MidiMessage#getStatus

Constructor Detail

MetaMessageback to summary
public MetaMessage()

Constructs a new MetaMessage. The contents of the message are not set here; use setMessage to set them subsequently.

MetaMessageback to summary
public MetaMessage(int type, byte[] data, int length) throws InvalidMidiDataException

Constructs a new MetaMessage and sets the message parameters. The contents of the message can be changed by using the setMessage method.

Parameters
type:int

meta-message type (must be less than 128)

data:byte[]

the data bytes in the MIDI message

length:int

an amount of bytes in the data byte array; it should be non-negative and less than or equal to data.length

Exceptions
InvalidMidiDataException:
if the parameter values do not specify a valid MIDI meta message
Since
1.7
See Also
setMessage(int, byte[], int), getType(), getData()
MetaMessageback to summary
protected MetaMessage(byte[] data)

Constructs a new MetaMessage.

Parameters
data:byte[]

an array of bytes containing the complete message. The message data may be changed using the setMessage method.

See Also
setMessage

Method Detail

cloneback to summary
public Object clone()

Implements abstract javax.sound.midi.MidiMessage.clone.

Creates a new object of the same class and with the same contents as this object.

Returns:Object

a clone of this instance

Annotations
@Override
getDataback to summary
public byte[] getData()

Obtains a copy of the data for the meta message. The returned array of bytes does not include the status byte or the message length data. The length of the data for the meta message is the length of the array. Note that the length of the entire message includes the status byte and the meta message type byte, and therefore may be longer than the returned array.

Returns:byte[]

array containing the meta message data

See Also
MidiMessage#getLength
getTypeback to summary
public int getType()

Obtains the type of the MetaMessage.

Returns:int

an integer representing the MetaMessage type

getVarIntLengthback to summary
private int getVarIntLength(long value)
setMessageback to summary
public void setMessage(int type, byte[] data, int length) throws InvalidMidiDataException

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.

Parameters
type:int

meta-message type (must be less than 128)

data:byte[]

the data bytes in the MIDI message

length:int

the number of bytes in the data byte array

Exceptions
InvalidMidiDataException:
if the parameter values do not specify a valid MIDI meta message
writeVarIntback to summary
private void writeVarInt(byte[] data, int off, long value)