OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
data_copy.hpp
1#pragma once
2#include <ossia/dataflow/audio_port.hpp>
3#include <ossia/dataflow/data.hpp>
4#include <ossia/dataflow/geometry_port.hpp>
5#include <ossia/dataflow/midi_port.hpp>
6#include <ossia/dataflow/typed_value.hpp>
7#include <ossia/dataflow/value_port.hpp>
9#include <ossia/detail/nullable_variant.hpp>
10#include <ossia/network/base/parameter.hpp>
11namespace ossia
12{
13
14struct clear_data
15{
16 void operator()(value_port& p) const { p.clear(); }
17
18 void operator()(midi_port& p) const { p.messages.clear(); }
19
20 void operator()(audio_port& p) const { p.set_channels(0); }
21
22 void operator()(geometry_port& p) const { p.clear(); }
23
24 void operator()() const { }
25};
26
27struct data_size
28{
29 std::size_t operator()(const value_delay_line& p) const { return p.data.size(); }
30
31 std::size_t operator()(const midi_delay_line& p) const { return p.messages.size(); }
32
33 std::size_t operator()(const audio_delay_line& p) const { return p.samples.size(); }
34
35 std::size_t operator()(const geometry_delay_line& p) const
36 {
37 return p.geometries.size();
38 }
39
40 std::size_t operator()(const ossia::monostate&) const { return 0; }
41 std::size_t operator()() const { return 0; }
42};
43
44struct move_data
45{
46 void operator()(value_port& out, value_port& in)
47 {
48 in.add_port_values(std::move(out));
49 }
50
51 void operator()(audio_port& out, audio_port& in)
52 {
53 auto tmp = std::move(in.get());
54 in.get() = std::move(out.get());
55 out.get() = std::move(tmp);
56 }
57
58 void operator()(midi_port& out, midi_port& in)
59 {
60 auto tmp = std::move(in.messages);
61 in.messages = std::move(out.messages);
62 out.messages = std::move(tmp);
63 }
64
65 void operator()(geometry_port& out, geometry_port& in)
66 {
67 // OPTIMIZEME
68 // if(out.flags & geometry_port::dirty_meshes)
69 in.geometry = out.geometry; //std::move(out.meshes);
70 // if(out.flags & geometry_port::dirty_transform)
71 in.transform = out.transform;
72 in.flags = out.flags;
73 out.flags = {};
74 }
75};
76
77struct copy_data
78{
80 void
81 operator()(const value_vector<std::pair<ossia::typed_value, int>>& out, value_port& in)
82 {
83 // Called in local_pull_visitor
84 for(auto& val : out)
85 in.add_local_value(val.first);
86 }
87 void operator()(const value_vector<ossia::typed_value>& out, value_port& in)
88 {
89 // Called in copy_data_pos, when copying from a delay line to a port
90 for(auto& val : out)
91 in.add_local_value(val);
92 }
93
94 void operator()(const value_port& out, value_port& in)
95 {
96 // Called in init_node_visitor::copy, when copying from a node to another
97 in.add_port_values(out);
98 }
99
100 void operator()(const net::parameter_base& param, value_port& in)
101 {
102 // Called from global_pull_visitor
103 in.add_global_value(param, param.value());
104 }
105
106 void operator()(
107 const net::parameter_base& param, const value_vector<ossia::value>& vec,
108 value_port& in)
109 {
110 // Called from global_pull_visitor
111 in.add_global_values(param, vec);
112 }
113
114 void operator()(const value_port& out, value_delay_line& in)
115 {
116#if !defined(OSSIA_FREESTANDING)
117 // Called in env_writer, when copying from a node to a delay line
118 value_vector<ossia::typed_value> vec;
119 vec.reserve(out.get_data().size());
120 for(const ossia::timed_value& val : out.get_data())
121 {
122 vec.emplace_back(val, out.index, out.type);
123 }
124 in.data.push_back(std::move(vec));
125#endif
126 }
127
129 void operator()(const audio_port& out, audio_delay_line& in)
130 {
131 // Called in env_writer, when copying from a node to a delay line
132 in.samples.push_back(out.get());
133 }
134
135 void operator()(const audio_port& out, audio_port& in)
136 {
137 // Called in init_node_visitor::copy, when copying from a node to another
138 mix(out.get(), in.get());
139 }
140
142 void operator()(const midi_port& out, midi_port& in)
143 {
144 // Called in init_node_visitor::copy, when copying from a node to another
145 operator()(out.messages, in);
146 }
147
148 void operator()(const value_vector<libremidi::ump>& out, midi_port& in)
149 {
150 // Called in copy_data_pos, when copying from a delay line to a port
151 for(const auto& data : out)
152 in.messages.push_back(data);
153 }
154
155 void operator()(const midi_port& out, midi_delay_line& in)
156 {
157 // Called in env_writer, when copying from a node to a delay line
158 in.messages.push_back(out.messages);
159 }
160
162 void operator()(const geometry_port& out, geometry_port& in)
163 {
164 // Called in init_node_visitor::copy, when copying from a node to another
165 //if(out.flags & geometry_port::dirty_meshes)
166 in.geometry = out.geometry;
167 //if(out.flags & geometry_port::dirty_transform)
168 in.transform = out.transform;
169 in.flags = out.flags;
170 }
171
172 void operator()(const geometry_spec& out, geometry_port& in)
173 {
174 // Called in copy_data_pos below
175 in.geometry = out;
176 }
177
178 void operator()(const geometry_port& out, geometry_delay_line& in)
179 {
180 // Called in env_writer, when copying from a node to a delay line
181 // if(out.flags & geometry_port::dirty_meshes)
182 in.geometries.push_back(out.geometry);
183 }
184};
185
186struct copy_data_pos
187{
188 const std::size_t pos;
189
190 template <typename T, typename U>
191 void operator()(const T&, const U&) const
192 {
193 }
194
195 void operator()(const value_delay_line& out, value_port& in)
196 {
197 if(pos < out.data.size())
198 {
199 copy_data{}(out.data[pos], in);
200 }
201 }
202
203 void operator()(const audio_delay_line& out, audio_port& in)
204 {
205 if(pos < out.samples.size())
206 {
207 mix(out.samples[pos], in.get());
208 }
209 }
210
211 void operator()(const midi_delay_line& out, midi_port& in)
212 {
213 if(pos < out.messages.size())
214 {
215 copy_data{}(out.messages[pos], in);
216 }
217 }
218 void operator()(const geometry_delay_line& out, geometry_port& in)
219 {
220 if(pos < out.geometries.size())
221 {
222 copy_data{}(out.geometries[pos], in);
223 }
224 }
225};
226}
Definition git_info.h:7
Definition size.hpp:7