From caed581a68f5f674ff4d3a798c241258b0412693 Mon Sep 17 00:00:00 2001 From: ozpv <39195175+ozpv@users.noreply.github.com> Date: Fri, 15 May 2026 15:49:19 -0500 Subject: commit --- src/lib.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..82c1957 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,89 @@ +use crate::{ + audio::RetainPluginAudioProcessor, + gui::RetainPluginGui, + params::{RetainParamsLocal, RetainParamsShared}, +}; +use clack_extensions::{audio_ports::*, gui::PluginGui, params::*, state::PluginState}; +use clack_plugin::prelude::*; +use std::sync::Arc; + +mod audio; +mod gui; +mod params; +mod window_size; + +/// The type that represents our plugin in Clack. +/// +/// This is what implements the [`Plugin`] trait, where all the other subtypes are attached. +pub struct RetainPlugin; + +impl Plugin for RetainPlugin { + type AudioProcessor<'a> = RetainPluginAudioProcessor<'a>; + type Shared<'a> = RetainPluginShared; + type MainThread<'a> = RetainPluginMainThread<'a>; + + fn declare_extensions( + builder: &mut PluginExtensions, + _shared: Option<&RetainPluginShared>, + ) { + builder + .register::() + .register::() + .register::() + .register::(); + } +} + +impl DefaultPluginFactory for RetainPlugin { + fn get_descriptor() -> PluginDescriptor { + use clack_plugin::plugin::features::*; + + PluginDescriptor::new("org.haemolacriaa.retain", "Retain") + .with_features([AUDIO_EFFECT, STEREO]) + } + + fn new_shared(_host: HostSharedHandle<'_>) -> Result, PluginError> { + Ok(RetainPluginShared { + params: Arc::new(RetainParamsShared::new()), + }) + } + + fn new_main_thread<'a>( + _host: HostMainThreadHandle<'a>, + shared: &'a Self::Shared<'a>, + ) -> Result, PluginError> { + Ok(Self::MainThread { + shared, + params: RetainParamsLocal::new(&shared.params), + gui: None, + }) + } +} + +/// The plugin data that gets shared between the Main Thread and the Audio Thread. +pub struct RetainPluginShared { + /// The plugin's parameter values. + params: Arc, +} + +impl PluginShared<'_> for RetainPluginShared {} + +/// The data that belongs to the main thread of our plugin. +pub struct RetainPluginMainThread<'a> { + /// The local state of the parameters + params: RetainParamsLocal, + /// A reference to the plugin's shared data. + shared: &'a RetainPluginShared, + /// The plugin's GUI state and context + gui: Option, +} + +impl<'a> PluginMainThread<'a, RetainPluginShared> for RetainPluginMainThread<'a> { + fn on_main_thread(&mut self) { + if let Some(gui) = &self.gui { + gui.request_repaint(); + } + } +} + +clack_export_entry!(SinglePluginEntry); -- cgit v1.2.3