summaryrefslogtreecommitdiff
path: root/src/monitor.rs
blob: bde5b3783db041dd51b1049a9707822b6fe3a180 (plain)
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
use super::*;
use std::collections::HashMap;
use synth::SampleBuffer;

pub struct VoiceDatum {
    pitch: Pitch,
    ampl: f32,
}

pub enum Datum {
    Voices(Vec<VoiceDatum>),
    Samples(SampleBuffer),
    Playtime(f32, f32),
}

pub enum DatumKind {
    Voices,
    Samples,
    Playtime,
}

impl<'a> From<&'a Datum> for DatumKind {
    fn from(d: &'a Datum) -> DatumKind {
        match *d {
            Datum::Voices(_) => DatumKind::Voices,
            Datum::Samples(_) => DatumKind::Samples,
            Datum::Playtime(_, _) => DatumKind::Playtime,
        }
    }
}

pub type Data = HashMap<DatumKind, Datum>;

pub trait Monitor {
    fn process(&mut self, data: &Data);
}

pub type MonBox = Box<dyn Monitor>;