Repository navigation
Expand file tree
/
Copy pathgraph_json.rs
More file actions
105 lines (92 loc) · 2.36 KB
/
Copy pathgraph_json.rs
File metadata and controls
105 lines (92 loc) · 2.36 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use serde;
/// The JSON incoming from our frontend: basically a 1:1 of what reactflow.toobject returns
#[derive(serde::Deserialize, Debug)]
pub struct GraphJson {
pub nodes: Vec<NodeJson>,
pub edges: Vec<EdgeJson>
}
#[derive(serde::Deserialize, Debug)]
pub struct NodeJson {
pub id: String,
// So far all node types have different nodejsondata so we can just this to decipher types,
// and not need the node_json that comes with reactflow's JSON output.
pub data: NodeJsonData
}
#[derive(serde::Deserialize, Debug, Clone, Copy)]
pub enum WaveType {
Sine,
Triangle,
Square,
Sawtooth
}
impl TryFrom<String> for WaveType {
type Error = ();
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.as_str() {
"sine" => Ok(WaveType::Sine),
"triangle" => Ok(WaveType::Triangle),
"square" => Ok(WaveType::Square),
"sawtooth" => Ok(WaveType::Sawtooth),
_ => Err(())
}
}
}
#[derive(serde::Deserialize, Debug, Clone, Copy)]
pub enum BinOp {
Add,
Sub,
Mul
}
impl TryFrom<String> for BinOp {
type Error = ();
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.as_str() {
"add" => Ok(BinOp::Add),
"sub" => Ok(BinOp::Sub),
"mul" => Ok(BinOp::Mul),
_ => Err(())
}
}
}
#[derive(serde::Deserialize, Debug, Clone, Copy)]
pub enum ShortBehavior {
Zero,
UseLastSample,
}
impl TryFrom<String> for ShortBehavior {
type Error = ();
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.as_str() {
"zero" => Ok(ShortBehavior::Zero),
"last_sample" => Ok(ShortBehavior::UseLastSample),
_ => Err(())
}
}
}
#[derive(serde::Deserialize, Debug)]
#[serde(untagged)]
pub enum NodeJsonData {
Input {
#[serde(rename = "filePath")]
file_path: String
},
WaveGen {
wave_type: String,
frequency: f32,
amplitude: f32,
seconds: f32
},
BinOp {
bin_op: String,
on_short_a: String,
on_short_b: String,
},
Output {}
}
#[derive(serde::Deserialize, Debug)]
pub struct EdgeJson {
pub source: String,
pub target: String,
#[serde(rename="targetHandle")]
pub target_handle: Option<String>
}