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
use crate::manifest::description::{Layer, PackFlow};
use crate::range::{Label, Range};
use crate::utils::new_tf;
use rill_protocol::flow::core::{Flow, TimedEvent};
use rill_protocol::io::provider::StreamType;
use rill_protocol::timed_frame::TimedFrame;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PulseSpec {
pub retain: u32,
pub range: Range,
pub label: Label,
}
impl Default for PulseSpec {
fn default() -> Self {
Self {
retain: 30,
range: Range::default(),
label: Label::default(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PulseState {
pub spec: PulseSpec,
pub frame: TimedFrame<f64>,
}
impl From<PulseSpec> for PulseState {
fn from(spec: PulseSpec) -> Self {
let frame = new_tf(spec.retain as i64 + 1);
Self { spec, frame }
}
}
impl PackFlow for PulseState {
fn layer() -> Layer {
Layer::Visual
}
}
impl Flow for PulseState {
type Action = ();
type Event = PulseEvent;
fn stream_type() -> StreamType {
StreamType::from(module_path!())
}
fn apply(&mut self, event: Self::Event) {
match event {
PulseEvent::Push { value } => {
self.frame.insert_pop(value);
}
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PulseEvent {
Push { value: TimedEvent<f64> },
}