Skip to content

Most visited

Recently visited

navigation

MidiReceiver

public abstract class MidiReceiver
extends Object

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


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.

Inherited methods

From class java.lang.Object

Public constructors

MidiReceiver

added in API level 23
MidiReceiver ()

Default MidiReceiver constructor. Maximum message size is set to MAX_VALUE

MidiReceiver

added in API level 23
MidiReceiver (int maxMessageSize)

MidiReceiver constructor.

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

Public methods

flush

added in API level 23
void flush ()

Instructs the receiver to discard all pending MIDI data.

Throws
IOException

getMaxMessageSize

added in API level 23
int getMaxMessageSize ()

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

Returns
int maximum message size

onFlush

added in API level 23
void onFlush ()

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

onSend

added in API level 23
void onSend (byte[] msg, 
                int offset, 
                int count, 
                long timestamp)

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 byte: a byte array containing the MIDI data

offset int: the offset of the first byte of the data in the array to be processed

count int: the number of bytes of MIDI data in the array to be processed

timestamp long: the timestamp of the message (based on nanoTime()

Throws
IOException

send

added in API level 23
void send (byte[] msg, 
                int offset, 
                int count)

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 byte: a byte array containing the MIDI data

offset int: the offset of the first byte of the data in the array to be sent

count int: the number of bytes of MIDI data in the array to be sent

Throws
IOException if the data could not be sent in entirety

send

added in API level 23
void send (byte[] msg, 
                int offset, 
                int count, 
                long timestamp)

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 byte: a byte array containing the MIDI data

offset int: the offset of the first byte of the data in the array to be sent

count int: the number of bytes of MIDI data in the array to be sent

timestamp long: the timestamp of the message, based on nanoTime()

Throws
IOException if the data could not be sent in entirety
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.