Keep a reference to WrapperView in WrapperInner
This commit is contained in:
parent
8ddad4e893
commit
0675feb54b
|
@ -8,7 +8,8 @@ use vst3_sys::base::{kInvalidArgument, kResultOk, tresult};
|
||||||
use vst3_sys::vst::IComponentHandler;
|
use vst3_sys::vst::IComponentHandler;
|
||||||
|
|
||||||
use super::context::WrapperProcessContext;
|
use super::context::WrapperProcessContext;
|
||||||
use super::util::{VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID};
|
use super::util::{ObjectPtr, VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID};
|
||||||
|
use super::view::WrapperView;
|
||||||
use crate::buffer::Buffer;
|
use crate::buffer::Buffer;
|
||||||
use crate::context::{EventLoop, GuiContext, MainThreadExecutor, OsEventLoop};
|
use crate::context::{EventLoop, GuiContext, MainThreadExecutor, OsEventLoop};
|
||||||
use crate::param::internals::ParamPtr;
|
use crate::param::internals::ParamPtr;
|
||||||
|
@ -30,6 +31,10 @@ pub(crate) struct WrapperInner<P: Plugin> {
|
||||||
/// `IEditController::set_component_handler`.
|
/// `IEditController::set_component_handler`.
|
||||||
pub component_handler: RwLock<Option<VstPtr<dyn IComponentHandler>>>,
|
pub component_handler: RwLock<Option<VstPtr<dyn IComponentHandler>>>,
|
||||||
|
|
||||||
|
/// Our own [IPlugView] instance. This is set while the editor is actually visible (which is
|
||||||
|
/// different form the lifetimei of [super::WrapperView] itself).
|
||||||
|
pub plug_view: RwLock<Option<ObjectPtr<WrapperView<P>>>>,
|
||||||
|
|
||||||
/// A realtime-safe task queue so the plugin can schedule tasks that need to be run later on the
|
/// A realtime-safe task queue so the plugin can schedule tasks that need to be run later on the
|
||||||
/// GUI thread.
|
/// GUI thread.
|
||||||
///
|
///
|
||||||
|
@ -106,6 +111,8 @@ impl<P: Plugin> WrapperInner<P> {
|
||||||
|
|
||||||
component_handler: RwLock::new(None),
|
component_handler: RwLock::new(None),
|
||||||
|
|
||||||
|
plug_view: RwLock::new(None),
|
||||||
|
|
||||||
event_loop: RwLock::new(MaybeUninit::uninit()),
|
event_loop: RwLock::new(MaybeUninit::uninit()),
|
||||||
|
|
||||||
is_processing: AtomicBool::new(false),
|
is_processing: AtomicBool::new(false),
|
||||||
|
|
|
@ -64,6 +64,14 @@ impl<T: vst3_sys::ComInterface + ?Sized> From<vst3_sys::VstPtr<T>> for VstPtr<T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: IUnknown> From<&T> for ObjectPtr<T> {
|
||||||
|
/// Create a smart pointer for an existing reference counted object.
|
||||||
|
fn from(obj: &T) -> Self {
|
||||||
|
unsafe { obj.add_ref() };
|
||||||
|
Self { ptr: obj }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: IUnknown> Drop for ObjectPtr<T> {
|
impl<T: IUnknown> Drop for ObjectPtr<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { (*self).release() };
|
unsafe { (*self).release() };
|
||||||
|
@ -77,11 +85,3 @@ unsafe impl<T: ComInterface + ?Sized> Sync for VstPtr<T> {}
|
||||||
|
|
||||||
unsafe impl<T: IUnknown> Send for ObjectPtr<T> {}
|
unsafe impl<T: IUnknown> Send for ObjectPtr<T> {}
|
||||||
unsafe impl<T: IUnknown> Sync for ObjectPtr<T> {}
|
unsafe impl<T: IUnknown> Sync for ObjectPtr<T> {}
|
||||||
|
|
||||||
impl<T: IUnknown> ObjectPtr<T> {
|
|
||||||
/// Create a smart pointer for an existing reference counted object.
|
|
||||||
pub fn new(obj: &T) -> Self {
|
|
||||||
unsafe { obj.add_ref() };
|
|
||||||
Self { ptr: obj }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use vst3_sys::gui::{IPlugFrame, IPlugView};
|
||||||
use vst3_sys::VST3;
|
use vst3_sys::VST3;
|
||||||
|
|
||||||
use super::inner::WrapperInner;
|
use super::inner::WrapperInner;
|
||||||
use super::util::VstPtr;
|
use super::util::{ObjectPtr, VstPtr};
|
||||||
use crate::plugin::{Editor, Plugin};
|
use crate::plugin::{Editor, Plugin};
|
||||||
use crate::ParentWindowHandle;
|
use crate::ParentWindowHandle;
|
||||||
|
|
||||||
|
@ -117,6 +117,8 @@ impl<P: Plugin> IPlugView for WrapperView<P> {
|
||||||
self.editor
|
self.editor
|
||||||
.spawn(ParentWindowHandle { handle }, self.inner.clone()),
|
.spawn(ParentWindowHandle { handle }, self.inner.clone()),
|
||||||
);
|
);
|
||||||
|
*self.inner.plug_view.write() = Some(ObjectPtr::from(self));
|
||||||
|
|
||||||
kResultOk
|
kResultOk
|
||||||
} else {
|
} else {
|
||||||
kResultFalse
|
kResultFalse
|
||||||
|
@ -126,7 +128,9 @@ impl<P: Plugin> IPlugView for WrapperView<P> {
|
||||||
unsafe fn removed(&self) -> tresult {
|
unsafe fn removed(&self) -> tresult {
|
||||||
let mut editor_handle = self.editor_handle.write();
|
let mut editor_handle = self.editor_handle.write();
|
||||||
if editor_handle.is_some() {
|
if editor_handle.is_some() {
|
||||||
|
*self.inner.plug_view.write() = None;
|
||||||
*editor_handle = None;
|
*editor_handle = None;
|
||||||
|
|
||||||
kResultOk
|
kResultOk
|
||||||
} else {
|
} else {
|
||||||
kResultFalse
|
kResultFalse
|
||||||
|
|
Loading…
Reference in a new issue