rawdio/effects/gain/
gain_node.rs1use crate::{
2 commands::Id, graph::GraphNode, parameter::*, prelude::*, utility::create_parameters, DspNode,
3};
4
5use super::gain_processor::GainProcessor;
6
7pub struct Gain {
15 pub node: GraphNode,
17
18 params: Parameters,
19}
20
21const MIN_GAIN: f64 = f64::NEG_INFINITY;
22const MAX_GAIN: f64 = f64::INFINITY;
23const DEFAULT_GAIN: f64 = 1.0;
24
25impl DspNode for Gain {
26 fn get_parameters_mut(&mut self) -> &mut Parameters {
27 &mut self.params
28 }
29}
30
31impl Gain {
32 pub fn new(context: &dyn Context, channel_count: usize) -> Self {
34 let id = Id::generate();
35
36 let (params, realtime_params) = create_parameters(
37 id,
38 context,
39 [(
40 "gain",
41 ParameterRange::new(DEFAULT_GAIN, MIN_GAIN, MAX_GAIN),
42 )],
43 );
44
45 let processor = Box::new(GainProcessor::new());
46
47 Self {
48 node: GraphNode::new(
49 id,
50 context,
51 channel_count,
52 channel_count,
53 processor,
54 realtime_params,
55 ),
56 params,
57 }
58 }
59
60 pub fn gain(&mut self) -> &mut AudioParameter {
62 self.get_parameter_mut("gain")
63 }
64}