flutter_midi_pro 1.0.5
flutter_midi_pro: ^1.0.5 copied to clipboard
The `flutter_midi_pro` plugin provides functions for loading SoundFont (.sf2) files, as well as playing and stopping MIDI notes.
flutter_midi_pro #
The flutter_midi_pro
plugin provides functions for loading SoundFont (.sf2) files, as well as playing and stopping MIDI notes.
Installation #
To use this plugin, add flutter_midi_pro
as a dependency in your pubspec.yaml file. For example:
dependencies:
flutter_midi_pro: ^1.0.0
Usage #
Import flutter_midi_pro.dart
and use the MidiPro
class to access the plugin's functions.
import 'package:flutter_midi_pro/flutter_midi_pro.dart';
Create a MidiPro Variable #
final _midiPro = MidiPro();
Load SoundFont File #
Use the loadSoundfont
function to load a SoundFont file with sf2 path and a specified name in initState.
void initState() {
_midiPro.loadSoundfont(sf2Path: _sf2Path);
super.initState();
}
Play MIDI Note #
Use the playMidiNote
function to play a MIDI note with a given MIDI value and velocity.
play(int midi, {int velocity = 127}) {
_midiPro.playMidiNote(midi: midi, velocity: velocity);
}
Stop MIDI Note #
Use the stopMidiNote
function to stop a MIDI note with a given MIDI number and velocity.
void stop(int midi) {
_midiPro.stopMidiNote(midi: midi);
}
Example #
Here's an example of how you could use the flutter_midi_pro
plugin to play a piano using a SoundFont file and using the flutter_piano_pro
:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_midi_pro/flutter_midi_pro.dart';
import 'package:flutter_piano_pro/flutter_piano_pro.dart';
import 'package:flutter_piano_pro/note_model.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _midiPro = MidiPro();
final String _sf2Path = 'assets/tight_piano.sf2';
Map<int, NoteModel> pointerAndNote = {};
void play(int midi, {int velocity = 127}) {
_midiPro.playMidiNote(midi: midi, velocity: velocity);
}
void stop(int midi) {
_midiPro.stopMidiNote(midi: midi);
}
@override
void initState() {
_midiPro.loadSoundfont(sf2Path: _sf2Path);
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter Midi Pro Example'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
PianoPro(
noteCount: 15,
onTapDown: (NoteModel? note, int tapId) {
if (note == null) return;
play(note.midiNoteNumber);
setState(() => pointerAndNote[tapId] = note);
},
onTapUpdate: (NoteModel? note, int tapId) {
if (note == null) return;
if (pointerAndNote[tapId] == note) return;
stop(pointerAndNote[tapId]!.midiNoteNumber);
play(note.midiNoteNumber);
pointerAndNote[tapId] = note;
},
onTapUp: (int tapId) {
stop(pointerAndNote[tapId]!.midiNoteNumber);
pointerAndNote.remove(tapId);
},
)
],
)),
),
);
}
}
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.
Thank you for contributing to flutter_piano_pro!
License #
This project is licensed under the MIT License. See the LICENSE file for details.