melodium_engine/designer/
connection.rs1use super::{Reference, TreatmentInstanciation};
2use melodium_common::descriptor::{Attribuable, Attributes};
3use std::sync::{Arc, RwLock, Weak};
4
5#[derive(Debug)]
6pub enum IO {
7 Sequence(),
8 Treatment(Weak<RwLock<TreatmentInstanciation>>),
9}
10
11impl PartialEq for IO {
12 fn eq(&self, other: &Self) -> bool {
13 match self {
14 IO::Sequence() => false,
15 IO::Treatment(s_t) => match other {
16 IO::Sequence() => false,
17 IO::Treatment(o_t) => s_t.ptr_eq(o_t),
18 },
19 }
20 }
21}
22
23#[derive(Debug)]
36pub struct Connection {
37 pub output_treatment: IO,
38 pub output_name: String,
39
40 pub input_treatment: IO,
41 pub input_name: String,
42
43 pub attributes: Attributes,
44
45 pub design_reference: Option<Arc<dyn Reference>>,
46}
47
48impl Connection {
49 pub fn new_internal(
50 output_name: &str,
51 output_treatment: &Arc<RwLock<TreatmentInstanciation>>,
52 input_name: &str,
53 input_treatment: &Arc<RwLock<TreatmentInstanciation>>,
54 attributes: Attributes,
55 design_reference: Option<Arc<dyn Reference>>,
56 ) -> Self {
57 Self {
58 output_name: output_name.to_string(),
59 output_treatment: IO::Treatment(Arc::downgrade(output_treatment)),
60 input_name: input_name.to_string(),
61 input_treatment: IO::Treatment(Arc::downgrade(input_treatment)),
62 attributes,
63 design_reference,
64 }
65 }
66
67 pub fn new_self(
68 self_input_name: &str,
69 self_output_name: &str,
70 attributes: Attributes,
71 design_reference: Option<Arc<dyn Reference>>,
72 ) -> Self {
73 Self {
74 output_name: self_input_name.to_string(),
75 output_treatment: IO::Sequence(),
76 input_name: self_output_name.to_string(),
77 input_treatment: IO::Sequence(),
78 attributes,
79 design_reference,
80 }
81 }
82
83 pub fn new_self_to_internal(
84 self_input_name: &str,
85 input_name: &str,
86 input_treatment: &Arc<RwLock<TreatmentInstanciation>>,
87 attributes: Attributes,
88 design_reference: Option<Arc<dyn Reference>>,
89 ) -> Self {
90 Self {
91 output_name: self_input_name.to_string(),
92 output_treatment: IO::Sequence(),
93 input_name: input_name.to_string(),
94 input_treatment: IO::Treatment(Arc::downgrade(input_treatment)),
95 attributes,
96 design_reference,
97 }
98 }
99
100 pub fn new_internal_to_self(
101 output_name: &str,
102 output_treatment: &Arc<RwLock<TreatmentInstanciation>>,
103 self_output_name: &str,
104 attributes: Attributes,
105 design_reference: Option<Arc<dyn Reference>>,
106 ) -> Self {
107 Self {
108 output_name: output_name.to_string(),
109 output_treatment: IO::Treatment(Arc::downgrade(output_treatment)),
110 input_name: self_output_name.to_string(),
111 input_treatment: IO::Sequence(),
112 attributes,
113 design_reference,
114 }
115 }
116}
117
118impl Attribuable for Connection {
119 fn attributes(&self) -> &Attributes {
120 &self.attributes
121 }
122}