Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:8.9.1'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 28
namespace 'com.appleeducate.fluttermidi'
compileSdk 35

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 35
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand All @@ -38,4 +38,4 @@ android {

dependencies {
implementation 'com.github.appleeducate:MidiDriver-Android-SF2:1.0'
}
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.appleeducate.fluttermidi;

import android.content.Context;

import androidx.annotation.NonNull;

import cn.sherlock.com.sun.media.sound.SF2Soundbank;
import cn.sherlock.com.sun.media.sound.SoftSynthesizer;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
Expand All @@ -10,109 +13,111 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.BinaryMessenger;

import java.io.File;
import java.io.IOException;

import jp.kshoji.javax.sound.midi.InvalidMidiDataException;
import jp.kshoji.javax.sound.midi.MidiUnavailableException;
import jp.kshoji.javax.sound.midi.Receiver;
import jp.kshoji.javax.sound.midi.ShortMessage;

/** FlutterMidiPlugin */
/**
* FlutterMidiPlugin
*/
public class FlutterMidiPlugin implements MethodCallHandler, FlutterPlugin {
private SoftSynthesizer synth;
private Receiver recv;
private MethodChannel methodChannel;
private Context applicationContext;
private SoftSynthesizer synth;
private Receiver recv;
private MethodChannel methodChannel;
private Context applicationContext;

/** Plugin registration. */
@SuppressWarnings("deprecation")
public static void registerWith(Registrar registrar) {
final FlutterMidiPlugin instance = new FlutterMidiPlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}
/**
* Plugin registration.
*/
@SuppressWarnings("deprecation")
public static void registerWith(Registrar registrar) {
final FlutterMidiPlugin instance = new FlutterMidiPlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
}
@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
}

/*
"Also, note that the plugin should still contain the static registerWith() method
to remain compatible with apps that don’t use the v2 Android embedding.
(See Upgrading pre 1.12 Android projects for details.) The easiest thing to
do (if possible) is move the logic from registerWith() into a private method that
both registerWith() and onAttachedToEngine() can call. Either registerWith() or
onAttachedToEngine() will be called, not both."
/*
"Also, note that the plugin should still contain the static registerWith() method
to remain compatible with apps that don’t use the v2 Android embedding.
(See Upgrading pre 1.12 Android projects for details.) The easiest thing to
do (if possible) is move the logic from registerWith() into a private method that
both registerWith() and onAttachedToEngine() can call. Either registerWith() or
onAttachedToEngine() will be called, not both."

- https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration
*/
private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
methodChannel = new MethodChannel(messenger, "flutter_midi");
methodChannel.setMethodCallHandler(new FlutterMidiPlugin());
}
- https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration
*/
private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
methodChannel = new MethodChannel(messenger, "flutter_midi");
methodChannel.setMethodCallHandler(new FlutterMidiPlugin());
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
applicationContext = null;
methodChannel.setMethodCallHandler(null);
methodChannel = null;
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
applicationContext = null;
methodChannel.setMethodCallHandler(null);
methodChannel = null;
}

@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("prepare_midi")) {
try {
String _path = call.argument("path");
File _file = new File(_path);
SF2Soundbank sf = new SF2Soundbank(_file);
synth = new SoftSynthesizer();
synth.open();
synth.loadAllInstruments(sf);
synth.getChannels()[0].programChange(0);
synth.getChannels()[1].programChange(1);
recv = synth.getReceiver();
} catch (IOException e) {
e.printStackTrace();
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
} else if (call.method.equals("change_sound")) {
try {
String _path = call.argument("path");
File _file = new File(_path);
SF2Soundbank sf = new SF2Soundbank(_file);
synth = new SoftSynthesizer();
synth.open();
synth.loadAllInstruments(sf);
synth.getChannels()[0].programChange(0);
synth.getChannels()[1].programChange(1);
recv = synth.getReceiver();
} catch (IOException e) {
e.printStackTrace();
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
} else if (call.method.equals("play_midi_note")) {
int _note = call.argument("note");
int _velocity = call.argument("velocity");
try {
ShortMessage msg = new ShortMessage();
msg.setMessage(ShortMessage.NOTE_ON, 0, _note, _velocity);
recv.send(msg, -1);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
}
} else if (call.method.equals("stop_midi_note")) {
int _note = call.argument("note");
int _velocity = call.argument("velocity");
try {
ShortMessage msg = new ShortMessage();
msg.setMessage(ShortMessage.NOTE_OFF, 0, _note, _velocity);
recv.send(msg, -1);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
}
} else {
@Override
public void onMethodCall(MethodCall call, @NonNull Result result) {
switch (call.method) {
case "prepare_midi":
case "change_sound":
try {
String _path = call.argument("path");
File _file = new File(_path);
SF2Soundbank sf = new SF2Soundbank(_file);
synth = new SoftSynthesizer();
synth.open();
synth.loadAllInstruments(sf);
synth.getChannels()[0].programChange(0);
synth.getChannels()[1].programChange(1);
recv = synth.getReceiver();
result.success(null);
} catch (IOException | MidiUnavailableException e) {
e.printStackTrace();
result.error(e.getMessage(), null, null);
}
break;
case "play_midi_note": {
int _note = call.argument("note");
int _velocity = call.argument("velocity");
try {
ShortMessage msg = new ShortMessage();
msg.setMessage(ShortMessage.NOTE_ON, 0, _note, _velocity);
recv.send(msg, -1);
result.success(null);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
result.error(e.getMessage(), null, null);
}
break;
}
case "stop_midi_note": {
int _note = call.argument("note");
int _velocity = call.argument("velocity");
try {
ShortMessage msg = new ShortMessage();
msg.setMessage(ShortMessage.NOTE_OFF, 0, _note, _velocity);
recv.send(msg, -1);
result.success(null);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
result.error(e.getMessage(), null, null);
}
break;
}
default:
break;
}
}
}
}
1 change: 1 addition & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ gradle-wrapper.jar
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
.cxx
49 changes: 11 additions & 38 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
plugins {
id "com.android.application"
id "dev.flutter.flutter-gradle-plugin"
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
compileSdkVersion 35

lintOptions {
disable 'InvalidPackage'
Expand All @@ -39,10 +13,10 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
minSdkVersion 21
targetSdkVersion 35
versionCode flutter.versionCode
versionName flutter.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand All @@ -60,8 +34,7 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.6.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}
17 changes: 2 additions & 15 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand All @@ -26,6 +13,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
1 change: 0 additions & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
6 changes: 3 additions & 3 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Wed Jan 31 00:12:58 IST 2024
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
zipStoreBase=GRADLE_USER_HOME
Loading