From b1f24bfad964fd5d5355c01b8df355f12e4bfbd6 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm <mail@robbertvanderhelm.nl> Date: Sat, 22 Oct 2022 13:13:08 +0200 Subject: [PATCH] Reorder Context methods --- src/context.rs | 12 ++++++------ src/wrapper/clap/context.rs | 16 ++++++++-------- src/wrapper/standalone/context.rs | 16 ++++++++-------- src/wrapper/vst3/context.rs | 16 ++++++++-------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/context.rs b/src/context.rs index 4c703392..9e6371bd 100644 --- a/src/context.rs +++ b/src/context.rs @@ -16,6 +16,9 @@ use crate::wrapper::state::PluginState; // The implementing wrapper needs to be able to handle concurrent requests, and it should perform // the actual callback within [MainThreadQueue::do_maybe_async]. pub trait InitContext<P: Plugin> { + /// Get the current plugin API. + fn plugin_api(&self) -> PluginApi; + /// Run a task directly on this thread. This ensures that the task has finished executing before /// the plugin finishes initializing. /// @@ -25,9 +28,6 @@ pub trait InitContext<P: Plugin> { /// behavior when doing offline rendering. fn execute(&self, task: P::BackgroundTask); - /// Get the current plugin API. - fn plugin_api(&self) -> PluginApi; - /// Update the current latency of the plugin. If the plugin is currently processing audio, then /// this may cause audio playback to be restarted. fn set_latency_samples(&self, samples: u32); @@ -51,6 +51,9 @@ pub trait InitContext<P: Plugin> { // The implementing wrapper needs to be able to handle concurrent requests, and it should perform // the actual callback within [MainThreadQueue::do_maybe_async]. pub trait ProcessContext<P: Plugin> { + /// Get the current plugin API. + fn plugin_api(&self) -> PluginApi; + /// Run a task on a background thread. This allows defering expensive background tasks for /// alter. As long as creating the `task` is realtime-safe, this operation is too. /// @@ -61,9 +64,6 @@ pub trait ProcessContext<P: Plugin> { /// your task executor. fn execute_async(&self, task: P::BackgroundTask); - /// Get the current plugin API. - fn plugin_api(&self) -> PluginApi; - /// Get information about the current transport position and status. fn transport(&self) -> &Transport; diff --git a/src/wrapper/clap/context.rs b/src/wrapper/clap/context.rs index f3ad795e..89789d28 100644 --- a/src/wrapper/clap/context.rs +++ b/src/wrapper/clap/context.rs @@ -114,14 +114,14 @@ impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> { } impl<P: ClapPlugin> InitContext<P> for WrapperInitContext<'_, P> { - fn execute(&self, task: P::BackgroundTask) { - (self.wrapper.task_executor.lock())(task); - } - fn plugin_api(&self) -> PluginApi { PluginApi::Clap } + fn execute(&self, task: P::BackgroundTask) { + (self.wrapper.task_executor.lock())(task); + } + fn set_latency_samples(&self, samples: u32) { self.wrapper.set_latency_samples(samples) } @@ -132,15 +132,15 @@ impl<P: ClapPlugin> InitContext<P> for WrapperInitContext<'_, P> { } impl<P: ClapPlugin> ProcessContext<P> for WrapperProcessContext<'_, P> { + fn plugin_api(&self) -> PluginApi { + PluginApi::Clap + } + fn execute_async(&self, task: P::BackgroundTask) { let task_posted = self.wrapper.do_maybe_async(Task::PluginTask(task)); nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); } - fn plugin_api(&self) -> PluginApi { - PluginApi::Clap - } - #[inline] fn transport(&self) -> &Transport { &self.transport diff --git a/src/wrapper/standalone/context.rs b/src/wrapper/standalone/context.rs index 7e7ec4c1..7fa572aa 100644 --- a/src/wrapper/standalone/context.rs +++ b/src/wrapper/standalone/context.rs @@ -79,14 +79,14 @@ impl<P: Plugin, B: Backend> GuiContext for WrapperGuiContext<P, B> { } impl<P: Plugin, B: Backend> InitContext<P> for WrapperInitContext<'_, P, B> { - fn execute(&self, task: P::BackgroundTask) { - (self.wrapper.task_executor_wrapper.task_executor.lock())(task); - } - fn plugin_api(&self) -> PluginApi { PluginApi::Standalone } + fn execute(&self, task: P::BackgroundTask) { + (self.wrapper.task_executor_wrapper.task_executor.lock())(task); + } + fn set_latency_samples(&self, _samples: u32) { nih_debug_assert_failure!("TODO: WrapperInitContext::set_latency_samples()"); } @@ -97,15 +97,15 @@ impl<P: Plugin, B: Backend> InitContext<P> for WrapperInitContext<'_, P, B> { } impl<P: Plugin, B: Backend> ProcessContext<P> for WrapperProcessContext<'_, P, B> { + fn plugin_api(&self) -> PluginApi { + PluginApi::Standalone + } + fn execute_async(&self, task: P::BackgroundTask) { let task_posted = self.wrapper.event_loop.do_maybe_async(task); nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); } - fn plugin_api(&self) -> PluginApi { - PluginApi::Standalone - } - #[inline] fn transport(&self) -> &Transport { &self.transport diff --git a/src/wrapper/vst3/context.rs b/src/wrapper/vst3/context.rs index b431d403..d8a8335d 100644 --- a/src/wrapper/vst3/context.rs +++ b/src/wrapper/vst3/context.rs @@ -116,14 +116,14 @@ impl<P: Vst3Plugin> GuiContext for WrapperGuiContext<P> { } impl<P: Vst3Plugin> InitContext<P> for WrapperInitContext<'_, P> { - fn execute(&self, task: P::BackgroundTask) { - (self.inner.task_executor.lock())(task); - } - fn plugin_api(&self) -> PluginApi { PluginApi::Vst3 } + fn execute(&self, task: P::BackgroundTask) { + (self.inner.task_executor.lock())(task); + } + fn set_latency_samples(&self, samples: u32) { self.inner.set_latency_samples(samples) } @@ -134,15 +134,15 @@ impl<P: Vst3Plugin> InitContext<P> for WrapperInitContext<'_, P> { } impl<P: Vst3Plugin> ProcessContext<P> for WrapperProcessContext<'_, P> { + fn plugin_api(&self) -> PluginApi { + PluginApi::Vst3 + } + fn execute_async(&self, task: P::BackgroundTask) { let task_posted = self.inner.do_maybe_async(Task::PluginTask(task)); nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); } - fn plugin_api(&self) -> PluginApi { - PluginApi::Vst3 - } - #[inline] fn transport(&self) -> &Transport { &self.transport