FileDocCategorySizeDatePackage
MetaMessage.javaAPI DocAndroid 1.5 API4013Wed May 06 22:41:02 BST 2009javax.sound.midi

MetaMessage

public class MetaMessage extends MidiMessage

Fields Summary
public static final int
META
private int
dsp
Constructors Summary
public MetaMessage()

 //displacement from begin of array that 
                     //return by method getData() from begin
                     //of array that contain data
    
      
        super(new byte[] {-1, 0});
    
protected MetaMessage(byte[] data)

        super(data);
        if (data == null) {
            throw new NullPointerException();
        }
        if (super.length > 3) {
            int n = 3;
            while ((n <= super.length) && (super.data[n - 1] < 0)) {
                n++;
            }
            dsp = n;
        }
    
Methods Summary
public java.lang.Objectclone()

        return new MetaMessage(this.getMessage());
    
public byte[]getData()

        if ((super.data != null) && (super.length > 3)) {
            byte[] bt = new byte[super.length - dsp];
            for (int i = dsp; i < super.length; i++) {
                bt[i - dsp] = super.data[i];
            }
            return bt;
        }
        return new byte[0];
    
public intgetType()

        if ((super.data != null) && (super.length >= 2)) {
            return super.data[1] & 0xFF;
        }
        return 0;
    
public voidsetMessage(int type, byte[] data, int length)

        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;
        }