搜尋套件、儲存庫與 APP 分類

套件詳情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 是一個 Flutter 插件,透過 SoundFont (.sf2) 檔案實現音訊合成,允許使用者載入樂器、切換樂器並播放 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。