if (type < 0 || type >= 128) {
// sound.0A=Invalid meta event with type {0}
throw new InvalidMidiDataException(Messages.getString("sound.0A", type)); //$NON-NLS-1$
}
if (length < 0 || (data != null && length > data.length)) {
// sound.03=length out of bounds: {0}
throw new InvalidMidiDataException(Messages.getString("sound.03", length)); //$NON-NLS-1$
}
try {
if (data == null) {
if (length != 0) {
throw new NullPointerException();
}
super.setMessage(new byte[] { -1, (byte) type, 0 }, 3);
} else {
int div = 128;
int n = 1;
int ost;
int sm = 0;
while (length / div != 0) {
n++;
div *= 128;
}
int ln = n;
byte[] tdata = new byte[length + ln + 2];
div = 1;
ost = (length / div) % 128;
while (n != 0) {
tdata[n - 1 + 2] = (byte) (ost + sm);
n--;
div *= 128;
ost = (length / div) % 128;
sm = 128;
}
tdata[0] = -1;
tdata[1] = (byte) type;
if (length > 0) {
for (int i = 0; i < length; i++) {
tdata[2 + ln + i] = data[i];
}
}
super.setMessage(tdata, length + 2 + ln);
dsp = ln + 2;
}
} catch (InvalidMidiDataException e) {
throw e;
}