Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/context/process.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A context passed during the process function.

use super::PluginApi;
use crate::prelude::{Plugin, PluginNoteEvent};
use crate::prelude::{Plugin, PluginNoteEvent, ProcessMode};

/// Contains both context data and callbacks the plugin can use during processing. Most notably this
/// is how a plugin sends and receives note events, gets transport information, and accesses
Expand Down Expand Up @@ -92,6 +92,22 @@ pub trait ProcessContext<P: Plugin> {
/// monophonic modulation when dropping the capacity down to 1.
fn set_current_voice_capacity(&self, capacity: u32);

/// The render mode the host has requested **after** [`Plugin::initialize()`], for plugin APIs
/// that let a host switch it mid-session. `None` means the API has no such mechanism, in which
/// case [`BufferConfig::process_mode`][crate::prelude::BufferConfig::process_mode] from the
/// last `initialize()` call is still authoritative.
///
/// CLAP hosts may call `clap_plugin_render::set()` at any time on the main thread, for
/// instance to render an offline bounce faster than real time without re-activating the
/// plugin. That change only reaches `BufferConfig` on the next `initialize()`, so a plugin
/// whose real-time path cannot keep up with faster-than-real-time processing (e.g. one that
/// hands audio to a worker thread and polls for results without blocking) can read this to
/// switch to a blocking strategy for the duration of the bounce. The value is a lock-free
/// atomic load and is safe to call from the audio thread.
fn host_render_mode(&self) -> Option<ProcessMode> {
None
}

// 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).
Expand Down
6 changes: 5 additions & 1 deletion src/wrapper/clap/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::wrapper::{OutputParamEvent, Task, Wrapper};
use crate::event_loop::EventLoop;
use crate::prelude::{
ClapPlugin, GuiContext, InitContext, ParamPtr, PluginApi, PluginNoteEvent, ProcessContext,
RemoteControlsContext, RemoteControlsPage, RemoteControlsSection, Transport,
ProcessMode, RemoteControlsContext, RemoteControlsPage, RemoteControlsSection, Transport,
};
use crate::wrapper::util::strlcpy;

Expand Down Expand Up @@ -127,6 +127,10 @@ impl<P: ClapPlugin> ProcessContext<P> for WrapperProcessContext<'_, P> {
fn set_current_voice_capacity(&self, capacity: u32) {
self.wrapper.set_current_voice_capacity(capacity)
}

fn host_render_mode(&self) -> Option<ProcessMode> {
Some(self.wrapper.current_process_mode.load())
}
}

impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
Expand Down
Loading