1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
182 *
183 * @return array containing the meta message data
184 * @see MidiMessage#getLength
185 */
186 public byte[] getData() {
187 byte[] returnedArray = new byte[dataLength];
188 System.arraycopy(data, (length - dataLength), returnedArray, 0, dataLength);
189 return returnedArray;
190 }
191
192 /**
193 * Creates a new object of the same class and with the same contents as this
194 * object.
195 *
196 * @return a clone of this instance
197 */
198 @Override
199 public Object clone() {
200 byte[] newData = new byte[length];
201 System.arraycopy(data, 0, newData, 0, newData.length);
202
203 MetaMessage event = new MetaMessage(newData);
204 return event;
205 }
206
207 // HELPER METHODS
208
209 private int getVarIntLength(long value) {
210 int length = 0;
211 do {
212 value = value >> 7;
213 length++;
214 } while (value > 0);
215 return length;
216 }
217
218 private static final long mask = 0x7F;
219
220 private void writeVarInt(byte[] data, int off, long value) {
221 int shift=63; // number of bitwise left-shifts of mask
222 // first screen out leading zeros
223 while ((shift > 0) && ((value & (mask << shift)) == 0)) shift-=7;
224 // then write actual values
|
1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
182 *
183 * @return array containing the meta message data
184 * @see MidiMessage#getLength
185 */
186 public byte[] getData() {
187 byte[] returnedArray = new byte[dataLength];
188 System.arraycopy(data, (length - dataLength), returnedArray, 0, dataLength);
189 return returnedArray;
190 }
191
192 /**
193 * Creates a new object of the same class and with the same contents as this
194 * object.
195 *
196 * @return a clone of this instance
197 */
198 @Override
199 public Object clone() {
200 byte[] newData = new byte[length];
201 System.arraycopy(data, 0, newData, 0, newData.length);
202 return new MetaMessage(newData);
203 }
204
205 // HELPER METHODS
206
207 private int getVarIntLength(long value) {
208 int length = 0;
209 do {
210 value = value >> 7;
211 length++;
212 } while (value > 0);
213 return length;
214 }
215
216 private static final long mask = 0x7F;
217
218 private void writeVarInt(byte[] data, int off, long value) {
219 int shift=63; // number of bitwise left-shifts of mask
220 // first screen out leading zeros
221 while ((shift > 0) && ((value & (mask << shift)) == 0)) shift-=7;
222 // then write actual values
|