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 class SysexMessage extends MidiMessage {
23: public static final int SPECIAL_SYSTEM_EXCLUSIVE = 247;
24:
25: public static final int SYSTEM_EXCLUSIVE = 240;
26:
27: public SysexMessage() {
28: super (new byte[] { -16, -9 });
29: }
30:
31: protected SysexMessage(byte[] data) {
32: super (data);
33: }
34:
35: @Override
36: public Object clone() {
37: return new SysexMessage(this .getMessage());
38: }
39:
40: public byte[] getData() {
41: byte[] bt = new byte[super .length - 1];
42: for (int i = 1; i < super .length; i++) {
43: bt[i - 1] = super .data[i];
44: }
45: return bt;
46: }
47:
48: @Override
49: public void setMessage(byte[] data, int length)
50: throws InvalidMidiDataException {
51: //FIXME
52: /*
53: * if this exception throw out, the value of wrong status byte
54: * should be the hexadecimal value
55: */
56: if (((data[0] & 0xFF) != SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE)
57: && ((data[0] & 0xFF) != SysexMessage.SYSTEM_EXCLUSIVE)) {
58: // sound.09=Invalid status byte for sysex message: {0}
59: throw new InvalidMidiDataException(Messages.getString(
60: "sound.09", //$NON-NLS-1$
61: data[0] & 0xFF));
62: }
63: super .setMessage(data, length);
64: }
65:
66: public void setMessage(int status, byte[] data, int length)
67: throws InvalidMidiDataException {
68: //FIXME
69: /*
70: * if this exception throw out, the value of wrong status byte
71: * should be the hexadecimal value
72: */
73: if ((status != SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE)
74: && (status != SysexMessage.SYSTEM_EXCLUSIVE)) {
75: // sound.09=Invalid status byte for sysex message: {0}
76: throw new InvalidMidiDataException(Messages.getString(
77: "sound.09", //$NON-NLS-1$
78: status));
79: }
80: if ((length < 0) || (length > data.length)) {
81: // sound.03=length out of bounds: {0}
82: throw new IndexOutOfBoundsException(Messages.getString(
83: "sound.03", length)); //$NON-NLS-1$
84: }
85: byte[] bt = new byte[length + 1];
86: bt[0] = (byte) status;
87: for (int i = 0; i < length; i++) {
88: bt[i + 1] = data[i];
89: }
90: super .setMessage(bt, length + 1);
91: }
92: }
|