/* * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code 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 * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.sound.midi; /** * A {@code MetaMessage} is a {@link MidiMessage} that is not meaningful to * synthesizers, but that can be stored in a MIDI file and interpreted by a * sequencer program. (See the discussion in the {@code MidiMessage} class * description.) The Standard MIDI Files specification defines various types of * meta-events, such as sequence number, lyric, cue point, and set tempo. There * are also meta-events for such information as lyrics, copyrights, tempo * indications, time and key signatures, markers, etc. For more information, see * the Standard MIDI Files 1.0 specification, which is part of the Complete MIDI * 1.0 Detailed Specification published by the MIDI Manufacturer's Association * (http://www.midi.org). *
* When data is being transported using MIDI wire protocol, a
* {@link ShortMessage} with the status value {@code 0xFF} represents a system
* reset message. In MIDI files, this same status value denotes a
* {@code MetaMessage}. The types of meta-message are distinguished from each
* other by the first byte that follows the status byte {@code 0xFF}. The
* subsequent bytes are data bytes. As with system exclusive messages, there are
* an arbitrary number of data bytes, depending on the type of
* {@code MetaMessage}.
*
* @author David Rivas
* @author Kara Kytle
* @see MetaEventListener
*/
public class MetaMessage extends MidiMessage {
/**
* Status byte for {@code MetaMessage} (0xFF, or 255), which is used in MIDI
* files. It has the same value as {@link ShortMessage#SYSTEM_RESET}, which
* is used in the real-time "MIDI wire" protocol.
*
* @see MidiMessage#getStatus
*/
public static final int META = 0xFF; // 255
/**
* The length of the actual message in the data array. This is used to
* determine how many bytes of the data array is the message, and how many
* are the status byte, the type byte, and the variable-length-int
* describing the length of the message.
*/
private int dataLength = 0;
/**
* Constructs a new {@code MetaMessage}. The contents of the message are not
* set here; use {@link #setMessage(int, byte[], int) setMessage} to set
* them subsequently.
*/
public MetaMessage() {
// Default meta message data: just the META status byte value
this(new byte[]{(byte) META, 0});
}
/**
* 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}.
*
* @param data an array of bytes containing the complete message. The
* message data may be changed using the {@code setMessage} method.
* @see #setMessage
*/
protected MetaMessage(byte[] data) {
super(data);
//$$fb 2001-10-06: need to calculate dataLength. Fix for bug #4511796
if (data.length>=3) {
dataLength=data.length-3;
int pos=2;
while (pos