forked from ilmai/plugin-things
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.rs
More file actions
93 lines (73 loc) · 2.88 KB
/
Copy pathplugin.rs
File metadata and controls
93 lines (73 loc) · 2.88 KB
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
90
91
92
93
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::{Read, Write};
use std::rc::Rc;
use plinth_plugin::error::Error;
use plinth_plugin::{export_clap, export_vst3, Event, Host, HostInfo, Parameters, Plugin, ProcessorConfig};
use plinth_plugin::clap::ClapPlugin;
use plinth_plugin::vst3::Vst3Plugin;
use crate::editor::{EditorSettings, GainPluginEditor};
use crate::{parameters::GainParameters, processor::GainPluginProcessor};
#[derive(Default)]
pub struct GainPlugin {
parameters: Rc<GainParameters>,
editor_settings: Rc<RefCell<EditorSettings>>,
}
impl Plugin for GainPlugin {
const NAME: &'static str = "Gain Example";
const VENDOR: &'static str = "Viiri Audio";
const VERSION: &'static str = "0.1";
type Processor = GainPluginProcessor;
type Editor = GainPluginEditor;
type Parameters = GainParameters;
fn new(_host_info: HostInfo) -> Self {
Self::default()
}
fn init(&mut self) {
}
fn with_parameters<T>(&self, mut f: impl FnMut(&Self::Parameters) -> T) -> T {
f(&self.parameters)
}
fn process_event(&mut self, event: &Event) {
self.parameters.process_event(event);
}
fn create_processor(&mut self, _config: ProcessorConfig) -> Self::Processor {
GainPluginProcessor::new((*self.parameters).clone())
}
fn create_editor(&mut self, host: Rc<dyn Host>) -> Self::Editor {
GainPluginEditor::new(host, self.parameters.clone(), self.editor_settings.clone())
}
fn save_state(&self, writer: &mut impl Write) -> Result<(), Error> {
let serialized_parameters: HashMap<_, _> = self.parameters.serialize().collect();
let parameters_json = serde_json::to_string(&serialized_parameters)
.map_err(|_| Error::SerializationError)?;
write!(writer, "{parameters_json}")?;
Ok(())
}
fn load_state(&mut self, reader: &mut impl Read) -> Result<(), Error> {
let mut parameters_json = String::new();
reader.read_to_string(&mut parameters_json)?;
let serialized_parameters: HashMap<_, _> = serde_json::from_str(¶meters_json)
.map_err(|_| Error::SerializationError)?;
self.parameters.deserialize(serialized_parameters)?;
Ok(())
}
}
impl ClapPlugin for GainPlugin {
const CLAP_ID: &'static str = "viiri-audio.gain-example";
const FEATURES: &'static [plinth_plugin::clap::Feature] = &[
plinth_plugin::clap::Feature::AudioEffect,
plinth_plugin::clap::Feature::Stereo,
];
}
impl Vst3Plugin for GainPlugin {
const CLASS_ID: u128 = 0xE84410DB1788DC81;
const SUBCATEGORIES: &'static [plinth_plugin::vst3::Subcategory] = &[
plinth_plugin::vst3::Subcategory::Fx,
plinth_plugin::vst3::Subcategory::Stereo,
];
}
export_clap!(GainPlugin);
export_vst3!(GainPlugin);
#[cfg(feature = "standalone")]
impl plinth_plugin::standalone::StandalonePlugin for GainPlugin {}