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
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 28

namespace 'com.appleeducate.fluttermidi'

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
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;
Expand All @@ -24,31 +23,11 @@ public class FlutterMidiPlugin implements MethodCallHandler, FlutterPlugin {
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());
}

@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."

- 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());
this.applicationContext = binding.getApplicationContext();
methodChannel = new MethodChannel(binding.getBinaryMessenger(), "flutter_midi");
methodChannel.setMethodCallHandler(this);
}

@Override
Expand All @@ -60,8 +39,8 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {

@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("prepare_midi")) {
try {
try {
if (call.method.equals("prepare_midi")) {
String _path = call.argument("path");
File _file = new File(_path);
SF2Soundbank sf = new SF2Soundbank(_file);
Expand All @@ -71,13 +50,8 @@ public void onMethodCall(MethodCall call, Result result) {
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 {
result.success(null);
} else if (call.method.equals("change_sound")) {
String _path = call.argument("path");
File _file = new File(_path);
SF2Soundbank sf = new SF2Soundbank(_file);
Expand All @@ -87,32 +61,32 @@ public void onMethodCall(MethodCall call, Result result) {
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 {
result.success(null);
} else if (call.method.equals("play_midi_note")) {
int _note = call.argument("note");
int _velocity = call.argument("velocity");
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 {
result.success(null);
} else if (call.method.equals("stop_midi_note")) {
int _note = call.argument("note");
int _velocity = call.argument("velocity");
ShortMessage msg = new ShortMessage();
msg.setMessage(ShortMessage.NOTE_OFF, 0, _note, _velocity);
recv.send(msg, -1);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
result.success(null);
} else {
result.notImplemented();
}
} else {
} catch (IOException e) {
result.error("IO_ERROR", "Failed to load soundbank: " + e.getMessage(), null);
} catch (MidiUnavailableException e) {
result.error("MIDI_UNAVAILABLE", "MIDI synthesizer unavailable: " + e.getMessage(), null);
} catch (InvalidMidiDataException e) {
result.error("INVALID_MIDI_DATA", "Invalid MIDI data: " + e.getMessage(), null);
} catch (Exception e) {
result.error("UNKNOWN_ERROR", "An unexpected error occurred: " + e.getMessage(), null);
}
}
}
7 changes: 3 additions & 4 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
Expand All @@ -26,14 +29,10 @@
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

Expand Down
39 changes: 37 additions & 2 deletions example/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,42 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 77512a3c46ec447cc64bac959e3043c2f0bdd446
channel: master
revision: "be698c48a6750c8cb8e61c740ca9991bb947aba2"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
- platform: android
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
- platform: ios
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
- platform: linux
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
- platform: macos
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
- platform: web
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
- platform: windows
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
12 changes: 6 additions & 6 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# flutter_midi_example
# example

Demonstrates how to use the flutter_midi plugin.
A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.io/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.io/docs/cookbook)
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.io/docs), which offers tutorials,
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
28 changes: 28 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
7 changes: 7 additions & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ gradle-wrapper.jar
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
.cxx/

# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
key.properties
**/*.keystore
**/*.jks
67 changes: 0 additions & 67 deletions example/android/app/build.gradle

This file was deleted.

44 changes: 44 additions & 0 deletions example/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}

android {
namespace = "com.example.example"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}

flutter {
source = "../.."
}
6 changes: 3 additions & 3 deletions example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
<!-- Flutter needs it to communicate with the running application
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
Expand Down
Loading