RustAudio / vst3-sys

Raw Bindings to the VST3 API
Other
284 stars 18 forks source link

Rework the smart pointers and drop cruft #45

Closed robbert-vdh closed 2 years ago

robbert-vdh commented 2 years ago

These are the changes I mentioned in the Discord. The idea is to have VstPtr<T> mirror the VST3 SDK's Steinberg::IPtr<T>, but with clearer ownership semantics. This is explained in slightly more depth in the doc comment on VstPtr, but the short version is that VstPtr::owned() should be used with functions that return an object instance so the caller has ownership over the object, and VstPtr::shared() should be used with objects that are shared with the callee as a function argument. Lifetime management then works exactly the same as with a regular Arc<T>. There is also a RawVstPtr<T> with a corresponding StaticVstPtr<T> argument type for the FFI compatibility that doesn't do any lifetime management. This was needed because JUCE based hosts will segfault as soon as a parameter value queue is released once, no matter how many references were added before that point. The other changes made are:

m-hilgendorf commented 2 years ago

Thank you, @robbert-vdh !