Cloneable
MetaMessage
, ShortMessage
, SysexMessage
public abstract class MidiMessage extends Object implements Cloneable
MidiMessage
is the base class for MIDI messages. They include not only the standard MIDI messages that a synthesizer can respond to, but also "meta-events" that can be used by sequencer programs. There are 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). The base MidiMessage
class provides access to three types of information about a MIDI message:
MidiMessage
includes methods to get, but not set, these values. Setting them is a subclass responsibility. The MIDI standard expresses MIDI data in bytes. However, because Java uses signed bytes, the Java Sound API uses integers instead of bytes when expressing MIDI data. For example, the getStatus()
method of MidiMessage
returns MIDI status bytes as integers. If you are processing MIDI data that originated outside Java Sound and now is encoded as signed bytes, the bytes can be converted to integers using this conversion:
int i = (int)(byte & 0xFF)
If you simply need to pass a known MIDI byte value as a method parameter, it can be expressed directly as an integer, using (for example) decimal or hexadecimal notation. For instance, to pass the "active sensing" status byte as the first argument to ShortMessage
's setMessage(int)
method, you can express it as 254 or 0xFE.
Modifier and Type | Field | Description |
---|---|---|
protected byte[] |
data |
The MIDI message data. |
protected int |
length |
The number of bytes in the MIDI message, including the status byte and any data bytes. |
Modifier | Constructor | Description |
---|---|---|
protected |
Constructs a new MidiMessage . |
Modifier and Type | Method | Description |
---|---|---|
abstract Object |
clone() |
Creates a new object of the same class and with the same contents as this object. |
int |
getLength() |
Obtains the total length of the MIDI message in bytes. |
byte[] |
getMessage() |
Obtains the MIDI message data. |
int |
getStatus() |
Obtains the status byte for the MIDI message. |
protected void |
setMessage |
Sets the data for the MIDI message. |
protected byte[] data
protected int length
protected MidiMessage(byte[] data)
MidiMessage
. This protected constructor is called by concrete subclasses, which should ensure that the data array specifies a complete, valid MIDI message.data
- an array of bytes containing the complete message. The message data may be changed using the setMessage
method.protected void setMessage(byte[] data, int length) throws InvalidMidiDataException
data
- the data bytes in the MIDI messagelength
- the number of bytes in the data byte arrayInvalidMidiDataException
- if the parameter values do not specify a valid MIDI meta messagepublic byte[] getMessage()
getLength()
method.MidiMessage
datapublic int getStatus()
MidiMessage
class description.public int getLength()
public abstract Object clone()
© 1993, 2023, 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/21/docs/api/java.desktop/javax/sound/midi/MidiMessage.html