Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stop note function #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.teplyakov.midiplayer">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="me.teplyakov.midiplayer">
</manifest>
4 changes: 4 additions & 0 deletions android/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ extern "C" JNIEXPORT void JNICALL Java_me_teplyakov_midiplayer_MidiPlayerPlugin_
fluid_synth_noteon(synthSingleton, 0, note, velocity);
}

extern "C" JNIEXPORT void JNICALL Java_me_teplyakov_midiplayer_MidiPlayerPlugin_fluidsynthStopNote(JNIEnv* env, jobject, jint note, jint velocity) {
fluid_synth_noteoff(synthSingleton, 0, note);
}

extern "C" JNIEXPORT void JNICALL Java_me_teplyakov_midiplayer_MidiPlayerPlugin_fluidsynthUnload(JNIEnv* env, jobject) {
// Clean up
delete_fluid_audio_driver(adriverSingleton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class MidiPlayerPlugin: FlutterPlugin, MethodCallHandler {

@JvmStatic
private external fun fluidsynthPlayNote(note: Int, velocity: Int)

@JvmStatic
private external fun fluidsynthStopNote(note: Int)

@JvmStatic
private external fun fluidsynthUnload()
Expand Down Expand Up @@ -49,6 +52,12 @@ class MidiPlayerPlugin: FlutterPlugin, MethodCallHandler {
if (note != null && velocity != null) {
fluidsynthPlayNote(note, velocity)
}
} else if (call.method == "stop_note") {
val args = call.arguments() as? Map<String, Any?>
val note = args?.get("note") as? Int
if (note != null) {
fluidsynthStopNote(note)
}
} else if (call.method == "dispose") {
fluidsynthUnload()
} else {
Expand Down
7 changes: 7 additions & 0 deletions ios/Classes/SwiftMidiPlayerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public class SwiftMidiPlayerPlugin: NSObject, FlutterPlugin {
let message = "Playing: \(String(describing: note))"
result(message)
}
case "stop_note":
if let args = call.arguments as? Dictionary<String, Any>,
let note = args["note"] as? Int {
au.stopPitch(midi: note)
let message = "Stopped: \(String(describing: note))"
result(message)
}
case "dispose":
result("done")
default:
Expand Down
9 changes: 9 additions & 0 deletions lib/midi_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ class MidiPlayer {
);
}

Future<void> stopNote({required int note}) {
return _channel.invokeMethod(
'stop_note',
{
'note': note,
},
);
}

/// Dispose engine
Future<void> dispose() {
return _channel.invokeMethod('dispose');
Expand Down