RustAudio / rust-lv2

A safe, fast, and modular framework to create LV2 plugins, written in Rust
Apache License 2.0
171 stars 23 forks source link

Provide number of samples in plugin run method #87

Closed niclashoyer closed 4 years ago

niclashoyer commented 4 years ago

The number of samples is not explicitly passed to the rust lv2 run method, while the original method has this information:

unsafe extern "C" fn run(instance: *mut c_void, sample_count: u32)

Is there some way to get the sample count in the plugins run method? I know that if I have an audio port I can get it using the buffer length, but I'm having a somewhat special case. I'm implementing a plugin with just two atom ports (MIDI events) and still need to do frame accurate timing (in this case sequencing). How would I go about that?

niclashoyer commented 4 years ago

I experimented a bit. At first I thought it would suffice to just add sample_count as a field to atom ports, but this got complicated. This change is more like the run method in the lv2 reference implementation, just pass the sample_count as last parameter. Then plugin implementations can use it to calculate frame accurate things, or just ignore it.

JOOpdenhoevel commented 4 years ago

I knew that the sample_count isn't passed as an argument of the run method and knew that there were a reason why we didn't add it, but I don't remember it anymore.

That's an interesting use case you've got there and there really is no way you can get the sample count. I will accept your PR.