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
use crate::internal_prelude::*;

#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub struct GlobalEcho(pub(crate) Handle);

/// Re-exported Synthizer `syz_EchoTapConfig` type.  Using this instead of a
/// dedicated struct prevents needing to clone your taps on the way to
/// Synthizer.
pub type EchoTapConfig = syz_EchoTapConfig;

impl GlobalEcho {
    pub fn new(context: &Context) -> Result<GlobalEcho> {
        wrap_constructor(|ud, cb| {
            let mut h = Default::default();
            check_error(unsafe {
                syz_createGlobalEcho(&mut h, context.to_syz_handle(), null_mut(), ud, Some(cb))
            })?;
            Ok(GlobalEcho(Handle::new(h)))
        })
    }

    /// An empty slice clears the taps. Alternatively, you can use `clear_taps`.
    pub fn set_taps(&self, taps: &[EchoTapConfig]) -> Result<()> {
        if taps.is_empty() {
            return self.clear_taps();
        }

        check_error(unsafe {
            syz_globalEchoSetTaps(
                self.to_syz_handle(),
                taps.len() as u32,
                &taps[0] as *const syz_EchoTapConfig,
            )
        })
    }

    pub fn clear_taps(&self) -> Result<()> {
        check_error(unsafe { syz_globalEchoSetTaps(self.to_syz_handle(), 0, std::ptr::null()) })
    }

    effect_properties!();

    object_common!();
}

handle_traits!(GlobalEcho);