adding packages

This commit is contained in:
2026-01-15 14:38:46 -08:00
parent ef86e3ab6a
commit 6869cf47e5
5253 changed files with 726695 additions and 34 deletions
@@ -0,0 +1,16 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
Future<File?> writeToFile(ByteData data,
{String name = "instrument.sf2"}) async {
if (kIsWeb) return null;
final buffer = data.buffer;
final directory = await getApplicationDocumentsDirectory();
final path = "${directory.path}/$name";
return File(path)
.writeAsBytes(buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
}
@@ -0,0 +1,70 @@
import 'package:flutter/services.dart';
import 'platform_interface.dart';
const MethodChannel _channel = MethodChannel('flutter_midi');
class MethodChannelUrlLauncher extends FlutterMidiPlatform {
/// Needed so that the sound font is loaded
/// On iOS make sure to include the sound_font.SF2 in the Runner folder.
/// This does not work in the simulator.
@override
Future<String?> prepare({
required ByteData? sf2,
String name = 'instrument.sf2',
}) async {
return _channel.invokeMethod<String>('prepare_midi', {
'name': name,
'data': sf2,
});
}
/// Needed so that the sound font is loaded
/// On iOS make sure to include the sound_font.SF2 in the Runner folder.
/// This does not work in the simulator.
@override
Future<String?> changeSound({
required ByteData? sf2,
String name = 'instrument.sf2',
}) async {
return _channel.invokeMethod<String>('change_sound', {
'name': name,
'data': sf2,
});
}
/// Unmute the device temporarily even if the mute switch is on or toggled in settings.
@override
Future<String?> unmute() {
return _channel.invokeMethod<String>('unmute');
}
/// Use this when stopping the sound onTouchUp or to cancel a long file.
/// Not needed if playing midi onTap.
/// Stop with velocity in the range between 0-127
@override
Future<String?> stopMidiNote({
required int midi,
int velocity = 64,
}) {
return _channel.invokeMethod<String>('stop_midi_note', {
'note': midi,
'velocity': velocity,
});
}
/// Play a midi note from the sound_font.SF2 library bundled with the application.
/// Play a midi note in the range between 0-127
/// Play with velocity in the range between 0-127
/// Multiple notes can be played at once as separate calls.
@override
Future<String?> playMidiNote({
required int midi,
int velocity = 64,
}) {
return _channel.invokeMethod<String>('play_midi_note', {
'note': midi,
'velocity': velocity,
});
}
}
@@ -0,0 +1,63 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'method_channel.dart';
class FlutterMidiPlatform extends PlatformInterface {
FlutterMidiPlatform() : super(token: _token);
static final Object _token = Object();
static FlutterMidiPlatform _instance = MethodChannelUrlLauncher();
static FlutterMidiPlatform get instance => _instance;
static set instance(FlutterMidiPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
/// Needed so that the sound font is loaded
/// On iOS make sure to include the sound_font.SF2 in the Runner folder.
/// This does not work in the simulator.
Future<String?> prepare({
required ByteData? sf2,
String name = 'instrument.sf2',
}) async {
debugPrint('Setup Midi..');
throw UnimplementedError('prepare() has not been implemented.');
}
/// Needed so that the sound font is loaded
/// On iOS make sure to include the sound_font.SF2 in the Runner folder.
/// This does not work in the simulator.
Future<String?> changeSound({
required ByteData? sf2,
String name = 'instrument.sf2',
}) async {
throw UnimplementedError('changeSound() has not been implemented.');
}
/// Unmute the device temporarily even if the mute switch is on or toggled in settings.
Future<String?> unmute() async {
throw UnimplementedError('canLaunch() has not been implemented.');
}
/// Use this when stopping the sound onTouchUp or to cancel a long file.
/// Not needed if playing midi onTap.
/// Stop with velocity in the range between 0-127
Future<String?> stopMidiNote({
required int midi,
int velocity = 64,
}) async {
throw UnimplementedError('stopMidiNote() has not been implemented.');
}
/// Play a midi note from the sound_font.SF2 library bundled with the application.
/// Play a midi note in the range between 0-127
/// Play with velocity in the range between 0-127
/// Multiple notes can be played at once as separate calls.
Future<String?> playMidiNote({
required int midi,
int velocity = 64,
}) async {
throw UnimplementedError('playMidiNote() has not been implemented.');
}
}