01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.sound.midi;
19:
20: import org.apache.harmony.sound.internal.nls.Messages;
21:
22: public abstract class MidiMessage implements Cloneable {
23:
24: protected byte[] data;
25:
26: protected int length;
27:
28: protected MidiMessage(byte[] data) {
29: if (data == null) {
30: length = 0;
31: } else {
32: length = data.length;
33: this .data = data;
34: }
35: }
36:
37: @Override
38: public abstract Object clone();
39:
40: public int getLength() {
41: return length;
42: }
43:
44: public byte[] getMessage() {
45: if (data == null) {
46: throw new NullPointerException();
47: }
48: return data.clone();
49: }
50:
51: public int getStatus() {
52: if ((data == null) || (length == 0)) {
53: return 0;
54: }
55: return data[0] & 0xFF;
56: }
57:
58: protected void setMessage(byte[] data, int length)
59: throws InvalidMidiDataException {
60: if ((length < 0) || (length > data.length)) {
61: // sound.03=length out of bounds: {0}
62: throw new IndexOutOfBoundsException(Messages.getString(
63: "sound.03", length)); //$NON-NLS-1$
64: }
65:
66: this .data = new byte[length];
67: if (length != 0) {
68: for (int i = 0; i < length; i++) {
69: this.data[i] = data[i];
70: }
71: }
72: this.length = length;
73: }
74: }
|