changeset 1166:8e01a3dee336

5050147: RFE: Add More Useful Constructors to MidiMessage Subclasses Reviewed-by: alexp
author amenkov
date Fri, 17 Apr 2009 15:02:46 +0400
parents 7601454859c2
children f94a3aaae91d
files src/share/classes/javax/sound/midi/MetaMessage.java src/share/classes/javax/sound/midi/ShortMessage.java src/share/classes/javax/sound/midi/SysexMessage.java
diffstat 3 files changed, 148 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/sound/midi/MetaMessage.java	Fri Apr 17 12:46:24 2009 +0400
+++ b/src/share/classes/javax/sound/midi/MetaMessage.java	Fri Apr 17 15:02:46 2009 +0400
@@ -102,6 +102,29 @@
         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 <code>MetaMessage</code>.
--- a/src/share/classes/javax/sound/midi/ShortMessage.java	Fri Apr 17 12:46:24 2009 +0400
+++ b/src/share/classes/javax/sound/midi/ShortMessage.java	Fri Apr 17 15:02:46 2009 +0400
@@ -187,6 +187,83 @@
         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 <code>ShortMessage</code>.
--- a/src/share/classes/javax/sound/midi/SysexMessage.java	Fri Apr 17 12:46:24 2009 +0400
+++ b/src/share/classes/javax/sound/midi/SysexMessage.java	Fri Apr 17 15:02:46 2009 +0400
@@ -120,6 +120,54 @@
         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 <code>SysexMessage</code>.