nbs/noteblocks/
layer.rs

1use super::note::Note;
2use crate::NbsFormat;
3use std::collections::HashMap;
4
5/// A Layer contains an list of notes and some additional information.
6#[derive(Debug)]
7pub struct Layer {
8    /// Name of the layer.
9    pub name: String,
10    /// Only avabile in the new format version 4.
11    pub locked: Option<bool>,
12    /// Layer volume.
13    pub volume: i8,
14    /// Only avabile in the new format since version 2.
15    pub stereo: Option<i8>,
16    pub notes: HashMap<i16, Note>,
17}
18
19impl Layer {
20    /// Creates an new empty Layer.
21    pub fn new() -> Self {
22        Layer {
23            name: String::new(),
24            locked: None,
25            volume: 100,
26            stereo: None,
27            notes: HashMap::new(),
28        }
29    }
30
31    /// Creates an new Layer with default values for the specified format
32    pub fn from_format(format: NbsFormat) -> Self {
33        let mut layer = Layer::new();
34        layer.name = String::new();
35        if format.version() >= 4 {
36            layer.locked = Some(false);
37        }
38        layer.volume = 100;
39        if format.version() >= 2 {
40            layer.stereo = Some(100);
41        }
42        layer
43    }
44}