1
0
Fork 0

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.
This commit is contained in:
Robbert van der Helm 2022-03-04 13:22:58 +01:00
parent 7fd3c31a0f
commit 99f97978a9
3 changed files with 12 additions and 12 deletions

View file

@ -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).

View file

@ -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()
}
}

View file

@ -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()
}
}