From 99f97978a9195286165a74d111093b4222b8392d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm <mail@robbertvanderhelm.nl> Date: Fri, 4 Mar 2022 13:22:58 +0100 Subject: [PATCH] Reorder ProcessContext methods When we'll add more things here the more common getters should come first and less common operations like changing latency should come last. --- src/context.rs | 8 ++++---- src/wrapper/clap/context.rs | 8 ++++---- src/wrapper/vst3/context.rs | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/context.rs b/src/context.rs index 9bab558e..bda02b63 100644 --- a/src/context.rs +++ b/src/context.rs @@ -15,10 +15,6 @@ use crate::plugin::NoteEvent; // 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 { - /// 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); - /// Return the next note event, if there is one. The event contains the timing /// /// TODO: Rethink this API, both in terms of ergonomics, and if we can do this in a way that @@ -26,6 +22,10 @@ pub trait ProcessContext { /// here) fn next_midi_event(&mut self) -> Option<NoteEvent>; + /// 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); + // TODO: Add this, this works similar to [GuiContext::set_parameter] but it adds the parameter // change to a queue (or directly to the VST3 plugin's parameter output queues) instead of // using main thread host automation (and all the locks involved there). diff --git a/src/wrapper/clap/context.rs b/src/wrapper/clap/context.rs index 9fdd0059..3a7b340b 100644 --- a/src/wrapper/clap/context.rs +++ b/src/wrapper/clap/context.rs @@ -71,6 +71,10 @@ impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> { } impl<P: ClapPlugin> ProcessContext for WrapperProcessContext<'_, P> { + fn next_midi_event(&mut self) -> Option<NoteEvent> { + self.input_events_guard.pop_front() + } + fn set_latency_samples(&self, samples: u32) { // Only make a callback if it's actually needed // XXX: For CLAP we could move this handling to the Plugin struct, but it may be worthwhile @@ -81,8 +85,4 @@ impl<P: ClapPlugin> ProcessContext for WrapperProcessContext<'_, P> { nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); } } - - fn next_midi_event(&mut self) -> Option<NoteEvent> { - self.input_events_guard.pop_front() - } } diff --git a/src/wrapper/vst3/context.rs b/src/wrapper/vst3/context.rs index 5375b135..747e7801 100644 --- a/src/wrapper/vst3/context.rs +++ b/src/wrapper/vst3/context.rs @@ -91,6 +91,10 @@ impl<P: Vst3Plugin> GuiContext for WrapperGuiContext<P> { } impl<P: Vst3Plugin> ProcessContext for WrapperProcessContext<'_, P> { + fn next_midi_event(&mut self) -> Option<NoteEvent> { + self.input_events_guard.pop_front() + } + fn set_latency_samples(&self, samples: u32) { // Only trigger a restart if it's actually needed let old_latency = self.inner.current_latency.swap(samples, Ordering::SeqCst); @@ -102,8 +106,4 @@ impl<P: Vst3Plugin> ProcessContext for WrapperProcessContext<'_, P> { nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); } } - - fn next_midi_event(&mut self) -> Option<NoteEvent> { - self.input_events_guard.pop_front() - } }