Added in API level 23

MidiReceiver

abstract class MidiReceiver
kotlin.Any
   ↳ android.media.midi.MidiReceiver

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

Summary

Public constructors

Default MidiReceiver constructor.

MidiReceiver(maxMessageSize: Int)

MidiReceiver constructor.

Public methods
open Unit

Instructs the receiver to discard all pending MIDI data.

Int

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

open Unit

Called when the receiver is instructed to discard all pending MIDI data.

abstract Unit
onSend(msg: ByteArray!, offset: Int, count: Int, timestamp: Long)

Called whenever the receiver is passed new MIDI data.

open Unit
send(msg: ByteArray!, offset: Int, count: Int)

Called to send MIDI data to the receiver without a timestamp.

open Unit
send(msg: ByteArray!, offset: Int, count: Int, timestamp: Long)

Called to send MIDI data to the receiver with a specified timestamp.

Public constructors

MidiReceiver

Added in API level 23
MidiReceiver()

Default MidiReceiver constructor. Maximum message size is set to java.lang.Integer#MAX_VALUE

MidiReceiver

Added in API level 23
MidiReceiver(maxMessageSize: Int)

MidiReceiver constructor.

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

Public methods

flush

Added in API level 23
open fun flush(): Unit

Instructs the receiver to discard all pending MIDI data.

Exceptions
java.io.IOException

getMaxMessageSize

Added in API level 23
fun getMaxMessageSize(): Int

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

Return
Int maximum message size

onFlush

Added in API level 23
open fun onFlush(): Unit

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.

Exceptions
java.io.IOException

onSend

Added in API level 23
abstract fun onSend(
    msg: ByteArray!,
    offset: Int,
    count: Int,
    timestamp: Long
): Unit

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 ByteArray!: 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 java.lang.System#nanoTime
Exceptions
java.io.IOException

send

Added in API level 23
open fun send(
    msg: ByteArray!,
    offset: Int,
    count: Int
): Unit

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 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 ByteArray!: 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
Exceptions
java.io.IOException if the data could not be sent in entirety

send

Added in API level 23
open fun send(
    msg: ByteArray!,
    offset: Int,
    count: Int,
    timestamp: Long
): Unit

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 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 ByteArray!: 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 java.lang.System#nanoTime
Exceptions
java.io.IOException if the data could not be sent in entirety