dawproject_rs/api/device_mods/
compressor.rs1#![allow(unused)]
2use super::{device::DeviceElements, device_role::DeviceRole};
3
4use {
5 super::{
6 super::add_one_get, super::bool_parameter::BoolParameter, super::fake_rng,
7 super::real_parameter::RealParameter,
8 },
9 fake::{Dummy, Fake, Faker},
10 serde::{Deserialize, Serialize},
11};
12#[derive(Debug, Deserialize, Serialize, Clone, Dummy)]
13enum CompressorParamsEnum {
14 Attack(RealParameter),
15 AutoMakeup(BoolParameter),
16 InputGain(RealParameter),
17 OutputGain(RealParameter),
18 Ratio(RealParameter),
19 Release(RealParameter),
20 Threshold(RealParameter),
21}
22
23type CompressorParams = Vec<CompressorParamsEnum>;
24
25#[derive(Debug, Deserialize, Serialize, Clone, Dummy)]
26pub struct Compressor {
27 #[serde(rename = "@id")]
28 id: Option<String>,
29 #[serde(rename = "$value", default)]
30 device_elements: DeviceElements,
31 #[serde(rename = "@deviceID")]
32 #[serde(skip_serializing_if = "Option::is_none")]
33 device_id: Option<String>,
34 #[serde(rename = "@deviceName")]
35 #[serde(skip_serializing_if = "Option::is_none")]
36 device_name: Option<String>,
37 #[serde(rename = "@deviceRole")]
38 #[serde(skip_serializing_if = "Option::is_none")]
39 device_role: Option<DeviceRole>,
40 #[serde(rename = "@deviceVendor")]
41 #[serde(skip_serializing_if = "Option::is_none")]
42 device_vendor: Option<String>,
43 #[serde(rename = "@loaded")]
44 #[serde(skip_serializing_if = "Option::is_none")]
45 loaded: Option<bool>,
46 #[serde(rename = "$value", default)]
47 compressor_elements: Vec<CompressorParamsEnum>,
48}
49
50impl Compressor {
51 pub fn new_test() -> Self {
52 Self {
53 id: Some(format!("id{}", add_one_get())),
54 device_elements: vec![],
55 device_id: None,
56 device_name: None,
57 device_role: None,
58 device_vendor: None,
59 loaded: None,
60 compressor_elements: vec![],
61 }
62 }
63
64 pub fn new_fake() -> Self {
65 let o: Self = Faker.fake_with_rng(&mut fake_rng());
66 o
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use {super::Compressor, quick_xml::se::to_string, std::error::Error};
73
74 #[test]
75 pub fn se_test() -> Result<(), Box<dyn Error>> {
76 let mut o = Compressor::new_fake();
77
78 match to_string(&o) {
79 Ok(o) => println!("{}", o),
80 Err(err) => return Err(err.into()),
81 }
82
83 Ok(())
84 }
85}