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
class provides methods
for getting and setting the contents of the MIDI message.
Field Summary |
---|
public static final int | MIDI_TIME_CODE | Status byte for MIDI Time Code Quarter Frame message (0xF1, or 241).Also see:
- MidiMessage#getStatus
|
public static final int | SONG_POSITION_POINTER | Status byte for Song Position Pointer message (0xF2, or 242).Also see:
- MidiMessage#getStatus
|
public static final int | SONG_SELECT | Status byte for MIDI Song Select message (0xF3, or 243).Also see:
- MidiMessage#getStatus
|
public static final int | TUNE_REQUEST | Status byte for Tune Request message (0xF6, or 246).Also see:
- MidiMessage#getStatus
|
public static final int | END_OF_EXCLUSIVE | Status byte for End of System Exclusive message (0xF7, or 247).Also see:
- MidiMessage#getStatus
|
public static final int | TIMING_CLOCK | Status byte for Timing Clock messagem (0xF8, or 248).Also see:
- MidiMessage#getStatus
|
public static final int | START | Status byte for Start message (0xFA, or 250).Also see:
- MidiMessage#getStatus
|
public static final int | CONTINUE | Status byte for Continue message (0xFB, or 251).Also see:
- MidiMessage#getStatus
|
public static final int | STOP | Status byte for Stop message (0xFC, or 252).Also see:
- MidiMessage#getStatus
|
public static final int | ACTIVE_SENSING | Status byte for Active Sensing message (0xFE, or 254).Also see:
- MidiMessage#getStatus
|
public static final int | SYSTEM_RESET | Status byte for System Reset message (0xFF, or 255).Also see:
- MidiMessage#getStatus
|
public static final int | NOTE_OFF | Command value for Note Off message (0x80, or 128) |
public static final int | NOTE_ON | Command value for Note On message (0x90, or 144) |
public static final int | POLY_PRESSURE | Command value for Polyphonic Key Pressure (Aftertouch) message (0xA0, or 160) |
public static final int | CONTROL_CHANGE | Command value for Control Change message (0xB0, or 176) |
public static final int | PROGRAM_CHANGE | Command value for Program Change message (0xC0, or 192) |
public static final int | CHANNEL_PRESSURE | Command value for Channel Pressure (Aftertouch) message (0xD0, or 208) |
public static final int | PITCH_BEND | Command value for Pitch Bend message (0xE0, or 224) |
Constructor: |
public ShortMessage() {
this(new byte[3]);
// Default message data: NOTE_ON on Channel 0 with max volume
data[0] = (byte) (NOTE_ON & 0xFF);
data[1] = (byte) 64;
data[2] = (byte) 127;
length = 3;
}
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. |
public ShortMessage(int status) throws InvalidMidiDataException {
super(null);
setMessage(status); // can throw InvalidMidiDataException
}
Constructs a new {@code ShortMessage} which represents a MIDI
message that takes no data bytes.
The contents of the message can be changed by using one of
the {@code setMessage} methods. |
protected ShortMessage(byte[] data) {
// $$fb this may set an invalid message.
// Can't correct without compromising compatibility
super(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.
Also see:
- setMessage
|
public ShortMessage(int status,
int data1,
int data2) throws InvalidMidiDataException {
super(null);
setMessage(status, data1, data2); // can throw InvalidMidiDataException
}
Constructs a new {@code ShortMessage} which represents a MIDI message
that 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.
The contents of the message can be changed by using one of
the {@code setMessage} methods. |
public ShortMessage(int command,
int channel,
int data1,
int data2) throws InvalidMidiDataException {
super(null);
setMessage(command, channel, data1, data2);
}
Constructs a new {@code ShortMessage} which represents a channel
MIDI message that 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.
The contents of the message can be changed by using one of
the {@code setMessage} methods. |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.sound.midi.ShortMessage Detail: |
public Object clone() {
byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length);
ShortMessage msg = new ShortMessage(newData);
return msg;
}
Creates a new object of the same class and with the same contents
as this object. |
public int getChannel() {
// this returns 0 if an invalid message is set
return (getStatus() & 0x0F);
}
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. |
public int getCommand() {
// this returns 0 if an invalid message is set
return (getStatus() & 0xF0);
}
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. |
public int getData1() {
if (length > 1) {
return (data[1] & 0xFF);
}
return 0;
}
Obtains the first data byte in the message. |
public int getData2() {
if (length > 2) {
return (data[2] & 0xFF);
}
return 0;
}
Obtains the second data byte in the message. |
protected final int getDataLength(int status) throws InvalidMidiDataException {
// system common and system real-time messages
switch(status) {
case 0xF6: // Tune Request
case 0xF7: // EOX
// System real-time messages
case 0xF8: // Timing Clock
case 0xF9: // Undefined
case 0xFA: // Start
case 0xFB: // Continue
case 0xFC: // Stop
case 0xFD: // Undefined
case 0xFE: // Active Sensing
case 0xFF: // System Reset
return 0;
case 0xF1: // MTC Quarter Frame
case 0xF3: // Song Select
return 1;
case 0xF2: // Song Position Pointer
return 2;
default:
}
// channel voice and mode messages
switch(status & 0xF0) {
case 0x80:
case 0x90:
case 0xA0:
case 0xB0:
case 0xE0:
return 2;
case 0xC0:
case 0xD0:
return 1;
default:
throw new InvalidMidiDataException("Invalid status byte: " + status);
}
}
Retrieves the number of data bytes associated with a particular
status byte value. |
public void setMessage(int status) throws InvalidMidiDataException {
// check for valid values
int dataLength = getDataLength(status); // can throw InvalidMidiDataException
if (dataLength != 0) {
throw new InvalidMidiDataException("Status byte; " + status + " requires " + dataLength + " data bytes");
}
setMessage(status, 0, 0);
}
Sets the parameters for a MIDI message that takes no data bytes. |
public void setMessage(int status,
int data1,
int data2) throws InvalidMidiDataException {
// check for valid values
int dataLength = getDataLength(status); // can throw InvalidMidiDataException
if (dataLength > 0) {
if (data1 < 0 || data1 > 127) {
throw new InvalidMidiDataException("data1 out of range: " + data1);
}
if (dataLength > 1) {
if (data2 < 0 || data2 > 127) {
throw new InvalidMidiDataException("data2 out of range: " + data2);
}
}
}
// set the length
length = dataLength + 1;
// re-allocate array if ShortMessage(byte[]) constructor gave array with fewer elements
if (data == null || data.length < length) {
data = new byte[3];
}
// set the data
data[0] = (byte) (status & 0xFF);
if (length > 1) {
data[1] = (byte) (data1 & 0xFF);
if (length > 2) {
data[2] = (byte) (data2 & 0xFF);
}
}
}
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. |
public void setMessage(int command,
int channel,
int data1,
int data2) throws InvalidMidiDataException {
// check for valid values
if (command >= 0xF0 || command < 0x80) {
throw new InvalidMidiDataException("command out of range: 0x" + Integer.toHexString(command));
}
if ((channel & 0xFFFFFFF0) != 0) { // < = > (channel< 0 || channel >15)
throw new InvalidMidiDataException("channel out of range: " + channel);
}
setMessage((command & 0xF0) | (channel & 0x0F), data1, data2);
}
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. |