f_link 0.2.4 f_link: ^0.2.4 copied to clipboard
A wrapper plugin for Ableton Link's C extension to be used with Flutter.
f_link is a Flutter wrapper of abl_link, which is a C 11 extension made by Ableton for their C++ codebase. This library attempts to be unopinionated and plain in copying the functionality of abl_link, while providing some high level convenience and safety.
Ableton Link is a technology that synchronizes musical beat, tempo, phase, and start/stop commands across multiple applications running on one or more devices. Applications on devices connected to a local network discover each other automatically and form a musical session in which each participant can perform independently: anyone can start or stop while still staying in time. Anyone can change the tempo, the others will follow. Anyone can join or leave without disrupting the session.
Android apps must declare their use of the network in the Android manifest in
android/src/main/AndroidManifest.xml. Add this permission request inside the
<uses-permission android:name="android.permission.INTERNET" />
Requires entitlements to be set to give the app network usage permissions. Add this key to
macos/Runner/DebugProfile.entitlements and to
- f_link currently wraps around all functions available in 'abl_link.h' and makes them publicly available. The destructors are implemented with NativeFinalizer, which should make manually destroying instances and freeing memory unnecessary.
- Function documentation has been copied almost 1:1 from 'abl_link.h' as it should still apply.
- Functions have been implemented as methods on either the
SessionStatestruct depending on which of the two the original C function uses as a primary parameter and what seemed to be the most intuitive.
- At this point, handling thread and realtime safety with Audio and App SessionStates is left up to the user, just like in the original library.
- Callbacks have been omitted from this library (see Known Issues).
Known Issues #
Audio Playback and Latency #
Audio playback and latency in Flutter requires some careful considerations as it is somewhat platform and integration dependent. Latency compensation would certainly need to be factored into the code either way.
Ableton recommends to handle audio Session States in a separate thread to minimize latency. This could potentially be achieved with isolates and maybe even by integrating another low level native library to handle playback. I am happy to receive feedback on this issue and I may update the example at some point with a possible solution.
No iOS support yet #
Registering callbacks with native code #
Callbacks are not implemented yet. Native callbacks are difficult to implement into the Dart event loop. Currently they could only safely be done with native ports, which I may attempt at some point. See this Issue for more details: https://github.com/dart-lang/sdk/issues/37022 . At this point the user has to implement a polling solutions instead of relying on callbacks (see Example).
NativeFinalizer should reliably destroy the native objects attached to AblLink and SessionState instances when they leave the current scope and become inaccessible. More investigations may be needed into the memory used by C++, to check if that reliably happens.
Pull requests and feedback in the discussions section is very welcome!
Ableton Link is dual licensed under GPLv2+ and a proprietary license.
This means that this wrapper is automatically under the GPLv2+ as well. A copy of the license is distributed with the source code.
If you would like to incorporate Link into a proprietary software application, please contact Ableton at email@example.com.
I also made an Ableton Link wrapper for Rust, called rusty_link, to learn about FFI wrapping before making this plugin.