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
13 changes: 13 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ pub trait Plugin: Default + Send + 'static {
context: &mut impl ProcessContext<Self>,
) -> ProcessStatus;

/// Called when audio processing stops, for instance when the plugin is turned off.
/// This is the counterpart to [`reset()`][Self::reset()] which is called
/// when processing starts or resumes.
///
/// Unlike [`deactivate()`][Self::deactivate()], this is called for temporary processing
/// interruptions like bypassing, not major lifecycle changes.
/// You can use this to gracefully handle the transition to a non-processing state, such as clearing
/// buffers, writing silence to displays, or saving state.
///
/// This method is called from both CLAP (`stop_processing`) and VST3 (`setProcessing(false)`)
/// hosts when they temporarily stop sending audio to the plugin.
fn process_stopped(&mut self) {}

/// Called when the plugin is deactivated. The host will call
/// [`initialize()`][Self::initialize()] again before the plugin resumes processing audio. These
/// two functions will not be called when the host only temporarily stops processing audio. You
Expand Down
4 changes: 4 additions & 0 deletions src/wrapper/clap/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,10 @@ impl<P: ClapPlugin> Wrapper<P> {
let wrapper = &*((*plugin).plugin_data as *const Self);

wrapper.is_processing.store(false, Ordering::SeqCst);

process_wrapper(|| {
wrapper.plugin.lock().process_stopped();
});
}

unsafe extern "C" fn reset(plugin: *const clap_plugin) {
Expand Down
5 changes: 5 additions & 0 deletions src/wrapper/vst3/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,11 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
};

process_wrapper(|| plugin.reset());
} else {
// Process stopped - call the plugin's process_stopped() method
process_wrapper(|| {
self.inner.plugin.lock().process_stopped();
});
}

// We don't have any special handling for suspending and resuming plugins, yet
Expand Down