パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v4.0.4

flutter_midi_pro

`flutter_midi_pro` プラグインは、SoundFont (.sf2) ファイルの読み込み、楽器の切り替え、MIDI コマンドによる音符の再生を行う機能を提供します。

AndroidiOSmacOS
30日間ダウンロード
2720
いいね数
33
Pub ポイント
150

パッケージをインストール

flutter pub add flutter_midi_pro

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

flutter_midi_pro は、SoundFont (.sf2) ファイルを介してオーディオ合成を可能にするFlutterプラグインであり、ユーザーが楽器をロードし、それらの間を切り替え、MIDIノートを演奏できるようにします。Android、iOS、macOSをサポートしており、高品質な楽器再生を必要とする音楽アプリに最適です。このプラグインはFlutterのUIフレームワークとシームレスに統合されており、開発者がアプリにインタラクティブな音楽機能を簡単に追加できるようにしています。特に教育ツール、バーチャル楽器、または音楽作曲アプリに役立ちます。

用途

  • バーチャルピアノアプリケーション
  • 音楽教育ツール
  • インタラクティブなサウンドエフェクト
  • MIDIベースのゲームオーディオ
  • アプリでの機器の切り替え

主な機能

  • .sf2 SoundFont ファイルをサポートしています
  • リアルタイムMIDIノート再生
  • 機器の切り替え
  • クロスプラットフォーム互換性(Android、iOS、macOS)
  • 音声の読み込みと再生用のシンプルなAPI

適している対象

  • 音楽アプリを開発する開発者
  • 教育ソフトウェアの作成者
  • MIDIオーディオが必要なゲーム開発者
  • Flutter を使用するオーディオ愛好家

注意事項

  • 楽器データ用に .sf2 ファイルが必要です
  • 大規模な SoundFont を使用するとメモリ使用量が増加する
  • MIDIノートイベントに限定
  • パフォーマンスはデバイスのオーディオ機能に依存します
  • 複雑なオーディオ処理には適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

flutter_midi_pro

pub packageGitHub stars GitHub issues

A SoundFont (.sf2) synthesizer plugin for Flutter, powered by FluidSynth on Android and AVFoundation on iOS/macOS.

  • Load multiple SoundFonts at once and play notes on 16 MIDI channels per soundfont
  • Full expression surface: pitch bend (+ bend range), channel/key aftertouch, any MIDI CC, sustain, master gain, panic
  • List the instruments inside an SF2 (getPresets) and switch presets per channel
  • MIDI file (.mid) playback with pitch-preserving tempo control, seek and loop (Android)
  • Built-in effects: reverb & chorus (FluidSynth), equalizer / delay / distortion (iOS/macOS)
  • Explicit init/dispose lifecycle, pop-free audio, automatic recovery from interruptions and route changes

Windows, Linux and Web support may be added in the future.

Android

The native (FluidSynth) part of the plugin is built with CMake, but no specific CMake version is required. The Android Gradle Plugin automatically downloads and uses its bundled CMake version from the Android SDK — no manual installation is needed. Any CMake from 3.18 up to and including 4.x works.

If you prefer to use your own CMake installation (e.g. the system CMake on Linux), you can optionally point cmake.dir in your project's local.properties to it. In that case make sure ninja is available on your PATH.

The official FluidSynth Android binaries (~40 MB) are downloaded automatically on the first build, checksum-verified and cached in the Gradle user home — later builds are offline. For fully offline environments, download fluidsynth-vX.Y.Z-android24.zip from the FluidSynth releases and unpack it to <plugin>/android/src/main/cpp/fluidsynth/ (so that include/ and lib/<abi>/ sit directly under it); a vendored copy takes precedence over the download.

Installation

To use this plugin, add flutter_midi_pro using terminal or pubspec.yaml file.

flutter pub add flutter_midi_pro

Usage

Import flutter_midi_pro.dart and use the MidiPro class to access the plugin's functions. MidiPro class is a singleton class, so you can use the same instance of the class in your application.

import 'package:flutter_midi_pro/flutter_midi_pro.dart';
Initialize

The package does nothing until it is initialized: no audio engine is created and no audio stream is opened. Call init before using any other method.

final midiPro = MidiPro();
await midiPro.init();
// Optional tuning knobs (defaults shown):
// await midiPro.init(sampleRate: 44100, bufferSize: 64, polyphony: 64);

Calling init while already initialized throws a StateError (call dispose first to re-initialize), and calling any other method before init also throws a StateError. You can check the current state with midiPro.isInitialized.

Load SoundFont File

Use the loadSoundfontAsset, loadSoundfontFile or loadSoundfontData functions to load a SoundFont file. These functions return an integer value that represents the soundfont ID. You can use this ID to load instruments from the SoundFont file and play MIDI notes. These functions load the instrument at the given bank and program number to all channels (0-15). If you want to load a specific instrument, you can use the selectInstrument function. Up to 16 soundfonts can be loaded at the same time; call unloadSoundfont(sfId) to release one.

final soundfontId = await midiPro.loadSoundfontAsset(assetPath: 'assets/soundfont.sf2', bank: 0, program: 0);
List and Select Instruments

getPresets lists every instrument inside a loaded soundfont — ready to feed an instrument picker — and selectInstrument binds an instrument at the given bank and program to a specific channel.

final presets = await midiPro.getPresets(soundfontId); // [(bank, program, name), ...]
await midiPro.selectInstrument(sfId: soundfontId, channel: 0, bank: 0, program: 0);
Play and Stop Notes

Use the playNote function to play a MIDI note. The key is the MIDI note number (0-127) and the velocity is the volume of the note (0-127). stopNote stops it on the same channel.

midiPro.playNote(sfId: soundfontId, channel: 0, key: 60, velocity: 127);
midiPro.stopNote(sfId: soundfontId, channel: 0, key: 60);
Expression and Control
await midiPro.pitchBend(value: 12000, channel: 0, sfId: soundfontId); // 0-16383, 8192 = center
await midiPro.setPitchBendRange(semitones: 12, channel: 0, sfId: soundfontId);
await midiPro.channelPressure(pressure: 90, channel: 0, sfId: soundfontId); // aftertouch
await midiPro.setSustain(enabled: true, channel: 0, sfId: soundfontId);
await midiPro.controlChange(controller: 10, value: 30, channel: 0, sfId: soundfontId); // any MIDI CC
await midiPro.setMasterGain(1.5); // global volume, 1.0 = default
await midiPro.panic();            // instantly silence everything

sendMidiEvent accepts raw MIDI channel messages, which makes it easy to bridge hardware MIDI input straight into the synthesizer.

MIDI File Player (Android)

Play Standard MIDI Files through a loaded soundfont — with pitch-preserving tempo scaling for practice, seeking and looping. File channels 0-15 play on the target soundfont's channels, so instrument selection and expression controls apply to playback too.

await midiPro.loadMidiAsset(assetPath: 'assets/song.mid', sfId: soundfontId);
await midiPro.setMidiTempo(0.5); // half speed, same pitch
await midiPro.setMidiLoop(-1);   // loop forever
await midiPro.playMidi();        // pauseMidi() / stopMidi() / seekMidi(tick)
final state = await midiPro.getMidiPlayerState(); // status, position, BPM, PPQ

Currently Android-only; iOS/macOS throw an UNSUPPORTED error for these methods.

Dispose

Use the dispose function to shut the synthesizer down: it stops all notes, unloads all soundfonts and releases the audio engine. After disposing you can call init again to start a fresh session; this cycle can be repeated any number of times.

await midiPro.dispose();
Audio session (iOS)

On iOS you can control how the synthesizer coexists with other audio — keep background music playing, survive video/ad audio session takeovers, and play regardless of the ring/mute switch:

await midiPro.configureAudioSession(
  category: AudioSessionCategory.playback,
  mixWithOthers: true,
);

This is iOS-only and a no-op on Android/macOS. The plugin also recovers automatically from audio interruptions (calls, Siri, ads), route changes (headphones/Bluetooth) and media services resets on iOS/macOS.

Effects
await midiPro.setReverb(enabled: true, roomSize: 0.6, level: 0.9); // all platforms
await midiPro.setChorus(enabled: true);                            // Android only
await midiPro.setEqualizer(enabled: true, bassGain: 6, trebleGain: 3); // iOS/macOS only
await midiPro.setDelay(enabled: true, time: 0.3, wetDryMix: 30);       // iOS/macOS only
await midiPro.setDistortion(enabled: true, preset: DistortionPreset.multiDistortedFunk); // iOS/macOS only
Platform support
Feature Android iOS macOS
Notes, control change, pitch bend, aftertouch, master gain, panic ✅ ✅ ✅
Preset listing (getPresets) ✅ ✅ ✅
Reverb (setReverb) ✅ full parameters ✅ preset + level ✅ preset + level
Chorus (setChorus) ✅ — —
Equalizer / Delay / Distortion — ✅ ✅
Audio session config (configureAudioSession) — ✅ —
MIDI file player (loadMidiFile, playMidi, …) ✅ planned planned
init sampleRate/bufferSize/polyphony ✅ synth settings ✅ session preferences (no polyphony) —

Example

You can find a complete example in the example directory — an interactive playground covering the full lifecycle (init/dispose), soundfont loading, an instrument picker built on getPresets, a piano with pitch bend, master gain, effects and the MIDI file player.

Contributions

Contributions are welcome! Please feel free to submit a PR or open an issue.

Contact

If you have any questions or suggestions, feel free to contact the package maintainer, Melih Hakan Pektas, via email or through GitHub.

Melih Hakan Pektas

Thank you for contributing to flutter_midi_pro!

License

This project is licensed under the MIT License. See the LICENSE file for details.

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。