This repository has no description
1use serde::{Deserialize, Serialize};
2use std::{collections::HashMap, fmt::Display};
3
4#[derive(Serialize, Deserialize, Clone)]
5pub struct Probe {
6 pub id: u32,
7 pub added_at: String,
8 /// Maps automation parameter indices to their names
9 pub automation_names: HashMap<usize, String>,
10 /// MIDI In signal name
11 pub midi_name: String,
12 /// Audio In signal name
13 pub audio_name: String,
14
15 #[serde(skip)]
16 pub datapoints: Vec<Datapoint>,
17}
18
19#[derive(Clone)]
20pub enum Datapoint {
21 Automation(usize, usize, f32),
22 Midi(usize, Vec<u8>),
23 Audio(usize, Vec<f32>),
24}
25
26impl Probe {
27 /// Returns a new probe with the `added_at` field set to the current time.
28 pub fn with_added_at_now(&self) -> Self {
29 return Self {
30 added_at: chrono::Utc::now().to_rfc3339(),
31 ..self.clone()
32 };
33 }
34
35 pub fn store(&mut self, datapoint: Datapoint) {
36 self.datapoints.push(datapoint);
37 }
38}
39
40impl Display for Probe {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(f, "probe {} [", self.id)?;
43 if !self.automation_names.is_empty() {
44 write!(f, "automations {:?}", self.automation_names)?;
45 if !self.midi_name.is_empty() || !self.audio_name.is_empty() {
46 write!(f, " ")?;
47 }
48 }
49 if !self.midi_name.is_empty() {
50 write!(f, "midi \"{}\"", self.midi_name)?;
51 if !self.audio_name.is_empty() {
52 write!(f, " ")?;
53 }
54 }
55 if !self.audio_name.is_empty() {
56 write!(f, "audio \"{}\"", self.audio_name)?;
57 }
58 write!(f, "]")?;
59 return Ok(());
60 }
61}
62
63impl Default for Probe {
64 fn default() -> Self {
65 Self {
66 id: 0,
67 audio_name: String::new(),
68 midi_name: String::new(),
69 added_at: chrono::Utc::now().to_rfc3339(),
70 datapoints: Vec::new(),
71 automation_names: HashMap::new(),
72 }
73 }
74}