l6t_file/
model.rs

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use std::fmt::{Display, Formatter, Result};

#[derive(Debug)]
pub struct TargetDevice {
    pub midi_id: u32,
    pub name: String,
    pub version: u32
}

#[derive(Debug)]
pub struct Model {
    pub model_id: u32,
    pub slot_id: u32,
    pub enabled: bool,
    pub ordinal: u8,
    pub params: Vec<ModelParam>
}

impl PartialEq for Model {
    fn eq(&self, other: &Self) -> bool {
        self.slot_id == other.slot_id &&
            self.model_id == other.model_id &&
            self.ordinal == other.ordinal
    }
}

#[derive(Debug)]
pub struct ModelParam {
    pub param_id: u32,
    pub value: Value
}

#[derive(Debug)]
pub enum Value {
    Int(u32),
    Float(f32)
}

#[derive(Debug)]
pub struct MetaTags {
    pub author: String,
    pub guitarist: String,
    pub band: String,
    pub song: String,
    pub style: String,
    pub pickup_style: String,
    pub pickup_position: String,
    pub date: usize,
    pub amp_name: String,
    pub creator_app: String,
    pub creator_app_version: String,
    pub comments: String
}

#[derive(Debug)]
pub struct L6Patch {
    pub target_device: TargetDevice,
    pub models: Vec<Model>,
    pub meta: MetaTags
}

impl Default for MetaTags {
    fn default() -> Self {
        MetaTags {
            author: "".to_string(),
            guitarist: "".to_string(),
            band: "".to_string(),
            song: "".to_string(),
            style: "".to_string(),
            pickup_style: "".to_string(),
            pickup_position: "".to_string(),
            date: 0,
            amp_name: "".to_string(),
            creator_app: "".to_string(),
            creator_app_version: "".to_string(),
            comments: "".to_string()
        }
    }
}

impl Default for TargetDevice {
    fn default() -> Self {
        TargetDevice {
            midi_id: 0,
            name: "".to_string(),
            version: 0
        }
    }
}

impl Default for L6Patch {
    fn default() -> Self {
        L6Patch {
            target_device: Default::default(),
            models: Default::default(),
            meta: Default::default()
        }
    }
}

impl Default for Model {
    fn default() -> Self {
        Model {
            model_id: 0,
            slot_id: 0,
            enabled: false,
            ordinal: 0,
            params: vec![]
        }
    }
}

impl Default for ModelParam {
    fn default() -> Self {
        ModelParam {
            param_id: 0,
            value: Value::Int(0)
        }
    }
}

impl Display for Value {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        match self {
            Value::Int(v) => write!(f, "int {}", v),
            Value::Float(v) => write!(f, "float {}", v)
        }
    }
}