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
use super::super::super::Result;
use super::super::super::libaudioverse_sys;

use std::os::raw::{ c_int };
use check;
use Error;

/// Proxy to a bool property.
pub struct BoolProperty {
    // allow nodes to construct instances of this struct
    pub(crate) index : c_int, // the index libaudioverse uses to identify this property for this node
    pub(crate) node_handle : libaudioverse_sys::LavHandle, // a handle to the parent node
}

impl BoolProperty {
    pub fn get(&self) -> Result<bool> {
        let mut value : i32 = 0;
        check(unsafe { libaudioverse_sys::Lav_nodeGetIntProperty(self.node_handle, self.index, &mut value) })?;
        match value {
            0 => Ok(false),
            1 => Ok(true),
            _ => Err(Error {
                code: libaudioverse_sys::Lav_ERRORS_Lav_ERROR_UNKNOWN,
                message : "Bool property out of range.".to_string()
            })
        }
    }
    
    fn set_int(&self, value : i32) -> Result<()> {
        check(unsafe { libaudioverse_sys::Lav_nodeSetIntProperty(self.node_handle, self.index, value) })?;
        Ok(())
    }
    
    /// Sets the value of this property.
    pub fn set(&self, value : bool) -> Result<()> {
        match value {
            true => self.set_int(1),
            false => self.set_int(0)
        }
    }
}