SOUL Lang with Flutter and Dart:FFI

In the last year I have been using Flutter, a cross platform app development framework which is really cool. Somewhat similar to React Native, although instead of depending on native UI components, you write dart code using the Flutter library and it gets compiled to machine code. This lets it be very powerful, performant and flexible. If you haven’t seen Flutter before I’d recommend checking it out!

When I first heard about SOUL Lang when it was announced last year, I thought that creating a Flutter app with a SOUL audio backend would be an amazing way to create audio apps.

Now that the SOUL beta has been released I’m trying to have a go at integrating them together.

There is a feature in beta in Dart called Dart:FFI which lets you call C code directly from Dart, and this can be used in flutter apps. This seems like it could potentially be a great way to make the link between Flutter and SOUL.

There are 2 ideas I had for a useful first step to take:

  1. Take one of the standalone soul examples from SOUL/examples/standalone, compile it to C++ using the soul generate --cpp command, and try to call this from Flutter thought Dart:ffi
  2. Try to create something similar to the SOULPatchHostDemo in Flutter

Do either of these seem realistic?

I had a go at idea 1, and the first blocker I hit is the following?:

If I compile a SOUL file, for example ClassicRingtone.soul to a cpp file, i.e. ClassicRingtone.cpp, how can I actually use this cpp file to make sound?

The compiled file has a ClassicRingtone class, which has a render method.
Is the idea that you have to call the render method every so often (e.g. every 10ms) to generate the next chunk of data to send to the speakers?
If so, do you have any idea of a minimal setup for doing this, and how I could do this from Flutter and send the output to the device speakers? Or is the idea that I should be using JUCE to do that?

(I saw this talk at the years ADC about integrating JUCE with React Native, by creating a JUCE app with a react native app inside it, so perhaps the same is possible with Flutter, although I haven’t come across anyone else trying this yet.)

Or is the idea that I should include the SOUL command line tool directly in the project, and then call these tools from Flutter to platy a patch?

I think what would be most likely to work well (when flutter has the right functionality), is if you were to take the SOULPatchHostDemo JUCE project and use a UIViewComponent to embed the flutterview. Flutter Desktop is still very alpha AFAIK. Maybe one day this page will include details about how to embed the flutter view on desktop

I think there are probably several ways then you could communicate between dart and the parent JUCE app, the FFI stuff being one of them

Thanks for the help!
The link you sent is helpful, I’ll try go down the route of embedding the Flutter app inside SOULPatchHostDemo!

I was aiming to build an app for iOS / Android, so am not too worries about using Flutter desktop right now.

in that case I think SOULPatchHostDemo is the wrong choice because there are no SOUL dylibs for iOS (you’re not allowed to JIT compile code on iOS). I am not sure what the status of SOUL C++ export is, but I guess that is what you need to look into

C++ export is still in a bit of a state - it’s useable but the interface is ugly. I’m tidying it up at the moment, so expect it to change in the coming weeks.

Ahh ok, I guess I should hold off on the iOS front for now then. I’ll have a go at hosting Flutter in a Juce app to try and get some kind of music app going, then at a later date will work on integrating SOUL