# Midi

## Summary

| ### Enumerations ||
|---|---|
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gaba01db17f4a2bfbc3db60dc172972a25{ https://developer.android.com/ndk/reference/group/midi#group___midi_1ggaba01db17f4a2bfbc3db60dc172972a25a099680a1a092e9809a315e527e85384f = 1, https://developer.android.com/ndk/reference/group/midi#group___midi_1ggaba01db17f4a2bfbc3db60dc172972a25acda48ee7ade411b83e9b731230c2ad45 = 2 }` | enum |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gaaf105ae5beaca1dee30ae54530691fce{ https://developer.android.com/ndk/reference/group/midi#group___midi_1ggaaf105ae5beaca1dee30ae54530691fcea5d674752c7ef538e552c25e8ab32e896 = 1, https://developer.android.com/ndk/reference/group/midi#group___midi_1ggaaf105ae5beaca1dee30ae54530691fcea217bbb1860dd35fe169b2ea90c0aa58c = 2, https://developer.android.com/ndk/reference/group/midi#group___midi_1ggaaf105ae5beaca1dee30ae54530691fceafd3d67929dc2f26c332f669ae9c7a3c8 = 3 }` | enum |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga6cd324ab89fc4c829fb27447d7a2e729{ https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729abe5ffb072723c1e2dd0516ddca6c8da4 = 0, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729ab1b8fd15c226ad8d9673d3e77e4f09dc = 1, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729a76695b44ab6f57eb2b76b41a407aa14c = 2, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729ad27fc2c70a56f0f48743813488f1484d = 3, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729a106007d22a489ba220a866fc832a1263 = 4, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729a78fab146d3571910fe6a39d25eda952c = 17, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729aeac3131c68c3af136f55d3a929de9fa9 = 18, https://developer.android.com/ndk/reference/group/midi#group___midi_1gga6cd324ab89fc4c829fb27447d7a2e729a4e1f180cd40cac43b96c5b85aaaed69a = -1 }` | enum |

| ### Typedefs ||
|---|---|
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga4760ba556786c41b89a3c0f4b15b70eb` | typedef `struct AMidiDevice` |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga2134969adfd5e8a63603c2c970f452d6` | typedef `enum https://developer.android.com/ndk/reference/group/midi#group___midi_1ga6cd324ab89fc4c829fb27447d7a2e729` |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga37ec2f525e368e954dc2d82e80a1bf59` | typedef `struct AMidiInputPort` |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga19ccd2095a5146f61d35361473701434` | typedef `struct AMidiOutputPort` |

| ### Functions ||
|---|---|
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga6f7f87430b67fd7f0949b598ded6041e(JNIEnv *env, jobject midiDeviceObj, AMidiDevice **outDevicePtrPtr)` | `https://developer.android.com/ndk/reference/group/media#group___media_1ga009a49041fe39f7bdc6d8b5cddbe760c AMIDI_API` Connects a native Midi Device object to the associated Java MidiDevice object. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gae4e3943bdb1e9959004b14ff88151db1(const AMidiDevice *device)` | `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga6cd324ab89fc4c829fb27447d7a2e729 AMIDI_API` Gets the MIDI device default protocol. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gaec0ab8c7bf0565f032c10b930ae92684(const AMidiDevice *device)` | `ssize_t AMIDI_API` Gets the number of input (sending) ports available on the specified MIDI device. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga70f985c0d037d3017852085cfac79379(const AMidiDevice *device)` | `ssize_t AMIDI_API` Gets the number of output (receiving) ports available on the specified MIDI device. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga7cc41c55b08cd7d3a9aa3114e3d519b4(const AMidiDevice *device)` | `int32_t AMIDI_API` Gets the MIDI device type. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gae2f864e49bbef6ca0fd355e66c1c3c73(const AMidiDevice *midiDevice)` | `https://developer.android.com/ndk/reference/group/media#group___media_1ga009a49041fe39f7bdc6d8b5cddbe760c AMIDI_API` Disconnects the native Midi Device Object from the associated Java MidiDevice object. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gaccfaa98af9585f892de4553ff4ec28cc(const AMidiInputPort *inputPort)` | `void AMIDI_API` Closes the input port. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gab44a38fb2817f35c2ec69fe3b8a0256d(const AMidiDevice *device, int32_t portNumber, AMidiInputPort **outInputPortPtr)` | `https://developer.android.com/ndk/reference/group/media#group___media_1ga009a49041fe39f7bdc6d8b5cddbe760c AMIDI_API` Opens the input port so that the client can send data to it. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gad295a25cbed349d0508dbaf5cc396ed4(const AMidiInputPort *inputPort, const uint8_t *buffer, size_t numBytes)` | `ssize_t AMIDI_API` Sends data to the specified input port. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga482d777ab12434b3098a03b3aca4f0a8(const AMidiInputPort *inputPort)` | `https://developer.android.com/ndk/reference/group/media#group___media_1ga009a49041fe39f7bdc6d8b5cddbe760c AMIDI_API` Sends a message with a 'MIDI flush command code' to the specified port. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gafd99958902c3bbd61fa482c948c55155(const AMidiInputPort *inputPort, const uint8_t *buffer, size_t numBytes, int64_t timestamp)` | `ssize_t AMIDI_API` Sends data to the specified input port with a timestamp. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1gab55ddf9806039a811fa6f9d5c9d5fe7d(const AMidiOutputPort *outputPort)` | `void AMIDI_API` Closes the output port. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga57692601e362fb585b8ad22f2e7c00cb(const AMidiDevice *device, int32_t portNumber, AMidiOutputPort **outOutputPortPtr)` | `https://developer.android.com/ndk/reference/group/media#group___media_1ga009a49041fe39f7bdc6d8b5cddbe760c AMIDI_API` Opens the output port so that the client can receive data from it. |
| `https://developer.android.com/ndk/reference/group/midi#group___midi_1ga214fe4c9e55e302269582fab5e8dd494(const AMidiOutputPort *outputPort, int32_t *opcodePtr, uint8_t *buffer, size_t maxBytes, size_t *numBytesReceivedPtr, int64_t *outTimestampPtr)` | `ssize_t AMIDI_API` Receives the next pending MIDI message. |

## Enumerations

### Anonymous Enum 15

Declared in `amidi/AMidi.h`

```text
 Anonymous Enum 15
```

| Properties ||
|---|---|
| `AMIDI_OPCODE_DATA` |   |
| `AMIDI_OPCODE_FLUSH` |   |

### Anonymous Enum 16

Declared in `amidi/AMidi.h`

```text
 Anonymous Enum 16
```

| Properties ||
|---|---|
| `AMIDI_DEVICE_TYPE_BLUETOOTH` |   |
| `AMIDI_DEVICE_TYPE_USB` |   |
| `AMIDI_DEVICE_TYPE_VIRTUAL` |   |

### AMidiDevice_Protocol

Declared in `amidi/AMidi.h`

```scdoc
 AMidiDevice_Protocol
```

| Properties ||
|---|---|
| `AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_128_BITS` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use MIDI 1.0 through UMP with packet sizes up to 128 bits. |
| `AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_128_BITS_AND_JRTS` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use MIDI 1.0 through UMP with packet sizes up to 128 bits and jitter reduction timestamps. |
| `AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_64_BITS` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use MIDI 1.0 through UMP with packet sizes up to 64 bits. |
| `AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_64_BITS_AND_JRTS` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use MIDI 1.0 through UMP with packet sizes up to 64 bits and jitter reduction timestamps. |
| `AMIDI_DEVICE_PROTOCOL_UMP_MIDI_2_0` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use MIDI 2.0 through UMP. |
| `AMIDI_DEVICE_PROTOCOL_UMP_MIDI_2_0_AND_JRTS` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use MIDI 2.0 through UMP and jitter reduction timestamps. |
| `AMIDI_DEVICE_PROTOCOL_UMP_USE_MIDI_CI` | Constant representing a default protocol with Universal MIDI Packets (UMP). UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. All UMP data should be a multiple of 4 bytes. Use UMP to negotiate with the device with MIDI-CI. MIDI-CI is defined in "MIDI Capability Inquiry (MIDI-CI)" spec. |
| `AMIDI_DEVICE_PROTOCOL_UNKNOWN` | Constant representing a device with an unknown default protocol. If Universal MIDI Packets (UMP) are needed, use MIDI-CI through MIDI 1.0. UMP is defined in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol" spec. MIDI-CI is defined in "MIDI Capability Inquiry (MIDI-CI)" spec. |

## Typedefs

### AMidiDevice

Declared in `amidi/AMidi.h`

```text
struct AMidiDevice AMidiDevice
```

### AMidiDevice_Protocol

Declared in `amidi/AMidi.h`

```gdscript
enum AMidiDevice_Protocol AMidiDevice_Protocol
```

### AMidiInputPort

Declared in `amidi/AMidi.h`

```text
struct AMidiInputPort AMidiInputPort
```

### AMidiOutputPort

Declared in `amidi/AMidi.h`

```text
struct AMidiOutputPort AMidiOutputPort
```

## Functions

### AMidiDevice_fromJava

Declared in `amidi/AMidi.h`

```scdoc
media_status_t AMIDI_API AMidiDevice_fromJava(
  JNIEnv *env,
  jobject midiDeviceObj,
  AMidiDevice **outDevicePtrPtr
)
```
Connects a native Midi Device object to the associated Java MidiDevice object.

Use this AMidiDevice to access the rest of the native MIDI API. Use [AMidiDevice_release()](https://developer.android.com/ndk/reference/group/midi#group___midi_1gae2f864e49bbef6ca0fd355e66c1c3c73) to disconnect from the Java object when not being used any more.

**See also:** [AMEDIA_ERROR_INVALID_OBJECT](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca2fe8f9d2a8563232b91e642fe80fd396) - the midiDeviceObj is null or already connected to a native AMidiDevice **See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - an unknown error occurred.

| Details ||
|---|---|
| Parameters | |---|---| | `env` | Points to the Java Environment. | | `midiDeviceObj` | The Java MidiDevice Object. | | `outDevicePtrPtr` | Points to the pointer to receive the AMidiDevice | |
| **Returns** | AMEDIA_OK on success, or a negative error value: |

### AMidiDevice_getDefaultProtocol

Declared in `amidi/AMidi.h`

```gdscript
AMidiDevice_Protocol AMIDI_API AMidiDevice_getDefaultProtocol(
  const AMidiDevice *device
)
```
Gets the MIDI device default protocol.


Most devices should return PROTOCOL_UNKNOWN (-1). This is intentional as devices with default UMP support are not backwards compatible. When the device is null, return AMIDI_DEVICE_PROTOCOL_UNKNOWN.

| Details ||
|---|---|
| Parameters | |---|---| | `device` | Specifies the MIDI device. | |
| **Returns** | The identifier of the MIDI device default protocol: AMIDI_DEVICE_PROTOCOL_UMP_USE_MIDI_CI AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_64_BITS AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_64_BITS_AND_JRTS AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_128_BITS AMIDI_DEVICE_PROTOCOL_UMP_MIDI_1_0_UP_TO_128_BITS_AND_JRTS AMIDI_DEVICE_PROTOCOL_UMP_MIDI_2_0 AMIDI_DEVICE_PROTOCOL_UMP_MIDI_2_0_AND_JRTS AMIDI_DEVICE_PROTOCOL_UNKNOWN |

Available since API 33.

### AMidiDevice_getNumInputPorts

Declared in `amidi/AMidi.h`

```gdscript
ssize_t AMIDI_API AMidiDevice_getNumInputPorts(
  const AMidiDevice *device
)
```
Gets the number of input (sending) ports available on the specified MIDI device.

**See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - the device parameter is [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4). **See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - couldn't retrieve the device info.

| Details ||
|---|---|
| Parameters | |---|---| | `device` | Specifies the MIDI device. | |
| **Returns** | If successful, returns the number of MIDI input (sending) ports available on the device. If an error occurs, returns a negative value indicating the error: |

### AMidiDevice_getNumOutputPorts

Declared in `amidi/AMidi.h`

```gdscript
ssize_t AMIDI_API AMidiDevice_getNumOutputPorts(
  const AMidiDevice *device
)
```
Gets the number of output (receiving) ports available on the specified MIDI device.

**See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - the device parameter is [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4). **See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - couldn't retrieve the device info.

| Details ||
|---|---|
| Parameters | |---|---| | `device` | Specifies the MIDI device. | |
| **Returns** | If successful, returns the number of MIDI output (receiving) ports available on the device. If an error occurs, returns a negative value indicating the error: |

### AMidiDevice_getType

Declared in `amidi/AMidi.h`

```gdscript
int32_t AMIDI_API AMidiDevice_getType(
  const AMidiDevice *device
)
```
Gets the MIDI device type.

**See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - the device parameter is [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4). **See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - Unknown error.

| Details ||
|---|---|
| Parameters | |---|---| | `device` | Specifies the MIDI device. | |
| **Returns** | The identifier of the MIDI device type: AMIDI_DEVICE_TYPE_USB AMIDI_DEVICE_TYPE_VIRTUAL AMIDI_DEVICE_TYPE_BLUETOOTH or a negative error value: |

### AMidiDevice_release

Declared in `amidi/AMidi.h`

```gdscript
media_status_t AMIDI_API AMidiDevice_release(
  const AMidiDevice *midiDevice
)
```
Disconnects the native Midi Device Object from the associated Java MidiDevice object.

**See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - the device parameter is [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4). **See also:** [AMEDIA_ERROR_INVALID_OBJECT](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca2fe8f9d2a8563232b91e642fe80fd396) - the device is not consistent with the associated Java MidiDevice. **See also:** [AMEDIA_ERROR_INVALID_OBJECT](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca2fe8f9d2a8563232b91e642fe80fd396) - the JNI interface initialization to the associated java MidiDevice failed. **See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - couldn't retrieve the device info.

| Details ||
|---|---|
| Parameters | |---|---| | `midiDevice` | Points to the native AMIDI_MidiDevice. | |
| **Returns** | AMEDIA_OK on success, or a negative error value: |

### AMidiInputPort_close

Declared in `amidi/AMidi.h`

```gdscript
void AMIDI_API AMidiInputPort_close(
  const AMidiInputPort *inputPort
)
```
Closes the input port.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `inputPort` | Identifies the input (sending) port to close. | |

### AMidiInputPort_open

Declared in `amidi/AMidi.h`

```gdscript
media_status_t AMIDI_API AMidiInputPort_open(
  const AMidiDevice *device,
  int32_t portNumber,
  AMidiInputPort **outInputPortPtr
)
```
Opens the input port so that the client can send data to it.

The port remains open and valid until [AMidiInputPort_close()](https://developer.android.com/ndk/reference/group/midi#group___midi_1gaccfaa98af9585f892de4553ff4ec28cc) is called for the returned AMidiInputPort.

**See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - Unknown Error.

| Details ||
|---|---|
| Parameters | |---|---| | `device` | Specifies the MIDI device. | | `portNumber` | Specifies the zero-based port index on the device to open. This value ranges between 0 and one less than the number of input ports reported by the [AMidiDevice_getNumInputPorts()](https://developer.android.com/ndk/reference/group/midi#group___midi_1gaec0ab8c7bf0565f032c10b930ae92684) function.. | | `outInputPortPtr` | Receives the native API port identifier of the opened port. | |
| **Returns** | AMEDIA_OK, or a negative error code: |

### AMidiInputPort_send

Declared in `amidi/AMidi.h`

```gdscript
ssize_t AMIDI_API AMidiInputPort_send(
  const AMidiInputPort *inputPort,
  const uint8_t *buffer,
  size_t numBytes
)
```
Sends data to the specified input port.

**See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - The specified port was [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4), the specified buffer was [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4).

| Details ||
|---|---|
| Parameters | |---|---| | `inputPort` | The identifier of the port to send data to. | | `buffer` | Points to the array of bytes containing the data to send. | | `numBytes` | Specifies the number of bytes to write. | |
| **Returns** | The number of bytes sent, which could be less than specified or a negative error code: |

### AMidiInputPort_sendFlush

Declared in `amidi/AMidi.h`

```gdscript
media_status_t AMIDI_API AMidiInputPort_sendFlush(
  const AMidiInputPort *inputPort
)
```
Sends a message with a 'MIDI flush command code' to the specified port.

This should cause a receiver to discard any pending MIDI data it may have accumulated and not processed.

**See also:** [AMEDIA_OK](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca430c9cb894d1503c082a6738edcc043b) if successful, otherwise a negative error code: **See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - The specified port was [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4)**See also:** [AMEDIA_ERROR_UNSUPPORTED](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760caf95a4a180de59e2677c27f0284742dbd) - The FLUSH command couldn't be sent.

| Details ||
|---|---|
| Parameters | |---|---| | `inputPort` | The identifier of the port to send the flush command to. | |
| **Returns** |   |

### AMidiInputPort_sendWithTimestamp

Declared in `amidi/AMidi.h`

```gdscript
ssize_t AMIDI_API AMidiInputPort_sendWithTimestamp(
  const AMidiInputPort *inputPort,
  const uint8_t *buffer,
  size_t numBytes,
  int64_t timestamp
)
```
Sends data to the specified input port with a timestamp.

**See also:** [AMEDIA_ERROR_INVALID_PARAMETER](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca30abe0adde4d946a110047edbe2ecb2d) - The specified port was [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4), the specified buffer was [NULL](https://developer.android.com/ndk/reference/group/icu4c#group__icu4c_1ga070d2ce7b6bb7e5c05602aa8c308d0c4).

| Details ||
|---|---|
| Parameters | |---|---| | `inputPort` | The identifier of the port to send data to. | | `buffer` | Points to the array of bytes containing the data to send. | | `numBytes` | Specifies the number of bytes to write. | | `timestamp` | The CLOCK_MONOTONIC time in nanoseconds to associate with the sent data. | |
| **Returns** | The number of bytes sent, which could be less than specified or a negative error code: |

### AMidiOutputPort_close

Declared in `amidi/AMidi.h`

```gdscript
void AMIDI_API AMidiOutputPort_close(
  const AMidiOutputPort *outputPort
)
```
Closes the output port.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `outputPort` | The native API port identifier of the port. | |

### AMidiOutputPort_open

Declared in `amidi/AMidi.h`

```gdscript
media_status_t AMIDI_API AMidiOutputPort_open(
  const AMidiDevice *device,
  int32_t portNumber,
  AMidiOutputPort **outOutputPortPtr
)
```
Opens the output port so that the client can receive data from it.

The port remains open and valid until [AMidiOutputPort_close()](https://developer.android.com/ndk/reference/group/midi#group___midi_1gab55ddf9806039a811fa6f9d5c9d5fe7d) is called for the returned AMidiOutputPort.

**See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - Unknown Error.

| Details ||
|---|---|
| Parameters | |---|---| | `device` | Specifies the MIDI device. | | `portNumber` | Specifies the zero-based port index on the device to open. This value ranges between 0 and one less than the number of output ports reported by the AMidiDevice_getNumOutputPorts function. | | `outOutputPortPtr` | Receives the native API port identifier of the opened port. | |
| **Returns** | AMEDIA_OK, or a negative error code: |

### AMidiOutputPort_receive

Declared in `amidi/AMidi.h`

```gdscript
ssize_t AMIDI_API AMidiOutputPort_receive(
  const AMidiOutputPort *outputPort,
  int32_t *opcodePtr,
  uint8_t *buffer,
  size_t maxBytes,
  size_t *numBytesReceivedPtr,
  int64_t *outTimestampPtr
)
```
Receives the next pending MIDI message.

To retrieve all pending messages, the client should repeatedly call this method until it returns 0.

Note that this is a non-blocking call. If there are no Midi messages are available, the function returns 0 immediately (for 0 messages received).

**See also:** [AMEDIA_ERROR_UNKNOWN](https://developer.android.com/ndk/reference/group/media#group___media_1gga009a49041fe39f7bdc6d8b5cddbe760ca1e153ccf39a5a276563af9b4f97ae002) - Unknown Error.

| Details ||
|---|---|
| Parameters | |---|---| | `outputPort` | Identifies the port to receive messages from. | | `opcodePtr` | Receives the message Op Code. | | `buffer` | Points to the buffer to receive the message data bytes. | | `maxBytes` | Specifies the size of the buffer pointed to by the buffer parameter. | | `numBytesReceivedPtr` | On exit, receives the actual number of bytes stored in buffer. | | `outTimestampPtr` | If non-NULL, receives the timestamp associated with the message. (the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds) | |
| **Returns** | the number of messages received (either 0 or 1), or a negative error code: |