Android APIs
public abstract class

MidiReceiver

extends Object
java.lang.Object
   ↳ android.media.midi.MidiReceiver
Known Direct Subclasses

Class Overview

Interface for sending and receiving data to and from a MIDI device.

Summary

Public Constructors
MidiReceiver()
Default MidiReceiver constructor.
MidiReceiver(int maxMessageSize)
MidiReceiver constructor.
Public Methods
void flush()
Instructs the receiver to discard all pending MIDI data.
final int getMaxMessageSize()
Returns the maximum size of a message this receiver can receive.
void onFlush()
Called when the receiver is instructed to discard all pending MIDI data.
abstract void onSend(byte[] msg, int offset, int count, long timestamp)
Called whenever the receiver is passed new MIDI data.
void send(byte[] msg, int offset, int count)
Called to send MIDI data to the receiver without a timestamp.
void send(byte[] msg, int offset, int count, long timestamp)
Called to send MIDI data to the receiver with a specified timestamp.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MidiReceiver ()

Added in API level 23

Default MidiReceiver constructor. Maximum message size is set to MAX_VALUE

public MidiReceiver (int maxMessageSize)

Added in API level 23

MidiReceiver constructor.

Parameters
maxMessageSize the maximum size of a message this receiver can receive

Public Methods

public void flush ()

Added in API level 23

Instructs the receiver to discard all pending MIDI data.

Throws
IOException

public final int getMaxMessageSize ()

Added in API level 23

Returns the maximum size of a message this receiver can receive.

Returns
  • maximum message size

public void onFlush ()

Added in API level 23

Called when the receiver is instructed to discard all pending MIDI data. Subclasses should override this method if they maintain a list or queue of MIDI data to be processed in the future.

Throws
IOException

public abstract void onSend (byte[] msg, int offset, int count, long timestamp)

Added in API level 23

Called whenever the receiver is passed new MIDI data. Subclasses override this method to receive MIDI data. May fail if count exceeds 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 to this parameter. Also, modifying the contents of the msg array parameter may result in other receivers in the same application receiving incorrect values in their {link #onSend} method.

Parameters
msg a byte array containing the MIDI data
offset the offset of the first byte of the data in the array to be processed
count the number of bytes of MIDI data in the array to be processed
timestamp the timestamp of the message (based on nanoTime()
Throws
IOException

public void send (byte[] msg, int offset, int count)

Added in API level 23

Called to send MIDI data to the receiver without a timestamp. Data will be processed by receiver in the order sent. Data will get split into multiple calls to onSend(byte[], int, int, long) if count exceeds getMaxMessageSize(). Blocks until all the data is sent or an exception occurs. In the latter case, the amount of data sent prior to the exception is not provided to caller. The communication should be considered corrupt. The sender should reestablish communication, reset all controllers and send all notes off.

Parameters
msg a byte array containing the MIDI data
offset the offset of the first byte of the data in the array to be sent
count the number of bytes of MIDI data in the array to be sent
Throws
IOException if the data could not be sent in entirety

public void send (byte[] msg, int offset, int count, long timestamp)

Added in API level 23

Called to send MIDI data to the receiver with a specified timestamp. Data will be processed by receiver in order first by timestamp, then in the order sent. Data will get split into multiple calls to onSend(byte[], int, int, long) if count exceeds getMaxMessageSize(). Blocks until all the data is sent or an exception occurs. In the latter case, the amount of data sent prior to the exception is not provided to caller. The communication should be considered corrupt. The sender should reestablish communication, reset all controllers and send all notes off.

Parameters
msg a byte array containing the MIDI data
offset the offset of the first byte of the data in the array to be sent
count the number of bytes of MIDI data in the array to be sent
timestamp the timestamp of the message, based on nanoTime()
Throws
IOException if the data could not be sent in entirety