grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.59k stars 323 forks source link

Rust: Any way to access 'self' in an ffunction? #1045

Closed PolyVector closed 4 months ago

PolyVector commented 4 months ago

Hiya, I'm trying to add sampling capabilities using a foreign function to an audio plugin that uses the Rust backend:

readAudioSample = ffunction(float read_audio_sample(float), "", "");

But I can't see any valid way of declaring it to be called with self, like self.read_audio_sample(). I'd like to access sample data without resorting to static variables if that's possible.

sletz commented 4 months ago

The ffunction primitive has never been worked out in the Rust backend. Can you provide a minimal test with the currently generated code and the one you would like to have ? Thanks.

PolyVector commented 4 months ago

You know, thinking about it... I wouldn't be able to add member variables to the generated struct to store sampler data, so having a member method wouldn't actually help me here. Maybe what I'm asking doesn't make sense, I'll have to think on this.

sletz commented 4 months ago

What about using the soundfile primitive ?

PolyVector commented 4 months ago

I don't think soundfile is supported in the Rust backend yet. Ideally I'd like to be able to call into arbitrary plugin functions from the generated DSP, but to be honest I can't think of a practical use case beyond what soundfile would provide.

If needed I could probably write a Rust macro to add custom functionality to the generated code. I just need to learn how to do that 😄

Edit: I realize I'm rambling at this point, feel free to close this. I appreciate your help @sletz :)

sletz commented 4 months ago

Then if needed soundfile would be have to be added sure...