1 7 8 package javax.sound.midi; 9 10 57 58 public abstract class MidiMessage implements Cloneable { 59 60 62 68 protected byte[] data; 69 70 71 76 protected int length = 0; 77 78 79 91 protected MidiMessage(byte[] data) { 92 this.data = data; 93 if (data != null) { 94 this.length = data.length; 95 } 96 } 97 98 99 105 protected void setMessage(byte[] data, int length) throws InvalidMidiDataException { 106 if (length < 0 || (length > 0 && length > data.length)) { 107 throw new IndexOutOfBoundsException ("length out of bounds: "+length); 108 } 109 this.length = length; 110 111 if (this.data == null || this.data.length < this.length) { 112 this.data = new byte[this.length]; 113 } 114 System.arraycopy(data, 0, this.data, 0, length); 115 } 116 117 118 128 public byte[] getMessage() { 129 byte[] returnedArray = new byte[length]; 130 System.arraycopy(data, 0, returnedArray, 0, length); 131 return returnedArray; 132 } 133 134 135 143 public int getStatus() { 144 if (length > 0) { 145 return (data[0] & 0xFF); 146 } 147 return 0; 148 } 149 150 151 160 public int getLength() { 161 return length; 162 } 163 164 165 170 public abstract Object clone(); 171 } 172 | Popular Tags |