1
0
Fork 0

Store the processing mode in BufferConfig

Instead of having a function on ProcessContext.
This commit is contained in:
Robbert van der Helm 2022-05-22 13:33:38 +02:00
parent ee3b0bf8e6
commit 783dc2245e
11 changed files with 41 additions and 44 deletions

View file

@ -13,6 +13,11 @@ code then it will not be listed here.
`param.hide()`, while `param.non_automatable()` simply makes it so that the `param.hide()`, while `param.non_automatable()` simply makes it so that the
parameter can only be changed manually and not through automation or parameter can only be changed manually and not through automation or
modulation. modulation.
- The current processing mode is now stored in `BufferConfig`. Previously this
could be fetched through a function on the `ProcessContext`, but this makes
more sense as it remains constant until a plugin is deactivated. The
`BufferConfig` now contains a field for the minimum buffer size that may or
may not be set depending on the plugin API.
## ... ## ...

View file

@ -24,9 +24,6 @@ pub trait ProcessContext {
/// Get information about the current transport position and status. /// Get information about the current transport position and status.
fn transport(&self) -> &Transport; fn transport(&self) -> &Transport;
/// The current processing mode. The host will reinitialize the plugin any time this changes.
fn process_mode(&self) -> ProcessMode;
/// Returns the next note event, if there is one. Use [`NoteEvent::timing()`] to get the event's /// Returns the next note event, if there is one. Use [`NoteEvent::timing()`] to get the event's
/// timing within the buffer. Only available when /// timing within the buffer. Only available when
/// [`Plugin::MIDI_INPUT`][crate::prelude::Plugin::MIDI_INPUT] is set. /// [`Plugin::MIDI_INPUT`][crate::prelude::Plugin::MIDI_INPUT] is set.
@ -207,22 +204,6 @@ pub enum PluginApi {
Vst3, Vst3,
} }
/// The plugin's current processing mode. Can be queried through [`ProcessContext::process_mode()`].
/// The host will reinitialize the plugin whenever this changes.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProcessMode {
/// The plugin is processing audio in real time at a fixed rate.
Realtime,
/// The plugin is processing audio at a real time-like pace, but at irregular intervals. The
/// host may do this to process audio ahead of time to loosen realtime constraints and to reduce
/// the chance of xruns happening. This is only used by VST3.
Buffered,
/// The plugin is rendering audio offline, potentially faster than realtime ('freewheeling').
/// The host will continuously call the process function back to back until all audio has been
/// processed.
Offline,
}
impl Display for PluginApi { impl Display for PluginApi {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {

View file

@ -300,6 +300,8 @@ pub struct BufferConfig {
/// sized buffers up to this size, or between the minimum and the maximum buffer size if both /// sized buffers up to this size, or between the minimum and the maximum buffer size if both
/// are set. /// are set.
pub max_buffer_size: u32, pub max_buffer_size: u32,
/// The current processing mode. The host will reinitialize the plugin any time this changes.
pub process_mode: ProcessMode,
} }
/// Indicates the current situation after the plugin has processed audio. /// Indicates the current situation after the plugin has processed audio.
@ -317,3 +319,19 @@ pub enum ProcessStatus {
/// infite tail. /// infite tail.
KeepAlive, KeepAlive,
} }
/// The plugin's current processing mode. Can be queried through [`ProcessContext::process_mode()`].
/// The host will reinitialize the plugin whenever this changes.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProcessMode {
/// The plugin is processing audio in real time at a fixed rate.
Realtime,
/// The plugin is processing audio at a real time-like pace, but at irregular intervals. The
/// host may do this to process audio ahead of time to loosen realtime constraints and to reduce
/// the chance of xruns happening. This is only used by VST3.
Buffered,
/// The plugin is rendering audio offline, potentially faster than realtime ('freewheeling').
/// The host will continuously call the process function back to back until all audio has been
/// processed.
Offline,
}

View file

@ -11,7 +11,7 @@ pub use crate::formatters;
pub use crate::util; pub use crate::util;
pub use crate::buffer::Buffer; pub use crate::buffer::Buffer;
pub use crate::context::{GuiContext, ParamSetter, PluginApi, ProcessContext, ProcessMode}; pub use crate::context::{GuiContext, ParamSetter, PluginApi, ProcessContext};
// This also includes the derive macro // This also includes the derive macro
pub use crate::midi::{control_change, MidiConfig, NoteEvent}; pub use crate::midi::{control_change, MidiConfig, NoteEvent};
pub use crate::param::enums::{Enum, EnumParam}; pub use crate::param::enums::{Enum, EnumParam};
@ -20,7 +20,7 @@ pub use crate::param::range::{FloatRange, IntRange};
pub use crate::param::smoothing::{Smoothable, Smoother, SmoothingStyle}; pub use crate::param::smoothing::{Smoothable, Smoother, SmoothingStyle};
pub use crate::param::{BoolParam, FloatParam, IntParam, Param, ParamFlags}; pub use crate::param::{BoolParam, FloatParam, IntParam, Param, ParamFlags};
pub use crate::plugin::{ pub use crate::plugin::{
BufferConfig, BusConfig, ClapPlugin, Editor, ParentWindowHandle, Plugin, ProcessStatus, BufferConfig, BusConfig, ClapPlugin, Editor, ParentWindowHandle, Plugin, ProcessMode,
Vst3Plugin, ProcessStatus, Vst3Plugin,
}; };
pub use crate::wrapper::state::PluginState; pub use crate::wrapper::state::PluginState;

View file

@ -4,7 +4,7 @@ use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use super::wrapper::{OutputParamEvent, Task, Wrapper}; use super::wrapper::{OutputParamEvent, Task, Wrapper};
use crate::context::{GuiContext, PluginApi, ProcessContext, ProcessMode, Transport}; use crate::context::{GuiContext, PluginApi, ProcessContext, Transport};
use crate::event_loop::EventLoop; use crate::event_loop::EventLoop;
use crate::midi::NoteEvent; use crate::midi::NoteEvent;
use crate::param::internals::ParamPtr; use crate::param::internals::ParamPtr;
@ -104,10 +104,6 @@ impl<P: ClapPlugin> ProcessContext for WrapperProcessContext<'_, P> {
&self.transport &self.transport
} }
fn process_mode(&self) -> ProcessMode {
self.wrapper.current_process_mode.load()
}
fn next_event(&mut self) -> Option<NoteEvent> { fn next_event(&mut self) -> Option<NoteEvent> {
self.input_events_guard.pop_front() self.input_events_guard.pop_front()
} }

View file

@ -78,13 +78,13 @@ use super::context::{WrapperGuiContext, WrapperProcessContext};
use super::descriptor::PluginDescriptor; use super::descriptor::PluginDescriptor;
use super::util::ClapPtr; use super::util::ClapPtr;
use crate::buffer::Buffer; use crate::buffer::Buffer;
use crate::context::{ProcessMode, Transport}; use crate::context::Transport;
use crate::event_loop::{EventLoop, MainThreadExecutor, TASK_QUEUE_CAPACITY}; use crate::event_loop::{EventLoop, MainThreadExecutor, TASK_QUEUE_CAPACITY};
use crate::midi::{MidiConfig, NoteEvent}; use crate::midi::{MidiConfig, NoteEvent};
use crate::param::internals::{ParamPtr, Params}; use crate::param::internals::{ParamPtr, Params};
use crate::param::ParamFlags; use crate::param::ParamFlags;
use crate::plugin::{ use crate::plugin::{
BufferConfig, BusConfig, ClapPlugin, Editor, ParentWindowHandle, ProcessStatus, BufferConfig, BusConfig, ClapPlugin, Editor, ParentWindowHandle, ProcessMode, ProcessStatus,
}; };
use crate::util::permit_alloc; use crate::util::permit_alloc;
use crate::wrapper::state::{self, PluginState}; use crate::wrapper::state::{self, PluginState};
@ -1517,6 +1517,7 @@ impl<P: ClapPlugin> Wrapper<P> {
sample_rate: sample_rate as f32, sample_rate: sample_rate as f32,
min_buffer_size: Some(min_frames_count), min_buffer_size: Some(min_frames_count),
max_buffer_size: max_frames_count, max_buffer_size: max_frames_count,
process_mode: wrapper.current_process_mode.load(),
}; };
// Befure initializing the plugin, make sure all smoothers are set the the default values // Befure initializing the plugin, make sure all smoothers are set the the default values

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use super::backend::Backend; use super::backend::Backend;
use super::wrapper::{GuiTask, Wrapper}; use super::wrapper::{GuiTask, Wrapper};
use crate::context::{GuiContext, PluginApi, ProcessContext, ProcessMode, Transport}; use crate::context::{GuiContext, PluginApi, ProcessContext, Transport};
use crate::midi::NoteEvent; use crate::midi::NoteEvent;
use crate::param::internals::ParamPtr; use crate::param::internals::ParamPtr;
use crate::plugin::Plugin; use crate::plugin::Plugin;
@ -81,11 +81,6 @@ impl<P: Plugin, B: Backend> ProcessContext for WrapperProcessContext<'_, P, B> {
&self.transport &self.transport
} }
fn process_mode(&self) -> ProcessMode {
// TODO: Detect JACK freewheeling and report it here
ProcessMode::Realtime
}
fn next_event(&mut self) -> Option<NoteEvent> { fn next_event(&mut self) -> Option<NoteEvent> {
nih_debug_assert_failure!("TODO: WrapperProcessContext::next_event()"); nih_debug_assert_failure!("TODO: WrapperProcessContext::next_event()");

View file

@ -15,7 +15,9 @@ use super::context::{WrapperGuiContext, WrapperProcessContext};
use crate::context::Transport; use crate::context::Transport;
use crate::param::internals::{ParamPtr, Params}; use crate::param::internals::{ParamPtr, Params};
use crate::param::ParamFlags; use crate::param::ParamFlags;
use crate::plugin::{BufferConfig, BusConfig, Editor, ParentWindowHandle, Plugin, ProcessStatus}; use crate::plugin::{
BufferConfig, BusConfig, Editor, ParentWindowHandle, Plugin, ProcessMode, ProcessStatus,
};
use crate::util::permit_alloc; use crate::util::permit_alloc;
use crate::wrapper::state::{self, PluginState}; use crate::wrapper::state::{self, PluginState};
@ -202,6 +204,8 @@ impl<P: Plugin, B: Backend> Wrapper<P, B> {
sample_rate: config.sample_rate, sample_rate: config.sample_rate,
min_buffer_size: None, min_buffer_size: None,
max_buffer_size: config.period_size, max_buffer_size: config.period_size,
// TODO: Detect JACK freewheeling and report it here
process_mode: ProcessMode::Realtime,
}, },
config, config,

View file

@ -117,10 +117,6 @@ impl<P: Vst3Plugin> ProcessContext for WrapperProcessContext<'_, P> {
&self.transport &self.transport
} }
fn process_mode(&self) -> crate::context::ProcessMode {
self.inner.current_process_mode.load()
}
fn next_event(&mut self) -> Option<NoteEvent> { fn next_event(&mut self) -> Option<NoteEvent> {
self.input_events_guard.pop_front() self.input_events_guard.pop_front()
} }

View file

@ -16,12 +16,12 @@ use super::param_units::ParamUnits;
use super::util::{ObjectPtr, VstPtr, VST3_MIDI_PARAMS_END, VST3_MIDI_PARAMS_START}; use super::util::{ObjectPtr, VstPtr, VST3_MIDI_PARAMS_END, VST3_MIDI_PARAMS_START};
use super::view::WrapperView; use super::view::WrapperView;
use crate::buffer::Buffer; use crate::buffer::Buffer;
use crate::context::{ProcessMode, Transport}; use crate::context::Transport;
use crate::event_loop::{EventLoop, MainThreadExecutor, OsEventLoop}; use crate::event_loop::{EventLoop, MainThreadExecutor, OsEventLoop};
use crate::midi::{MidiConfig, NoteEvent}; use crate::midi::{MidiConfig, NoteEvent};
use crate::param::internals::{ParamPtr, Params}; use crate::param::internals::{ParamPtr, Params};
use crate::param::ParamFlags; use crate::param::ParamFlags;
use crate::plugin::{BufferConfig, BusConfig, Editor, ProcessStatus, Vst3Plugin}; use crate::plugin::{BufferConfig, BusConfig, Editor, ProcessMode, ProcessStatus, Vst3Plugin};
use crate::wrapper::state::{self, PluginState}; use crate::wrapper::state::{self, PluginState};
use crate::wrapper::util::{hash_param_id, process_wrapper}; use crate::wrapper::util::{hash_param_id, process_wrapper};

View file

@ -23,10 +23,10 @@ use super::util::{
u16strlcpy, VstPtr, VST3_MIDI_CCS, VST3_MIDI_NUM_PARAMS, VST3_MIDI_PARAMS_START, u16strlcpy, VstPtr, VST3_MIDI_CCS, VST3_MIDI_NUM_PARAMS, VST3_MIDI_PARAMS_START,
}; };
use super::view::WrapperView; use super::view::WrapperView;
use crate::context::{ProcessMode, Transport}; use crate::context::Transport;
use crate::midi::{MidiConfig, NoteEvent}; use crate::midi::{MidiConfig, NoteEvent};
use crate::param::ParamFlags; use crate::param::ParamFlags;
use crate::plugin::{BufferConfig, BusConfig, ProcessStatus, Vst3Plugin}; use crate::plugin::{BufferConfig, BusConfig, ProcessMode, ProcessStatus, Vst3Plugin};
use crate::util::permit_alloc; use crate::util::permit_alloc;
use crate::wrapper::state; use crate::wrapper::state;
use crate::wrapper::util::process_wrapper; use crate::wrapper::util::process_wrapper;
@ -692,6 +692,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
sample_rate: setup.sample_rate as f32, sample_rate: setup.sample_rate as f32,
min_buffer_size: None, min_buffer_size: None,
max_buffer_size: setup.max_samples_per_block as u32, max_buffer_size: setup.max_samples_per_block as u32,
process_mode: self.inner.current_process_mode.load(),
})); }));
let mode = match setup.process_mode { let mode = match setup.process_mode {