diff --git a/src/wrapper/clap/context.rs b/src/wrapper/clap/context.rs
index 67e182f4..e6b0a27d 100644
--- a/src/wrapper/clap/context.rs
+++ b/src/wrapper/clap/context.rs
@@ -12,9 +12,7 @@ use crate::midi::NoteEvent;
use crate::params::internals::ParamPtr;
use crate::plugin::ClapPlugin;
-/// A [`InitContext`] implementation for the wrapper. This is a separate object so it can hold on
-/// to lock guards for event queues. Otherwise reading these events would require constant
-/// unnecessary atomic operations to lock the uncontested RwLocks.
+/// An [`InitContext`] implementation for the wrapper.
pub(crate) struct WrapperInitContext<'a, P: ClapPlugin> {
pub(super) wrapper: &'a Wrapper
,
}
diff --git a/src/wrapper/standalone/context.rs b/src/wrapper/standalone/context.rs
index 72ed7a46..bcb45965 100644
--- a/src/wrapper/standalone/context.rs
+++ b/src/wrapper/standalone/context.rs
@@ -12,9 +12,7 @@ use crate::midi::NoteEvent;
use crate::params::internals::ParamPtr;
use crate::plugin::Plugin;
-/// A [`InitContext`] implementation for the standalone wrapper. This is a separate object so it
-/// can hold on to lock guards for event queues. Otherwise reading these events would require
-/// constant unnecessary atomic operations to lock the uncontested RwLocks.
+/// An [`InitContext`] implementation for the standalone wrapper.
pub(crate) struct WrapperInitContext<'a, P: Plugin, B: Backend> {
pub(super) wrapper: &'a Wrapper
,
}
diff --git a/src/wrapper/vst3/context.rs b/src/wrapper/vst3/context.rs
index e42cab99..e9efc50f 100644
--- a/src/wrapper/vst3/context.rs
+++ b/src/wrapper/vst3/context.rs
@@ -1,4 +1,5 @@
use atomic_refcell::AtomicRefMut;
+use std::cell::Cell;
use std::collections::VecDeque;
use std::sync::atomic::Ordering;
use std::sync::Arc;
@@ -14,11 +15,26 @@ use crate::params::internals::ParamPtr;
use crate::plugin::Vst3Plugin;
use crate::wrapper::state::PluginState;
-/// A [`InitContext`] implementation for the wrapper. This is a separate object so it can hold on to
-/// lock guards for event queues. Otherwise reading these events would require constant unnecessary
-/// atomic operations to lock the uncontested locks.
+/// An [`InitContext`] implementation for the wrapper.
+///
+/// # Note
+///
+/// Requests to change the latency are only sent when this object is dropped. Otherwise there's the
+/// risk that the host will immediately deactivate/reactivate the plugin while still in the init
+/// call. Reentrannt function calls are difficult to handle in Rust without forcing everything to
+/// use interior mutability, so this will have to do for now. This does mean that `Plugin` mutex
+/// lock has to be dropped before this object.
pub(crate) struct WrapperInitContext<'a, P: Vst3Plugin> {
pub(super) inner: &'a WrapperInner
,
+ pub(super) pending_requests: PendingInitContextRequests,
+}
+
+/// Any requests that should be sent out when the [`WrapperInitContext`] is dropped. See that
+/// struct's docstring for mroe information.
+#[derive(Debug, Default)]
+pub(crate) struct PendingInitContextRequests {
+ /// The value of the last `.set_latency_samples()` call.
+ latency_changed: Cell