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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ix!();

use crate::{ControlStyle};

#[derive(Debug,Copy, Clone)]
pub enum PData {
    Int(i32),
    Bool(bool),
    Float(f32),
}

macro_rules! impl_pdata_try_into [
    ($ty:ty, $x:ident) => {

        impl TryInto<$ty> for PData {

            type Error = core::fmt::Error;

            fn try_into(self) -> Result<$ty, Self::Error> {
                return match self {
                    PData::$x(val) => Ok(val.into()),
                    _ => panic!(),
                }
            }
        }
    }
];

impl_pdata_try_into![f64,  Float];
impl_pdata_try_into![f32,  Float];
impl_pdata_try_into![i32,  Int];
impl_pdata_try_into![bool, Bool];

//can we factor this out?
//this was necessary in C,
//but probably not in rust
enhanced_enum![
    ValType {
        VtInt,
        VtBool,
        VtFloat,
    }
];

#[derive(Debug,Copy,Clone)]
pub struct ParamUserData {

}

#[derive(Debug)]
pub struct ParameterMeta {
    pub fmin:     f32,
    pub fmax:     f32,
    pub fdefault: f32,
    pub flags:    ControlStyle,
    pub clump:    u32,
    pub hide:     bool,
    pub expert:   bool,
    pub meta:     bool,
}

//do we want to leave this in here since there is a panic case?
impl std::ops::Sub for PData {
    type Output = Self;

    fn sub(self, other: Self) -> Self::Output {
        match (self, other) {
            (PData::Float(x1),   PData::Float(x2)) => { PData::Float(x1 - x2)        },
            (PData::Float(x1),   PData::Int(x2))   => { PData::Float(x1 - x2 as f32) },
            (PData::Int(x1),     PData::Float(x2)) => { PData::Float(x1 as f32 - x2) },
            (PData::Int(x1),     PData::Int(x2))   => { PData::Int(x1 - x2)          },
            _ => { panic!("incompatible types for ops::Sub! program logic bug!");  }
        }
    }
}