synthizer/
routes.rs

1use crate::internal_prelude::*;
2
3/// A Synthizer route, used to connect sources to effects.  See
4/// [Context::config_route] or, if you want to avoid this type,
5/// [Context::config_route_simple].
6///
7/// The `Default` impl on this type is a route with default settings.  For more
8/// advanced configuration, start with [RouteBuilder].
9#[derive(Clone)]
10pub struct RouteConfig(pub(crate) syz_RouteConfig);
11
12/// A builder for an effect route.  `new` and `Default` are the equivalent of
13/// `syz_initRouteConfig`, e.g. a builder representing the default route.
14#[derive(Clone)]
15pub struct RouteConfigBuilder(syz_RouteConfig);
16
17impl RouteConfigBuilder {
18    pub fn new() -> RouteConfigBuilder {
19        let mut cfg = Default::default();
20        unsafe { syz_initRouteConfig(&mut cfg as *mut syz_RouteConfig) };
21        RouteConfigBuilder(cfg)
22    }
23
24    pub fn set_gain(mut self, gain: f64) -> RouteConfigBuilder {
25        self.0.gain = gain;
26        self
27    }
28
29    pub fn set_fade_time(mut self, fade_time: f64) -> RouteConfigBuilder {
30        self.0.fade_time = fade_time;
31        self
32    }
33
34    pub fn set_filter(mut self, filter: BiquadConfig) -> RouteConfigBuilder {
35        self.0.filter = filter.cfg;
36        self
37    }
38
39    pub fn build(self) -> RouteConfig {
40        RouteConfig(self.0)
41    }
42}
43
44impl Default for RouteConfigBuilder {
45    fn default() -> RouteConfigBuilder {
46        RouteConfigBuilder::new()
47    }
48}
49
50impl Default for RouteConfig {
51    fn default() -> RouteConfig {
52        RouteConfigBuilder::new().build()
53    }
54}
55
56// Hack to stop people implementing our internal traits.
57mod route_traits {
58    use super::*;
59
60    pub trait RouteInput: ToSyzHandle {}
61    pub trait RouteOutput: ToSyzHandle {}
62}
63pub(crate) use route_traits::*;
64
65impl RouteOutput for Source {}
66impl RouteOutput for Handle {}
67impl RouteOutput for DirectSource {}
68impl RouteOutput for AngularPannedSource {}
69impl RouteOutput for ScalarPannedSource {}
70impl RouteOutput for Source3D {}
71
72impl RouteInput for Handle {}
73impl RouteInput for GlobalEcho {}
74impl RouteInput for GlobalFdnReverb {}