Skip to content

Commit

Permalink
fixed typing in android, better event type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Dante1349 committed May 31, 2022
1 parent ecdb847 commit 5c27c6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
25 changes: 12 additions & 13 deletions android/src/main/java/capacitormidi/MIDIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.getcapacitor.JSArray;
import com.getcapacitor.JSObject;
import com.getcapacitor.MessageHandler;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
Expand Down Expand Up @@ -47,21 +46,21 @@ public void openDevice(PluginCall call) {
JSObject midiMessage = new JSObject();

String rawType = String.valueOf(message.msg[1]);
int note = message.msg[2];
int velocity = message.msg[3];

String type = "";
switch(rawType) {
case "-112":
type = "NoteOn";
break;
case "-128":
type = "NoteOff";
break;
default:
type = "UNKNOWN - " + rawType;
break;
if ( rawType.equals("-112") && velocity != 0 ) {
type = "NoteOn";
} else if ( (rawType.equals("-128") || rawType.equals("-112")) && velocity == 0 ) {
type = "NoteOff";
} else {
type = "UNKNOWN - " + rawType;
}

midiMessage.put("type", type);
midiMessage.put("note", String.valueOf(message.msg[2]));
midiMessage.put("velocity", String.valueOf(message.msg[3]));
midiMessage.put("note", note);
midiMessage.put("velocity", velocity);

notifyListeners("MIDI_MSG_EVENT", midiMessage);
});
Expand Down
10 changes: 9 additions & 1 deletion android/src/main/java/capacitormidi/MidiMessageReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public MidiMessageReceiver(Consumer<MIDIDeviceMessage> consumer) {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onSend(byte[] msg, int offset, int count, long timestamp) throws IOException {
Log.i("MidiMessageReceiver", "msg: " + msg + ", offset: " + offset + ", count: " + count + ", timestamp: " + timestamp);
String message = "["
+String.valueOf(msg[0])+","
+String.valueOf(msg[1])+","
+String.valueOf(msg[2])+","
+String.valueOf(msg[3])+","
+String.valueOf(msg[4])+","
+String.valueOf(msg[5])+","
+"]";
Log.i("MidiMessageReceiver", "msg: " + message + ", offset: " + offset + ", count: " + count + ", timestamp: " + timestamp);
consumer.accept(new MIDIDeviceMessage(msg, offset, count, timestamp));
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-midi",
"version": "0.0.10",
"version": "0.0.11",
"description": "Grants access to midi devices via native libraries or WebMIDI.",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down

0 comments on commit 5c27c6b

Please sign in to comment.