android_midi 0.20.0
android_midi: ^0.20.0 copied to clipboard
A Flutter plugin for advanced MIDI device control and messaging on Android, with native performance.
android_midi #
android_midi is a Flutter plugin for advanced MIDI (Musical Instrument Digital Interface) control on Android devices. It provides a high-level API for device enumeration, connection management, and expressive MIDI message handling, powered by native C++ and Kotlin/Java code for optimal performance.
Features #
- Enumerate available MIDI devices (USB, virtual, etc.)
- Open and close MIDI devices and ports
- Send and receive MIDI messages (Note On/Off, Control Change, Program Change, Pitch Bend, Aftertouch, SysEx, raw data)
- Real-time MIDI input/output streams
- High-level musical helpers: play notes, chords, arpeggios, sequences, and phrases with tempo
- Rich event modeling (
MidiEvent,MidiPhrase, etc.) for expressive control - Native performance via JNI and C++
Installation #
Add to your pubspec.yaml:
dependencies:
android_midi: ^latest_version
Then run:
flutter pub get
Usage #
Import the package:
import 'package:android_midi/android_midi.dart';
Device Enumeration & Connection #
final devices = await AndroidMidi().listDevices();
final handle = await AndroidMidi().openMidiDevice(devices.first, devices.first.ports.first);
Sending MIDI Messages #
await AndroidMidi().sendNoteOn(handle, 0, 60, 127); // Middle C, max velocity
await AndroidMidi().sendNoteOff(handle, 0, 60, 0);
await AndroidMidi().sendControlChange(handle, 0, 64, 127); // Sustain pedal
await AndroidMidi().sendProgramChange(handle, 0, 5); // Change instrument
await AndroidMidi().sendPitchBend(handle, 0, 8192); // Center position
await AndroidMidi().sendSystemExclusive(handle, [0x7D, 0x10, 0x01]); // Example SysEx
High-Level Musical Helpers #
// Play a note for 500ms
await AndroidMidi().playNote(handle, 0, 60, 100, duration: Duration(milliseconds: 500));
// Play a chord
await AndroidMidi().playChord(handle, 0, [60, 64, 67], 100, duration: Duration(seconds: 1));
// Play an arpeggio
await AndroidMidi().playArpeggio(handle, 0, [60, 64, 67], 100, noteDuration: Duration(milliseconds: 200), delayBetweenNotes: Duration(milliseconds: 100));
// Play a musical phrase
final phrase = MidiPhrase(events: [...], tempo: 120.0);
await AndroidMidi().playPhrase(handle, phrase);
Receiving MIDI Data #
AndroidMidi().receiveMidiStream(handle).listen((data) {
// Handle incoming MIDI bytes
});
Refer to the example app in the example/ directory for more usage patterns and API details.
Platform Support #
Android only. Native code is implemented in C++ and Kotlin/Java for best performance.
Contributing #
Contributions, issues, and feature requests are welcome! Please open an issue or submit a pull request.
License #
This project is licensed under the MIT License. See the LICENSE file for details.