Allow negotiation of BLE MTU size

Hello,

I would like to be able to call gatt.requestMtu(int mtu) upon device connection inside JuceMidiSupport.java. However, I cannot seem to get the instructions here to work properly for debugging. Perhaps I missed some documentation somewhere. Can this feature please be added to JUCE? I am happy to make a request in the Github repo if that is the proper workflow.

4 Likes

For anyone wondering, you can make this change by:

  1. In juce_android_Midi.cpp, change

DECLARE_JNI_CLASS_WITH_BYTECODE (JuceMidiSupport, "com/rmsl/juce/JuceMidiSupport", 23, javaMidiByteCode)

to

DECLARE_JNI_CLASS_WITH_MIN_SDK (JuceMidiSupport, "com/rmsl/juce/JuceMidiSupport", 23)

  1. Rename the folder juce_audio_devices/native/java to juce_audio_devices/native/javacore/

  2. Add the new folder to the sourceSets inside build.gradle

    sourceSets {
        main.java.srcDirs +=
            ["../../../submodules/JUCE/modules/juce_core/native/javacore/init",
             "../../../submodules/JUCE/modules/juce_core/native/javacore/app",
             "../../../submodules/JUCE/modules/juce_gui_basics/native/javaopt/app",
             "../../../submodules/JUCE/modules/juce_audio_devices/native/javacore/app"
            ]
  1. In JuceMidiSupport.java, add your new code:
            public void onConnectionStateChange (BluetoothGatt gatt, int status, int newState)
            {
                if (newState == BluetoothProfile.STATE_CONNECTED)
                {
                    gatt.requestConnectionPriority (BluetoothGatt.CONNECTION_PRIORITY_HIGH);
                    gatt.requestMtu(517); // Add your request here
                    owner.pairBluetoothDeviceStepTwo (gatt.getDevice ());
                }
            }

You should get a callback here:

            public void onMtuChanged (BluetoothGatt gatt, int mtu, int status) {
                Log.d ("JUCE", "MTU Changed to: " + mtu);
            }

Would be lovely to see this option enabled from within the Projucer!