Example usage for javax.sound.midi MidiMessage getLength

List of usage examples for javax.sound.midi MidiMessage getLength

Introduction

In this page you can find the example usage for javax.sound.midi MidiMessage getLength.

Prototype

public int getLength() 

Source Link

Document

Obtains the total length of the MIDI message in bytes.

Usage

From source file:de.ailis.midi4js.MessageReceiver.java

/**
 * @see javax.sound.midi.Receiver#send(javax.sound.midi.MidiMessage, long)
 *//*from  w  w w  .j  a  v a  2 s  .c om*/
@Override
public void send(final MidiMessage message, final long timeStamp) {
    try {
        final JSONStringer json = new JSONStringer();
        json.object();
        json.key("status").value(message.getStatus());
        json.key("message");
        json.array();
        final byte[] data = message.getMessage();
        final int max = Math.min(data.length, message.getLength());
        for (int i = 0; i < max; i++)
            json.value(data[i] & 0xff);
        json.endArray();
        if (message instanceof ShortMessage)
            processShortMessage((ShortMessage) message, json);
        else if (message instanceof MetaMessage)
            processMetaMessage((MetaMessage) message, json);
        else if (message instanceof SysexMessage)
            processSysexMessage((SysexMessage) message, json);
        json.endObject();
        this.applet.execJSMethod("messageReceived", System.identityHashCode(this), json.toString(), timeStamp);
    } catch (final JSONException e) {
        throw new RuntimeException(e.toString(), e);
    }
}