Finish switching from vst3-sys to vst3#263
Finish switching from vst3-sys to vst3#263davemollen wants to merge 11 commits intorobbert-vdh:masterfrom
Conversation
src/wrapper/vst3/view.rs
Outdated
| .spawn(parent_handle, self.inner.clone().make_gui_context()), | ||
| ); | ||
| *self.inner.plug_view.write() = Some(ObjectPtr::from(self)); | ||
| // *self.inner.plug_view.write() = Some(ObjectPtr::from(self)); |
There was a problem hiding this comment.
A solution still needs to be found for this line. A direct equivalent of ObjectPtr::from(self) is not possible with the vst3 crate.
There was a problem hiding this comment.
I don't really know how this should be handled. So I will keep this open.
There was a problem hiding this comment.
I have taken a look. And I think I have found a working solution.
I think the plug_view field on the WrapperInner struct doesn't have to be set and cleared in the attached and removed function on the IPlugViewTrait. As far as I can tell it merely functions as a way to tell if the editor is open or not. So I store an is_editor_open atomic bool on WrapperInner instead and set that in the attached and removed function. The plug_view field can then be set when createView is called on IEditController.
I know you're short on time @micahrj, but greatly appreciated if you could take a look.
src/wrapper/vst3/view.rs
Outdated
| .map(|run_loop| RunLoopEventHandler::new(self.inner.clone(), run_loop)); | ||
| } | ||
| *self.plug_frame.write() = Some(VstPtr::from(frame)); | ||
| // *self.plug_frame.write() = Some(ComPtr::from(frame)); |
There was a problem hiding this comment.
Another line that still needs to be updated.
There was a problem hiding this comment.
This was actually straightforward
src/wrapper/vst3/view.rs
Outdated
| tasks: ArrayQueue::new(TASK_QUEUE_CAPACITY), | ||
| }); | ||
|
|
||
| let handler_ptr = &*handler as *const _ as *mut _; |
There was a problem hiding this comment.
This is not going to work at all. You can't just allocate a Box<RunLoopEventHandler> and then do an unsafe pointer cast to *mut IEventHandler.
The use of #[VST3(implements(IEventHandler))] above RunLoopEventHandler needs to be replaced with impl Class for RunLoopEventHandler, and the RunLoopEventHandler needs to be allocated with ComWrapper.
There was a problem hiding this comment.
I was afraid this wouldn't make much sense. Didn't really notice this in testing though.
There was a problem hiding this comment.
I applied your suggested changes here. Getting access to the IEventHandler pointer for the unregisterEventHandler call was a bit fiddly. Curious to hear if this looks right to you.
It feels a bit strange to store the ComPtr on the struct it's also pointing to, but don't know what other pattern could be used.
There was a problem hiding this comment.
This is basically the right solution, yeah. This is due to a limitation in the vst3 crate where there is no good way to get an interface pointer (e.g. *mut IEventHandler) directly from &self.
However, I have a couple points of feedback:
RwLockis not necessary here. TheIRunLoopandIEventHandlerinterfaces are restricted to being used on the main thread, soCellshould suffice.- Storing an actual
ComPtrwill result in a reference cycle, which means that theRunLoopEventHandlerwill never get dropped. Instead, you should just store a raw*mut IEventHandler.
There was a problem hiding this comment.
I followed up on these instructions. Thanks for guiding me to the right solution!
I was afraid of the reference cycle. Good to know this prevents that.
dd5c1dc to
76c5fb2
Compare
Switch from the vst3-sys crate to the vst3 crate. With this change VST3 plugins built with NIH-plug no longer depend on the GPLv3 license.
Changes: