overview

command
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

MIDI API overview and reference example.

Demonstrates the full device-to-port lifecycle of the ndk/midi package, which wraps Android's native MIDI API (AMidi). The example shows how to:

  • Obtain an AMidiDevice handle from the Java MidiManager via JNI
  • Inspect the number of input and output ports on the device
  • Open an input port and send MIDI messages (Note On, Note Off, Control Change, Program Change)
  • Construct MIDI messages as byte arrays with the correct status bytes
  • Close ports and the device in the correct order

Obtaining the AMidiDevice handle

The Android NDK does not provide a way to discover or open MIDI devices from C/native code. Device discovery happens on the Java side through android.media.midi.MidiManager. A typical pattern is:

  1. In Java/Kotlin, use MidiManager.openDevice() to get a MidiDevice.
  2. Call AMidiDevice_fromJava(env, javaMidiDevice) via JNI to obtain the native AMidiDevice pointer.
  3. Pass that pointer to Go (e.g. via a cgo bridge or as an unsafe.Pointer stored in a global).

Because this example cannot run standalone (it requires a live Android MIDI device obtained through JNI), it prints reference information about MIDI message formats and demonstrates the API calls that would be made once a Device handle is available.

This program must run on an Android device.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL