Skip to main content

sva_samples/
label.rs

1// Concern: states how exact one sampled value is | Non-concern: deciding that (collapse/blocks.rs), printing it | IO: none
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum Source {
5    Exact,
6    Measured,
7}
8
9/// A line the grid could not hold, levelled against amplitude 1.0.
10#[derive(Clone, Copy, Debug, PartialEq)]
11pub struct Dropped {
12    pub hz: f64,
13    pub db: f64,
14}
15
16macro_rules! rules {
17    ($($variant:ident => $text:literal,)+) => {
18        #[derive(Clone, Copy, Debug, PartialEq, Eq)]
19        pub enum Rule {
20            $($variant,)+
21        }
22
23        impl Rule {
24            /// The row of FORMAT 9.1 that ran, as the label prints it.
25            pub fn as_str(self) -> &'static str {
26                match self {
27                    $(Rule::$variant => $text,)+
28                }
29            }
30
31            pub fn named(text: &str) -> Option<Rule> {
32                match text {
33                    $($text => Some(Rule::$variant),)+
34                    _ => None,
35                }
36            }
37        }
38    };
39}
40
41rules! {
42    LineSpectrumSummed => "line spectrum, summed directly",
43    BandLimited => "band-limited projection",
44    CroppedPair => "cropped pair, tail truncated",
45    PointSampled => "point sampling",
46    Istft => "inverse short-time transform",
47    Reading => "reading",
48    Added => "sum, addend by addend",
49}
50
51#[derive(Clone, Debug, PartialEq)]
52pub enum Detail {
53    Lines {
54        rule: Rule,
55        summed: usize,
56        dropped: Vec<Dropped>,
57        dropped_more: usize,
58        tail_db: Option<f64>,
59    },
60    Continuous {
61        rule: Rule,
62    },
63    Cropped {
64        rule: Rule,
65        tail_db: Option<f64>,
66    },
67    Point {
68        rule: Rule,
69        alias_db: Option<f64>,
70        tail_db: Option<f64>,
71    },
72    Roundtrip {
73        rule: Rule,
74        edited: bool,
75    },
76    /// A reading off a buffer that exists; no collapse ran under it.
77    Reading {
78        rule: Rule,
79    },
80    /// A sum whose addends named different rows; the planes added.
81    Added {
82        parts: Vec<Detail>,
83    },
84}
85
86#[derive(Clone, Debug, PartialEq)]
87pub struct CuttingBelowSilenceThreshold {
88    pub silence_threshold_dbfs: f64,
89    pub treated_as_silent_from_sample: Vec<(String, i64)>,
90}
91
92#[derive(Clone, Debug, PartialEq)]
93pub struct Label {
94    pub source: Source,
95    pub profile: &'static str,
96    pub rate: u32,
97    pub detail: Detail,
98    /// The most seconds a read was moved to land on a whole sample.
99    pub moved: Option<f64>,
100    pub cutting_below_silence_threshold: Option<CuttingBelowSilenceThreshold>,
101}
102
103impl Label {
104    pub fn measured(profile: &'static str, rate: u32) -> Label {
105        Label {
106            source: Source::Measured,
107            profile,
108            rate,
109            detail: Detail::Reading {
110                rule: Rule::Reading,
111            },
112            moved: None,
113            cutting_below_silence_threshold: None,
114        }
115    }
116
117    pub fn new(source: Source, profile: &'static str, rate: u32, detail: Detail) -> Label {
118        Label {
119            source,
120            profile,
121            rate,
122            detail,
123            moved: None,
124            cutting_below_silence_threshold: None,
125        }
126    }
127
128    pub fn rule(&self) -> Rule {
129        self.detail.rule()
130    }
131}
132
133impl Detail {
134    pub fn rule(&self) -> Rule {
135        match *self {
136            Detail::Lines { rule, .. }
137            | Detail::Continuous { rule }
138            | Detail::Cropped { rule, .. }
139            | Detail::Point { rule, .. }
140            | Detail::Roundtrip { rule, .. }
141            | Detail::Reading { rule } => rule,
142            Detail::Added { .. } => Rule::Added,
143        }
144    }
145}