diff --git a/modules/juce_audio_devices/native/java/app/com/rmsl/juce/JuceMidiSupport.java b/modules/juce_audio_devices/native/java/app/com/rmsl/juce/JuceMidiSupport.java index 6d203aac5b..887c0485c9 100644 --- a/modules/juce_audio_devices/native/java/app/com/rmsl/juce/JuceMidiSupport.java +++ b/modules/juce_audio_devices/native/java/app/com/rmsl/juce/JuceMidiSupport.java @@ -108,9 +108,9 @@ public class JuceMidiSupport appContext = contextToUse; } - public String[] getMidiBluetoothAddresses () + public List getMidiBluetoothAddresses() { - return bluetoothMidiDevices.toArray (new String[bluetoothMidiDevices.size ()]); + return new ArrayList (bluetoothMidiDevices); } public String getHumanReadableStringForBluetoothAddress (String address) @@ -216,7 +216,7 @@ public class JuceMidiSupport private BluetoothLeScanner scanner; private static final String bluetoothLEMidiServiceUUID = "03B80E5A-EDE8-4B33-A751-6CE34EC4C700"; - private HashSet bluetoothMidiDevices = new HashSet (); + private HashSet bluetoothMidiDevices = new HashSet<>(); private Context appContext = null; } diff --git a/modules/juce_audio_utils/native/juce_BluetoothMidiDevicePairingDialogue_android.cpp b/modules/juce_audio_utils/native/juce_BluetoothMidiDevicePairingDialogue_android.cpp index ebba727092..21227a87b6 100644 --- a/modules/juce_audio_utils/native/juce_BluetoothMidiDevicePairingDialogue_android.cpp +++ b/modules/juce_audio_utils/native/juce_BluetoothMidiDevicePairingDialogue_android.cpp @@ -42,7 +42,7 @@ DECLARE_JNI_CLASS (AndroidJuceMidiSupport, "com/rmsl/juce/JuceMidiSupport") #undef JNI_CLASS_MEMBERS #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ - METHOD (getMidiBluetoothAddresses, "getMidiBluetoothAddresses", "()[Ljava/lang/String;") \ + METHOD (getMidiBluetoothAddresses, "getMidiBluetoothAddresses", "()Ljava/util/List;") \ METHOD (pairBluetoothMidiDevice, "pairBluetoothMidiDevice", "(Ljava/lang/String;)Z") \ METHOD (unpairBluetoothMidiDevice, "unpairBluetoothMidiDevice", "(Ljava/lang/String;)V") \ METHOD (getHumanReadableStringForBluetoothAddress, "getHumanReadableStringForBluetoothAddress", "(Ljava/lang/String;)Ljava/lang/String;") \ @@ -58,7 +58,9 @@ struct AndroidBluetoothMidiInterface static void startStopScan (bool startScanning) { JNIEnv* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); if (btManager.get() != nullptr) env->CallVoidMethod (btManager.get(), AndroidBluetoothManager.startStopScan, (jboolean) (startScanning ? 1 : 0)); @@ -70,21 +72,22 @@ struct AndroidBluetoothMidiInterface JNIEnv* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); // if this is null then bluetooth is not enabled if (btManager.get() == nullptr) return {}; - jobjectArray jDevices = (jobjectArray) env->CallObjectMethod (btManager.get(), - AndroidBluetoothManager.getMidiBluetoothAddresses); - LocalRef devices (jDevices); + LocalRef jDevices { (jobjectArray) env->CallObjectMethod (btManager.get(), + AndroidBluetoothManager.getMidiBluetoothAddresses) }; - const int count = env->GetArrayLength (devices.get()); + const auto count = env->CallIntMethod (jDevices, JavaList.size); - for (int i = 0; i < count; ++i) + for (auto i = (decltype (count)) 0; i < count; ++i) { - LocalRef string ((jstring) env->GetObjectArrayElement (devices.get(), i)); + LocalRef string { (jstring) env->CallObjectMethod (jDevices, JavaList.get, i) }; retval.add (juceString (string)); } @@ -96,7 +99,9 @@ struct AndroidBluetoothMidiInterface { JNIEnv* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); if (btManager.get() == nullptr) return false; @@ -110,7 +115,9 @@ struct AndroidBluetoothMidiInterface { JNIEnv* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); if (btManager.get() != nullptr) env->CallVoidMethod (btManager.get(), AndroidBluetoothManager.unpairBluetoothMidiDevice, @@ -122,7 +129,9 @@ struct AndroidBluetoothMidiInterface { JNIEnv* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); if (btManager.get() == nullptr) return address; @@ -150,7 +159,9 @@ struct AndroidBluetoothMidiInterface { JNIEnv* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); if (btManager.get() == nullptr) return unpaired; @@ -520,7 +531,9 @@ bool BluetoothMidiDevicePairingDialogue::isAvailable() { auto* env = getEnv(); - LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); + LocalRef btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, + AndroidJuceMidiSupport.getAndroidBluetoothManager, + getAppContext().get())); return btManager != nullptr; }