1 7 8 package javax.sound.midi; 9 10 58 public class SysexMessage extends MidiMessage { 59 60 61 63 64 68 public static final int SYSTEM_EXCLUSIVE = 0xF0; 70 71 77 public static final int SPECIAL_SYSTEM_EXCLUSIVE = 0xF7; 79 80 82 83 88 90 91 99 public SysexMessage() { 100 this(new byte[2]); 101 data[0] = (byte) (SYSTEM_EXCLUSIVE & 0xFF); 103 data[1] = (byte) (ShortMessage.END_OF_EXCLUSIVE & 0xFF); 104 } 105 106 107 114 protected SysexMessage(byte[] data) { 115 super(data); 116 } 117 118 119 127 public void setMessage(byte[] data, int length) throws InvalidMidiDataException { 128 int status = (data[0] & 0xFF); 129 if ((status != 0xF0) && (status != 0xF7)) { 130 throw new InvalidMidiDataException ("Invalid status byte for sysex message: 0x" + Integer.toHexString(status)); 131 } 132 super.setMessage(data, length); 133 } 134 135 136 143 public void setMessage(int status, byte[] data, int length) throws InvalidMidiDataException { 144 if ( (status != 0xF0) && (status != 0xF7) ) { 145 throw new InvalidMidiDataException ("Invalid status byte for sysex message: 0x" + Integer.toHexString(status)); 146 } 147 if (length < 0 || length > data.length) { 148 throw new IndexOutOfBoundsException ("length out of bounds: "+length); 149 } 150 this.length = length + 1; 151 152 if (this.data==null || this.data.length < this.length) { 153 this.data = new byte[this.length]; 154 } 155 156 this.data[0] = (byte) (status & 0xFF); 157 if (length > 0) { 158 System.arraycopy(data, 0, this.data, 1, length); 159 } 160 } 161 162 163 168 public byte[] getData() { 169 byte[] returnedArray = new byte[length - 1]; 170 System.arraycopy(data, 1, returnedArray, 0, (length - 1)); 171 return returnedArray; 172 } 173 174 175 180 public Object clone() { 181 byte[] newData = new byte[length]; 182 System.arraycopy(data, 0, newData, 0, newData.length); 183 SysexMessage event = new SysexMessage (newData); 184 return event; 185 } 186 } 187 | Popular Tags |