< prev index next >

src/java.desktop/share/classes/javax/sound/midi/ShortMessage.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 415      * @return the value of the {@code data2} field
 416      * @see #setMessage(int, int, int)
 417      */
 418     public int getData2() {
 419         if (length > 2) {
 420             return (data[2] & 0xFF);
 421         }
 422         return 0;
 423     }
 424 
 425     /**
 426      * Creates a new object of the same class and with the same contents as this
 427      * object.
 428      *
 429      * @return a clone of this instance
 430      */
 431     @Override
 432     public Object clone() {
 433         byte[] newData = new byte[length];
 434         System.arraycopy(data, 0, newData, 0, newData.length);
 435 
 436         ShortMessage msg = new ShortMessage(newData);
 437         return msg;
 438     }
 439 
 440     /**
 441      * Retrieves the number of data bytes associated with a particular status
 442      * byte value.
 443      *
 444      * @param  status status byte value, which must represent a short MIDI
 445      *         message
 446      * @return data length in bytes (0, 1, or 2)
 447      * @throws InvalidMidiDataException if the {@code status} argument does not
 448      *         represent the status byte for any short message
 449      */
 450     protected final int getDataLength(int status) throws InvalidMidiDataException {
 451         // system common and system real-time messages
 452         switch(status) {
 453         case 0xF6:                      // Tune Request
 454         case 0xF7:                      // EOX
 455             // System real-time messages
 456         case 0xF8:                      // Timing Clock
 457         case 0xF9:                      // Undefined


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 415      * @return the value of the {@code data2} field
 416      * @see #setMessage(int, int, int)
 417      */
 418     public int getData2() {
 419         if (length > 2) {
 420             return (data[2] & 0xFF);
 421         }
 422         return 0;
 423     }
 424 
 425     /**
 426      * Creates a new object of the same class and with the same contents as this
 427      * object.
 428      *
 429      * @return a clone of this instance
 430      */
 431     @Override
 432     public Object clone() {
 433         byte[] newData = new byte[length];
 434         System.arraycopy(data, 0, newData, 0, newData.length);
 435         return new ShortMessage(newData);


 436     }
 437 
 438     /**
 439      * Retrieves the number of data bytes associated with a particular status
 440      * byte value.
 441      *
 442      * @param  status status byte value, which must represent a short MIDI
 443      *         message
 444      * @return data length in bytes (0, 1, or 2)
 445      * @throws InvalidMidiDataException if the {@code status} argument does not
 446      *         represent the status byte for any short message
 447      */
 448     protected final int getDataLength(int status) throws InvalidMidiDataException {
 449         // system common and system real-time messages
 450         switch(status) {
 451         case 0xF6:                      // Tune Request
 452         case 0xF7:                      // EOX
 453             // System real-time messages
 454         case 0xF8:                      // Timing Clock
 455         case 0xF9:                      // Undefined


< prev index next >