1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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<Self>,
_shared: Option<&RetainPluginShared>,
) {
builder
.register::<PluginAudioPorts>()
.register::<PluginParams>()
.register::<PluginState>()
.register::<PluginGui>();
}
}
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<Self::Shared<'_>, PluginError> {
Ok(RetainPluginShared {
params: Arc::new(RetainParamsShared::new()),
})
}
fn new_main_thread<'a>(
_host: HostMainThreadHandle<'a>,
shared: &'a Self::Shared<'a>,
) -> Result<Self::MainThread<'a>, 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<RetainParamsShared>,
}
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<RetainPluginGui>,
}
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<RetainPlugin>);
|