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