1
0
Fork 0

Also perform resize requests using the run loop

This commit is contained in:
Robbert van der Helm 2022-04-20 19:52:02 +02:00
parent 98924a5728
commit 5d343f7873
3 changed files with 23 additions and 11 deletions

View file

@ -30,10 +30,12 @@ pub(crate) struct WrapperProcessContext<'a, P: Vst3Plugin> {
impl<P: Vst3Plugin> GuiContext for WrapperGuiContext<P> {
fn request_resize(&self) -> bool {
match &*self.inner.plug_view.read() {
Some(plug_view) => plug_view.request_resize(),
None => false,
}
let task_posted = self.inner.do_maybe_async(Task::RequestResize);
nih_debug_assert!(task_posted, "The task queue is full, dropping task...");
// TODO: We don't handle resize request failures right now. In practice this should however
// not happen.
true
}
// All of these functions are supposed to be called from the main thread, so we'll put some

View file

@ -139,6 +139,9 @@ pub enum Task {
/// Trigger a restart with the given restart flags. This is a bit set of the flags from
/// [`vst3_sys::vst::RestartFlags`].
TriggerRestart(i32),
/// Request the editor to be resized according to its current size. Right now there is no way to
/// handle denied resize requestsyet.
RequestResize,
}
/// VST3 makes audio processing pretty complicated. In order to support both block splitting for
@ -479,6 +482,12 @@ impl<P: Vst3Plugin> MainThreadExecutor<Task> for WrapperInner<P> {
}
None => nih_debug_assert_failure!("Component handler not yet set"),
},
Task::RequestResize => match &*self.plug_view.read() {
Some(plug_view) => {
plug_view.request_resize();
}
None => nih_debug_assert_failure!("Can't resize a closed editor"),
},
}
}
}

View file

@ -107,8 +107,12 @@ impl<P: Vst3Plugin> WrapperView<P> {
}
/// Ask the host to resize the view to the size specified by [Editor::size()]. Will return false
/// if the host doesn't like you.
pub fn request_resize(&self) -> bool {
/// if the host doesn't like you. This **needs** to be run from the GUI thread.
///
/// # Safety
///
/// May cause memory corruption in Linux REAPER when called from outside of the `IRunLoop`.
pub unsafe fn request_resize(&self) -> bool {
// Don't do anything if the editor is not open, because that would be strange
if self
.editor_handle
@ -131,11 +135,8 @@ impl<P: Vst3Plugin> WrapperView<P> {
// The argument types are a bit wonky here because you can't construct a
// `SharedVstPtr`. This _should_ work however.
// FIXME: Run this in the `IRonLoop` on Linux. Otherwise REAPER will be very cross
// with us.
let plug_view: SharedVstPtr<dyn IPlugView> =
unsafe { mem::transmute(self.__iplugviewvptr) };
let result = unsafe { plug_frame.resize_view(plug_view, &mut size) };
let plug_view: SharedVstPtr<dyn IPlugView> = mem::transmute(self.__iplugviewvptr);
let result = plug_frame.resize_view(plug_view, &mut size);
result == kResultOk
}