javax.sound.midi
Class ShortMessage

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.sound.midi.MidiMessage sample code for javax.sound.midi.MidiMessage definition code for javax.sound.midi.MidiMessage 
      extended by javax.sound.midi.ShortMessage
All Implemented Interfaces:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

public class ShortMessage
extends MidiMessage sample code for javax.sound.midi.MidiMessage definition code for javax.sound.midi.MidiMessage

A ShortMessage contains a MIDI message that has at most two data bytes following its status byte. The types of MIDI message that satisfy this criterion are channel voice, channel mode, system common, and system real-time--in other words, everything except system exclusive and meta-events. The ShortMessage class provides methods for getting and setting the contents of the MIDI message.

A number of ShortMessage methods have integer parameters by which you specify a MIDI status or data byte. If you know the numeric value, you can express it directly. For system common and system real-time messages, you can often use the corresponding fields of ShortMessage, such as SYSTEM_RESET sample code for javax.sound.midi.ShortMessage.SYSTEM_RESET definition code for javax.sound.midi.ShortMessage.SYSTEM_RESET . For channel messages, the upper four bits of the status byte are specified by a command value and the lower four bits are specified by a MIDI channel number. To convert incoming MIDI data bytes that are in the form of Java's signed bytes, you can use the conversion code given in the MidiMessage sample code for javax.sound.midi.MidiMessage definition code for javax.sound.midi.MidiMessage class description.

See Also:
SysexMessage sample code for javax.sound.midi.SysexMessage definition code for javax.sound.midi.SysexMessage , MetaMessage sample code for javax.sound.midi.MetaMessage definition code for javax.sound.midi.MetaMessage

Field Summary
static int ACTIVE_SENSING sample code for javax.sound.midi.ShortMessage.ACTIVE_SENSING definition code for javax.sound.midi.ShortMessage.ACTIVE_SENSING
          Status byte for Active Sensing message (0xFE, or 254).
static int CHANNEL_PRESSURE sample code for javax.sound.midi.ShortMessage.CHANNEL_PRESSURE definition code for javax.sound.midi.ShortMessage.CHANNEL_PRESSURE
          Command value for Channel Pressure (Aftertouch) message (0xD0, or 208)
static int CONTINUE sample code for javax.sound.midi.ShortMessage.CONTINUE definition code for javax.sound.midi.ShortMessage.CONTINUE
          Status byte for Continue message (0xFB, or 251).
static int CONTROL_CHANGE sample code for javax.sound.midi.ShortMessage.CONTROL_CHANGE definition code for javax.sound.midi.ShortMessage.CONTROL_CHANGE
          Command value for Control Change message (0xB0, or 176)
static int END_OF_EXCLUSIVE sample code for javax.sound.midi.ShortMessage.END_OF_EXCLUSIVE definition code for javax.sound.midi.ShortMessage.END_OF_EXCLUSIVE
          Status byte for End of System Exclusive message (0xF7, or 247).
static int MIDI_TIME_CODE sample code for javax.sound.midi.ShortMessage.MIDI_TIME_CODE definition code for javax.sound.midi.ShortMessage.MIDI_TIME_CODE
          Status byte for MIDI Time Code Quarter Frame message (0xF1, or 241).
static int NOTE_OFF sample code for javax.sound.midi.ShortMessage.NOTE_OFF definition code for javax.sound.midi.ShortMessage.NOTE_OFF
          Command value for Note Off message (0x80, or 128)
static int NOTE_ON sample code for javax.sound.midi.ShortMessage.NOTE_ON definition code for javax.sound.midi.ShortMessage.NOTE_ON
          Command value for Note On message (0x90, or 144)
static int PITCH_BEND sample code for javax.sound.midi.ShortMessage.PITCH_BEND definition code for javax.sound.midi.ShortMessage.PITCH_BEND
          Command value for Pitch Bend message (0xE0, or 224)
static int POLY_PRESSURE sample code for javax.sound.midi.ShortMessage.POLY_PRESSURE definition code for javax.sound.midi.ShortMessage.POLY_PRESSURE
          Command value for Polyphonic Key Pressure (Aftertouch) message (0xA0, or 128)
static int PROGRAM_CHANGE sample code for javax.sound.midi.ShortMessage.PROGRAM_CHANGE definition code for javax.sound.midi.ShortMessage.PROGRAM_CHANGE
          Command value for Program Change message (0xC0, or 192)
static int SONG_POSITION_POINTER sample code for javax.sound.midi.ShortMessage.SONG_POSITION_POINTER definition code for javax.sound.midi.ShortMessage.SONG_POSITION_POINTER
          Status byte for Song Position Pointer message (0xF2, or 242).
static int SONG_SELECT sample code for javax.sound.midi.ShortMessage.SONG_SELECT definition code for javax.sound.midi.ShortMessage.SONG_SELECT
          Status byte for MIDI Song Select message (0xF3, or 243).
static int START sample code for javax.sound.midi.ShortMessage.START definition code for javax.sound.midi.ShortMessage.START
          Status byte for Start message (0xFA, or 250).
static int STOP sample code for javax.sound.midi.ShortMessage.STOP definition code for javax.sound.midi.ShortMessage.STOP
          Status byte for Stop message (0xFC, or 252).
static int SYSTEM_RESET sample code for javax.sound.midi.ShortMessage.SYSTEM_RESET definition code for javax.sound.midi.ShortMessage.SYSTEM_RESET
          Status byte for System Reset message (0xFF, or 255).
static int TIMING_CLOCK sample code for javax.sound.midi.ShortMessage.TIMING_CLOCK definition code for javax.sound.midi.ShortMessage.TIMING_CLOCK
          Status byte for Timing Clock messagem (0xF8, or 248).
static int TUNE_REQUEST sample code for javax.sound.midi.ShortMessage.TUNE_REQUEST definition code for javax.sound.midi.ShortMessage.TUNE_REQUEST
          Status byte for Tune Request message (0xF6, or 246).
 
Fields inherited from class javax.sound.midi.MidiMessage sample code for javax.sound.midi.MidiMessage definition code for javax.sound.midi.MidiMessage
data sample code for javax.sound.midi.MidiMessage.data definition code for javax.sound.midi.MidiMessage.data , length sample code for javax.sound.midi.MidiMessage.length definition code for javax.sound.midi.MidiMessage.length
 
Constructor Summary
  ShortMessage sample code for javax.sound.midi.ShortMessage.ShortMessage() definition code for javax.sound.midi.ShortMessage.ShortMessage() ()
          Constructs a new ShortMessage.
protected ShortMessage sample code for javax.sound.midi.ShortMessage.ShortMessage(byte[]) definition code for javax.sound.midi.ShortMessage.ShortMessage(byte[]) (byte[] data)
          Constructs a new ShortMessage.
 
Method Summary
 Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for javax.sound.midi.ShortMessage.clone() definition code for javax.sound.midi.ShortMessage.clone() ()
          Creates a new object of the same class and with the same contents as this object.
 int getChannel sample code for javax.sound.midi.ShortMessage.getChannel() definition code for javax.sound.midi.ShortMessage.getChannel() ()
          Obtains the MIDI channel associated with this event.
 int getCommand sample code for javax.sound.midi.ShortMessage.getCommand() definition code for javax.sound.midi.ShortMessage.getCommand() ()
          Obtains the MIDI command associated with this event.
 int getData1 sample code for javax.sound.midi.ShortMessage.getData1() definition code for javax.sound.midi.ShortMessage.getData1() ()
          Obtains the first data byte in the message.
 int getData2 sample code for javax.sound.midi.ShortMessage.getData2() definition code for javax.sound.midi.ShortMessage.getData2() ()
          Obtains the second data byte in the message.
protected  int getDataLength sample code for javax.sound.midi.ShortMessage.getDataLength(int) definition code for javax.sound.midi.ShortMessage.getDataLength(int) (int status)
          Retrieves the number of data bytes associated with a particular status byte value.
 void setMessage sample code for javax.sound.midi.ShortMessage.setMessage(int) definition code for javax.sound.midi.ShortMessage.setMessage(int) (int status)
          Sets the parameters for a MIDI message that takes no data bytes.
 void setMessage sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int) (int status, int data1, int data2)
          Sets the parameters for a MIDI message that takes one or two data bytes.
 void setMessage sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) (int command, int channel, int data1, int data2)
          Sets the short message parameters for a channel message which takes up to two data bytes.
 
Methods inherited from class javax.sound.midi.MidiMessage sample code for javax.sound.midi.MidiMessage definition code for javax.sound.midi.MidiMessage
getLength sample code for javax.sound.midi.MidiMessage.getLength() definition code for javax.sound.midi.MidiMessage.getLength() , getMessage sample code for javax.sound.midi.MidiMessage.getMessage() definition code for javax.sound.midi.MidiMessage.getMessage() , getStatus sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , setMessage sample code for javax.sound.midi.MidiMessage.setMessage(byte[], int) definition code for javax.sound.midi.MidiMessage.setMessage(byte[], int)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
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)
 

Field Detail

MIDI_TIME_CODE sample code for javax.sound.midi.ShortMessage.MIDI_TIME_CODE

public static final int MIDI_TIME_CODE
Status byte for MIDI Time Code Quarter Frame message (0xF1, or 241).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

SONG_POSITION_POINTER sample code for javax.sound.midi.ShortMessage.SONG_POSITION_POINTER

public static final int SONG_POSITION_POINTER
Status byte for Song Position Pointer message (0xF2, or 242).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

SONG_SELECT sample code for javax.sound.midi.ShortMessage.SONG_SELECT

public static final int SONG_SELECT
Status byte for MIDI Song Select message (0xF3, or 243).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

TUNE_REQUEST sample code for javax.sound.midi.ShortMessage.TUNE_REQUEST

public static final int TUNE_REQUEST
Status byte for Tune Request message (0xF6, or 246).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

END_OF_EXCLUSIVE sample code for javax.sound.midi.ShortMessage.END_OF_EXCLUSIVE

public static final int END_OF_EXCLUSIVE
Status byte for End of System Exclusive message (0xF7, or 247).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

TIMING_CLOCK sample code for javax.sound.midi.ShortMessage.TIMING_CLOCK

public static final int TIMING_CLOCK
Status byte for Timing Clock messagem (0xF8, or 248).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

START sample code for javax.sound.midi.ShortMessage.START

public static final int START
Status byte for Start message (0xFA, or 250).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

CONTINUE sample code for javax.sound.midi.ShortMessage.CONTINUE

public static final int CONTINUE
Status byte for Continue message (0xFB, or 251).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

STOP sample code for javax.sound.midi.ShortMessage.STOP

public static final int STOP
Status byte for Stop message (0xFC, or 252).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

ACTIVE_SENSING sample code for javax.sound.midi.ShortMessage.ACTIVE_SENSING

public static final int ACTIVE_SENSING
Status byte for Active Sensing message (0xFE, or 254).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

SYSTEM_RESET sample code for javax.sound.midi.ShortMessage.SYSTEM_RESET

public static final int SYSTEM_RESET
Status byte for System Reset message (0xFF, or 255).

See Also:
MidiMessage.getStatus() sample code for javax.sound.midi.MidiMessage.getStatus() definition code for javax.sound.midi.MidiMessage.getStatus() , Constant Field Values

NOTE_OFF sample code for javax.sound.midi.ShortMessage.NOTE_OFF

public static final int NOTE_OFF
Command value for Note Off message (0x80, or 128)

See Also:
Constant Field Values

NOTE_ON sample code for javax.sound.midi.ShortMessage.NOTE_ON

public static final int NOTE_ON
Command value for Note On message (0x90, or 144)

See Also:
Constant Field Values

POLY_PRESSURE sample code for javax.sound.midi.ShortMessage.POLY_PRESSURE

public static final int POLY_PRESSURE
Command value for Polyphonic Key Pressure (Aftertouch) message (0xA0, or 128)

See Also:
Constant Field Values

CONTROL_CHANGE sample code for javax.sound.midi.ShortMessage.CONTROL_CHANGE

public static final int CONTROL_CHANGE
Command value for Control Change message (0xB0, or 176)

See Also:
Constant Field Values

PROGRAM_CHANGE sample code for javax.sound.midi.ShortMessage.PROGRAM_CHANGE

public static final int PROGRAM_CHANGE
Command value for Program Change message (0xC0, or 192)

See Also:
Constant Field Values

CHANNEL_PRESSURE sample code for javax.sound.midi.ShortMessage.CHANNEL_PRESSURE

public static final int CHANNEL_PRESSURE
Command value for Channel Pressure (Aftertouch) message (0xD0, or 208)

See Also:
Constant Field Values

PITCH_BEND sample code for javax.sound.midi.ShortMessage.PITCH_BEND

public static final int PITCH_BEND
Command value for Pitch Bend message (0xE0, or 224)

See Also:
Constant Field Values
Constructor Detail

ShortMessage sample code for javax.sound.midi.ShortMessage() definition code for javax.sound.midi.ShortMessage()

public ShortMessage()
Constructs a new ShortMessage. The contents of the new message are guaranteed to specify a valid MIDI message. Subsequently, you may set the contents of the message using one of the setMessage methods.

See Also:
setMessage(int) sample code for javax.sound.midi.ShortMessage.setMessage(int) definition code for javax.sound.midi.ShortMessage.setMessage(int)

ShortMessage sample code for javax.sound.midi.ShortMessage(byte[]) definition code for javax.sound.midi.ShortMessage(byte[])

protected ShortMessage(byte[] data)
Constructs a new ShortMessage.

Parameters:
data - an array of bytes containing the complete message. The message data may be changed using the setMessage method.
See Also:
setMessage(int) sample code for javax.sound.midi.ShortMessage.setMessage(int) definition code for javax.sound.midi.ShortMessage.setMessage(int)
Method Detail

setMessage sample code for javax.sound.midi.ShortMessage.setMessage(int) definition code for javax.sound.midi.ShortMessage.setMessage(int)

public void setMessage(int status)
                throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException 
Sets the parameters for a MIDI message that takes no data bytes.

Parameters:
status - the MIDI status byte
Throws:
InvalidMidiDataException - if status does not specify a valid MIDI status byte for a message that requires no data bytes.
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException
See Also:
setMessage(int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int) , setMessage(int, int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int)

setMessage sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int)

public void setMessage(int status,
                       int data1,
                       int data2)
                throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException 
Sets the parameters for a MIDI message that takes one or two data bytes. If the message takes only one data byte, the second data byte is ignored; if the message does not take any data bytes, both data bytes are ignored.

Parameters:
status - the MIDI status byte
data1 - the first data byte
data2 - the second data byte
Throws:
InvalidMidiDataException - if the the status byte, or all data bytes belonging to the message, do not specify a valid MIDI message.
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException
See Also:
setMessage(int, int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) , setMessage(int) sample code for javax.sound.midi.ShortMessage.setMessage(int) definition code for javax.sound.midi.ShortMessage.setMessage(int)

setMessage sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int)

public void setMessage(int command,
                       int channel,
                       int data1,
                       int data2)
                throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException 
Sets the short message parameters for a channel message which takes up to two data bytes. If the message only takes one data byte, the second data byte is ignored; if the message does not take any data bytes, both data bytes are ignored.

Parameters:
command - the MIDI command represented by this message
channel - the channel associated with the message
data1 - the first data byte
data2 - the second data byte
Throws:
InvalidMidiDataException - if the status byte or all data bytes belonging to the message, do not specify a valid MIDI message
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException
See Also:
setMessage(int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int) , setMessage(int) sample code for javax.sound.midi.ShortMessage.setMessage(int) definition code for javax.sound.midi.ShortMessage.setMessage(int) , getCommand() sample code for javax.sound.midi.ShortMessage.getCommand() definition code for javax.sound.midi.ShortMessage.getCommand() , getChannel() sample code for javax.sound.midi.ShortMessage.getChannel() definition code for javax.sound.midi.ShortMessage.getChannel() , getData1() sample code for javax.sound.midi.ShortMessage.getData1() definition code for javax.sound.midi.ShortMessage.getData1() , getData2() sample code for javax.sound.midi.ShortMessage.getData2() definition code for javax.sound.midi.ShortMessage.getData2()

getChannel sample code for javax.sound.midi.ShortMessage.getChannel() definition code for javax.sound.midi.ShortMessage.getChannel()

public int getChannel()
Obtains the MIDI channel associated with this event. This method assumes that the event is a MIDI channel message; if not, the return value will not be meaningful.

Returns:
MIDI channel associated with the message.
See Also:
setMessage(int, int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int)

getCommand sample code for javax.sound.midi.ShortMessage.getCommand() definition code for javax.sound.midi.ShortMessage.getCommand()

public int getCommand()
Obtains the MIDI command associated with this event. This method assumes that the event is a MIDI channel message; if not, the return value will not be meaningful.

See Also:
setMessage(int, int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int, int)

getData1 sample code for javax.sound.midi.ShortMessage.getData1() definition code for javax.sound.midi.ShortMessage.getData1()

public int getData1()
Obtains the first data byte in the message.

Returns:
the value of the data1 field
See Also:
setMessage(int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int)

getData2 sample code for javax.sound.midi.ShortMessage.getData2() definition code for javax.sound.midi.ShortMessage.getData2()

public int getData2()
Obtains the second data byte in the message.

Returns:
the value of the data2 field
See Also:
setMessage(int, int, int) sample code for javax.sound.midi.ShortMessage.setMessage(int, int, int) definition code for javax.sound.midi.ShortMessage.setMessage(int, int, int)

clone sample code for javax.sound.midi.ShortMessage.clone() definition code for javax.sound.midi.ShortMessage.clone()

public Object sample code for java.lang.Object definition code for java.lang.Object  clone()
Creates a new object of the same class and with the same contents as this object.

Specified by:
clone sample code for javax.sound.midi.MidiMessage.clone() definition code for javax.sound.midi.MidiMessage.clone() in class MidiMessage sample code for javax.sound.midi.MidiMessage definition code for javax.sound.midi.MidiMessage
Returns:
a clone of this instance.
See Also:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

getDataLength sample code for javax.sound.midi.ShortMessage.getDataLength(int) definition code for javax.sound.midi.ShortMessage.getDataLength(int)

protected final int getDataLength(int status)
                           throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException 
Retrieves the number of data bytes associated with a particular status byte value.

Parameters:
status - status byte value, which must represent a short MIDI message
Returns:
data length in bytes (0, 1, or 2)
Throws:
InvalidMidiDataException - if the status argument does not represent the status byte for any short message
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException