Loading media/java/android/media/midi/MidiDispatcher.java +2 −2 Original line number Diff line number Diff line Loading @@ -75,9 +75,9 @@ public final class MidiDispatcher extends MidiReceiver { public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { for (MidiReceiver receiver : mReceivers) { try { receiver.receive(msg, offset, count, timestamp); receiver.send(msg, offset, count, timestamp); } catch (IOException e) { // if the receiver fails we remove the receiver but do not propogate the exception // if the receiver fails we remove the receiver but do not propagate the exception mReceivers.remove(receiver); } } Loading media/java/android/media/midi/MidiInputPort.java +13 −10 Original line number Diff line number Diff line Loading @@ -81,19 +81,22 @@ public final class MidiInputPort extends MidiReceiver implements Closeable { * {@link java.lang.System#nanoTime} */ public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { assert(offset >= 0 && count >= 0 && offset + count <= msg.length); if (offset < 0 || count < 0 || offset + count > msg.length) { throw new IllegalArgumentException("offset or count out of range"); } if (count > MidiPortImpl.MAX_PACKET_DATA_SIZE) { throw new IllegalArgumentException("count exceeds max message size"); } synchronized (mBuffer) { while (count > 0) { int length = MidiPortImpl.packMessage(msg, offset, count, timestamp, mBuffer); mOutputStream.write(mBuffer, 0, length); int sent = MidiPortImpl.getMessageSize(mBuffer, length); assert(sent >= 0 && sent <= length); offset += sent; count -= sent; } } @Override public int getMaxMessageSize() { return MidiPortImpl.MAX_PACKET_DATA_SIZE; } @Override Loading media/java/android/media/midi/MidiOutputPort.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public final class MidiOutputPort extends MidiSender implements Closeable { long timestamp = MidiPortImpl.getMessageTimeStamp(buffer, count); // dispatch to all our receivers mDispatcher.receive(buffer, offset, size, timestamp); mDispatcher.send(buffer, offset, size, timestamp); } } catch (IOException e) { // FIXME report I/O failure? Loading media/java/android/media/midi/MidiReceiver.java +31 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import java.io.IOException; abstract public class MidiReceiver { /** * Called to pass MIDI data to the receiver. * May fail if count exceeds {@link getMaxMessageSize}. * * NOTE: the msg array parameter is only valid within the context of this call. * The msg bytes should be copied by the receiver rather than retaining a reference Loading @@ -42,4 +43,34 @@ abstract public class MidiReceiver { */ abstract public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException; /** * Returns the maximum size of a message this receiver can receive. * Defaults to {@link java.lang.Integer#MAX_VALUE} unless overridden. * @return maximum message size */ public int getMaxMessageSize() { return Integer.MAX_VALUE; } /** * Called to send MIDI data to the receiver * Data will get split into multiple calls to {@link receive} if count exceeds * {@link getMaxMessageSize}. * * @param msg a byte array containing the MIDI data * @param offset the offset of the first byte of the data in the byte array * @param count the number of bytes of MIDI data in the array * @param timestamp the timestamp of the message (based on {@link java.lang.System#nanoTime} * @throws IOException */ public void send(byte[] msg, int offset, int count, long timestamp) throws IOException { int messageSize = getMaxMessageSize(); while (count > 0) { int length = (count > messageSize ? messageSize : count); receive(msg, offset, length, timestamp); offset += length; count -= length; } } } services/usb/java/com/android/server/usb/UsbMidiDevice.java +1 −1 Original line number Diff line number Diff line Loading @@ -144,7 +144,7 @@ public final class UsbMidiDevice implements Closeable { int count = mInputStreams[index].read(buffer); long timestamp = System.nanoTime(); outputReceivers[index].receive(buffer, 0, count, timestamp); outputReceivers[index].send(buffer, 0, count, timestamp); } else if ((pfd.revents & (OsConstants.POLLERR | OsConstants.POLLHUP)) != 0) { done = true; Loading Loading
media/java/android/media/midi/MidiDispatcher.java +2 −2 Original line number Diff line number Diff line Loading @@ -75,9 +75,9 @@ public final class MidiDispatcher extends MidiReceiver { public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { for (MidiReceiver receiver : mReceivers) { try { receiver.receive(msg, offset, count, timestamp); receiver.send(msg, offset, count, timestamp); } catch (IOException e) { // if the receiver fails we remove the receiver but do not propogate the exception // if the receiver fails we remove the receiver but do not propagate the exception mReceivers.remove(receiver); } } Loading
media/java/android/media/midi/MidiInputPort.java +13 −10 Original line number Diff line number Diff line Loading @@ -81,19 +81,22 @@ public final class MidiInputPort extends MidiReceiver implements Closeable { * {@link java.lang.System#nanoTime} */ public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { assert(offset >= 0 && count >= 0 && offset + count <= msg.length); if (offset < 0 || count < 0 || offset + count > msg.length) { throw new IllegalArgumentException("offset or count out of range"); } if (count > MidiPortImpl.MAX_PACKET_DATA_SIZE) { throw new IllegalArgumentException("count exceeds max message size"); } synchronized (mBuffer) { while (count > 0) { int length = MidiPortImpl.packMessage(msg, offset, count, timestamp, mBuffer); mOutputStream.write(mBuffer, 0, length); int sent = MidiPortImpl.getMessageSize(mBuffer, length); assert(sent >= 0 && sent <= length); offset += sent; count -= sent; } } @Override public int getMaxMessageSize() { return MidiPortImpl.MAX_PACKET_DATA_SIZE; } @Override Loading
media/java/android/media/midi/MidiOutputPort.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public final class MidiOutputPort extends MidiSender implements Closeable { long timestamp = MidiPortImpl.getMessageTimeStamp(buffer, count); // dispatch to all our receivers mDispatcher.receive(buffer, offset, size, timestamp); mDispatcher.send(buffer, offset, size, timestamp); } } catch (IOException e) { // FIXME report I/O failure? Loading
media/java/android/media/midi/MidiReceiver.java +31 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import java.io.IOException; abstract public class MidiReceiver { /** * Called to pass MIDI data to the receiver. * May fail if count exceeds {@link getMaxMessageSize}. * * NOTE: the msg array parameter is only valid within the context of this call. * The msg bytes should be copied by the receiver rather than retaining a reference Loading @@ -42,4 +43,34 @@ abstract public class MidiReceiver { */ abstract public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException; /** * Returns the maximum size of a message this receiver can receive. * Defaults to {@link java.lang.Integer#MAX_VALUE} unless overridden. * @return maximum message size */ public int getMaxMessageSize() { return Integer.MAX_VALUE; } /** * Called to send MIDI data to the receiver * Data will get split into multiple calls to {@link receive} if count exceeds * {@link getMaxMessageSize}. * * @param msg a byte array containing the MIDI data * @param offset the offset of the first byte of the data in the byte array * @param count the number of bytes of MIDI data in the array * @param timestamp the timestamp of the message (based on {@link java.lang.System#nanoTime} * @throws IOException */ public void send(byte[] msg, int offset, int count, long timestamp) throws IOException { int messageSize = getMaxMessageSize(); while (count > 0) { int length = (count > messageSize ? messageSize : count); receive(msg, offset, length, timestamp); offset += length; count -= length; } } }
services/usb/java/com/android/server/usb/UsbMidiDevice.java +1 −1 Original line number Diff line number Diff line Loading @@ -144,7 +144,7 @@ public final class UsbMidiDevice implements Closeable { int count = mInputStreams[index].read(buffer); long timestamp = System.nanoTime(); outputReceivers[index].receive(buffer, 0, count, timestamp); outputReceivers[index].send(buffer, 0, count, timestamp); } else if ((pfd.revents & (OsConstants.POLLERR | OsConstants.POLLHUP)) != 0) { done = true; Loading