javax.sound.midi

Class ShortMessage

Implemented Interfaces:
Cloneable

public class ShortMessage
extends MidiMessage

A short MIDI message that is no longer than 3 bytes long.
Since:
1.3

Field Summary

static int
ACTIVE_SENSING
Status byte for Active Sensing message.
static int
CHANNEL_PRESSURE
Statue nibble for Channel Pressure message.
static int
CONTINUE
Status byte for Continue message.
static int
CONTROL_CHANGE
Status nibble for Control Change message.
static int
END_OF_EXCLUSIVE
Status byte for End Of Exclusive message.
static int
MIDI_TIME_CODE
Status byte for Time Code message.
static int
NOTE_OFF
Status nibble for Note Off message.
static int
NOTE_ON
Status nibble for Note On message.
static int
PITCH_BEND
Status nibble for Pitch Bend message.
static int
POLY_PRESSURE
Status nibble for Poly Pressure message.
static int
PROGRAM_CHANGE
Status nibble for Program Change message.
static int
SONG_POSITION_POINTER
Status byte for Song Position Pointer message.
static int
SONG_SELECT
Status byte for Song Select message.
static int
START
Status byte for Start message.
static int
STOP
Status byte for Stop message.
static int
SYSTEM_RESET
Status byte for System Reset message.
static int
TIMING_CLOCK
Status byte for Timing Clock message.
static int
TUNE_REQUEST
Status byte for Tune Request message.

Fields inherited from class javax.sound.midi.MidiMessage

data, length

Constructor Summary

ShortMessage()
Create a short MIDI message.
ShortMessage(byte[] data)
Create a short MIDI message.

Method Summary

Object
clone()
This method may be called to create a new copy of the Object.
int
getChannel()
Get the channel information from this MIDI message, assuming it is a MIDI channel message.
int
getCommand()
Get the command nibble from this MIDI message, assuming it is a MIDI channel message.
int
getData1()
Get the first data byte from this message, assuming it exists, and zero otherwise.
int
getData2()
Get the second data byte from this message, assuming it exists, and zero otherwise.
protected int
getDataLength(int status)
Return the number of data bytes needed for a given MIDI status byte.
void
setMessage(int status)
Set the MIDI message to one that requires no data bytes.
void
setMessage(int status, int data1, int data2)
Set the MIDI message.
void
setMessage(int command, int channel, int data1, int data2)

Methods inherited from class javax.sound.midi.MidiMessage

clone, getLength, getMessage, getStatus, setMessage

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ACTIVE_SENSING

public static final int ACTIVE_SENSING
Status byte for Active Sensing message.
Field Value:
254

CHANNEL_PRESSURE

public static final int CHANNEL_PRESSURE
Statue nibble for Channel Pressure message.
Field Value:
208

CONTINUE

public static final int CONTINUE
Status byte for Continue message.
Field Value:
251

CONTROL_CHANGE

public static final int CONTROL_CHANGE
Status nibble for Control Change message.
Field Value:
176

END_OF_EXCLUSIVE

public static final int END_OF_EXCLUSIVE
Status byte for End Of Exclusive message.
Field Value:
247

MIDI_TIME_CODE

public static final int MIDI_TIME_CODE
Status byte for Time Code message.
Field Value:
241

NOTE_OFF

public static final int NOTE_OFF
Status nibble for Note Off message.
Field Value:
128

NOTE_ON

public static final int NOTE_ON
Status nibble for Note On message.
Field Value:
144

PITCH_BEND

public static final int PITCH_BEND
Status nibble for Pitch Bend message.
Field Value:
224

POLY_PRESSURE

public static final int POLY_PRESSURE
Status nibble for Poly Pressure message.
Field Value:
160

PROGRAM_CHANGE

public static final int PROGRAM_CHANGE
Status nibble for Program Change message.
Field Value:
192

SONG_POSITION_POINTER

public static final int SONG_POSITION_POINTER
Status byte for Song Position Pointer message.
Field Value:
242

SONG_SELECT

public static final int SONG_SELECT
Status byte for Song Select message.
Field Value:
243

START

public static final int START
Status byte for Start message.
Field Value:
250

STOP

public static final int STOP
Status byte for Stop message.
Field Value:
252

SYSTEM_RESET

public static final int SYSTEM_RESET
Status byte for System Reset message.
Field Value:
255

TIMING_CLOCK

public static final int TIMING_CLOCK
Status byte for Timing Clock message.
Field Value:
248

TUNE_REQUEST

public static final int TUNE_REQUEST
Status byte for Tune Request message.
Field Value:
246

Constructor Details

ShortMessage

public ShortMessage()
Create a short MIDI message. The spec requires that this represent a valid MIDI message, but doesn't specify what it should be. We've chosen the STOP message for our implementation.

ShortMessage

protected ShortMessage(byte[] data)
Create a short MIDI message. The data argument should be a valid MIDI message. Unfortunately the spec does not allow us to throw an InvalidMidiDataException if data is invalid.
Parameters:
data - the message data

Method Details

clone

public Object clone()
This method may be called to create a new copy of the Object. The typical behavior is as follows:
  • o == o.clone() is false
  • o.getClass() == o.clone().getClass() is true
  • o.equals(o) is true

However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object).

If the Object you call clone() on does not implement Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.

Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.

All array types implement Cloneable, and override this method as follows (it should never fail):

 public Object clone()
 {
   try
     {
       super.clone();
     }
   catch (CloneNotSupportedException e)
     {
       throw new InternalError(e.getMessage());
     }
 }
 
Overrides:
clone in interface MidiMessage
Returns:
a copy of the Object
See Also:
Cloneable

getChannel

public int getChannel()
Get the channel information from this MIDI message, assuming it is a MIDI channel message.
Returns:
the MIDI channel for this message

getCommand

public int getCommand()
Get the command nibble from this MIDI message, assuming it is a MIDI channel message.
Returns:
the MIDI command for this message

getData1

public int getData1()
Get the first data byte from this message, assuming it exists, and zero otherwise.
Returns:
the first data byte or zero if none exists.

getData2

public int getData2()
Get the second data byte from this message, assuming it exists, and zero otherwise.
Returns:
the second date byte or zero if none exists.

getDataLength

protected final int getDataLength(int status)
            throws InvalidMidiDataException
Return the number of data bytes needed for a given MIDI status byte.
Parameters:
status - the status byte for a short MIDI message
Returns:
the number of data bytes needed for this status byte
Throws:
InvalidMidiDataException - if status is an invalid status byte

setMessage

public void setMessage(int status)
            throws InvalidMidiDataException
Set the MIDI message to one that requires no data bytes.
Parameters:
status - the status byte for this message
Throws:
InvalidMidiDataException - if status is bad, or requires data

setMessage

public void setMessage(int status,
                       int data1,
                       int data2)
            throws InvalidMidiDataException
Set the MIDI message.
Parameters:
status - the status byte for this message
data1 - the first data byte for this message
data2 - the second data byte for this message
Throws:
InvalidMidiDataException - if status is bad, or data is out of range

setMessage

public void setMessage(int command,
                       int channel,
                       int data1,
                       int data2)
            throws InvalidMidiDataException

ShortMessage.java -- A MIDI message no longer than 3 bytes Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.