From c5779d6b8074f07e19d563cd17e3a7e9224c095b Mon Sep 17 00:00:00 2001 From: amenkov Date: Fri, 17 Apr 2009 15:02:46 +0400 Subject: [PATCH] 5050147: RFE: Add More Useful Constructors to MidiMessage Subclasses Reviewed-by: alexp --- .../classes/javax/sound/midi/MetaMessage.java | 23 ++++++ .../javax/sound/midi/ShortMessage.java | 77 +++++++++++++++++++ .../javax/sound/midi/SysexMessage.java | 48 ++++++++++++ 3 files changed, 148 insertions(+) diff --git a/src/share/classes/javax/sound/midi/MetaMessage.java b/src/share/classes/javax/sound/midi/MetaMessage.java index 7718f8caf..8b27fa1f4 100644 --- a/src/share/classes/javax/sound/midi/MetaMessage.java +++ b/src/share/classes/javax/sound/midi/MetaMessage.java @@ -102,6 +102,29 @@ public class MetaMessage extends MidiMessage { this(defaultMessage); } + /** + * Constructs a new {@code MetaMessage} and sets the message parameters. + * The contents of the message can be changed by using + * the {@code setMessage} method. + * + * @param type meta-message type (must be less than 128) + * @param data the data bytes in the MIDI message + * @param length an amount of bytes in the {@code data} byte array; + * it should be non-negative and less than or equal to + * {@code data.length} + * @throws InvalidMidiDataException if the parameter values do not specify + * a valid MIDI meta message + * @see #setMessage(int, byte[], int) + * @see #getType() + * @see #getData() + * @since 1.7 + */ + public MetaMessage(int type, byte[] data, int length) + throws InvalidMidiDataException { + super(null); + setMessage(type, data, length); // can throw InvalidMidiDataException + } + /** * Constructs a new MetaMessage. diff --git a/src/share/classes/javax/sound/midi/ShortMessage.java b/src/share/classes/javax/sound/midi/ShortMessage.java index 716d7b0ef..2dddc3c7a 100644 --- a/src/share/classes/javax/sound/midi/ShortMessage.java +++ b/src/share/classes/javax/sound/midi/ShortMessage.java @@ -187,6 +187,83 @@ public class ShortMessage extends MidiMessage { length = 3; } + /** + * 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. + * + * @param status the MIDI status byte + * @throws InvalidMidiDataException if {@code status} does not specify + * a valid MIDI status byte for a message that requires no data bytes + * @see #setMessage(int) + * @see #setMessage(int, int, int) + * @see #setMessage(int, int, int, int) + * @see #getStatus() + * @since 1.7 + */ + 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 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. + * + * @param status the MIDI status byte + * @param data1 the first data byte + * @param 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 + * @see #setMessage(int) + * @see #setMessage(int, int, int) + * @see #setMessage(int, int, int, int) + * @see #getStatus() + * @see #getData1() + * @see #getData2() + * @since 1.7 + */ + 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 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. + * + * @param command the MIDI command represented by this message + * @param channel the channel associated with the message + * @param data1 the first data byte + * @param data2 the second data byte + * @throws InvalidMidiDataException if the command value, channel value + * or all data bytes belonging to the message do not specify + * a valid MIDI message + * @see #setMessage(int) + * @see #setMessage(int, int, int) + * @see #setMessage(int, int, int, int) + * @see #getCommand() + * @see #getChannel() + * @see #getData1() + * @see #getData2() + * @since 1.7 + */ + public ShortMessage(int command, int channel, int data1, int data2) + throws InvalidMidiDataException { + super(null); + setMessage(command, channel, data1, data2); + } + /** * Constructs a new ShortMessage. diff --git a/src/share/classes/javax/sound/midi/SysexMessage.java b/src/share/classes/javax/sound/midi/SysexMessage.java index a3833fffd..387d06603 100644 --- a/src/share/classes/javax/sound/midi/SysexMessage.java +++ b/src/share/classes/javax/sound/midi/SysexMessage.java @@ -120,6 +120,54 @@ public class SysexMessage extends MidiMessage { data[1] = (byte) (ShortMessage.END_OF_EXCLUSIVE & 0xFF); } + /** + * Constructs a new {@code SysexMessage} and sets the data for + * the message. The first byte of the data array must be a valid system + * exclusive status byte (0xF0 or 0xF7). + * The contents of the message can be changed by using one of + * the {@code setMessage} methods. + * + * @param data the system exclusive message data including the status byte + * @param length the length of the valid message data in the array, + * including the status byte; it should be non-negative and less than + * or equal to {@code data.length} + * @throws InvalidMidiDataException if the parameter values + * do not specify a valid MIDI meta message. + * @see #setMessage(byte[], int) + * @see #setMessage(int, byte[], int) + * @see #getData() + * @since 1.7 + */ + public SysexMessage(byte[] data, int length) + throws InvalidMidiDataException { + super(null); + setMessage(data, length); + } + + /** + * Constructs a new {@code SysexMessage} and sets the data for the message. + * The contents of the message can be changed by using one of + * the {@code setMessage} methods. + * + * @param status the status byte for the message; it must be a valid system + * exclusive status byte (0xF0 or 0xF7) + * @param data the system exclusive message data (without the status byte) + * @param length the length of the valid message data in the array; + * it should be non-negative and less than or equal to + * {@code data.length} + * @throws InvalidMidiDataException if the parameter values + * do not specify a valid MIDI meta message. + * @see #setMessage(byte[], int) + * @see #setMessage(int, byte[], int) + * @see #getData() + * @since 1.7 + */ + public SysexMessage(int status, byte[] data, int length) + throws InvalidMidiDataException { + super(null); + setMessage(status, data, length); + } + /** * Constructs a new SysexMessage. -- GitLab