2#include <ossia/detail/parse_strict.hpp>
3#include <ossia/detail/string_view.hpp>
4#include <ossia/detail/to_string.hpp>
5#include <ossia/network/base/parameter.hpp>
6#include <ossia/network/common/value_bounding.hpp>
7#include <ossia/network/domain/domain.hpp>
8#include <ossia/network/osc/detail/osc_1_0_policy.hpp>
9#include <ossia/network/osc/detail/osc_fwd.hpp>
10#include <ossia/network/value/value.hpp>
12#include <oscpack/osc/OscOutboundPacketStream.h>
13#include <oscpack/osc/OscReceivedElements.h>
19 static float get_float(oscpack::ReceivedMessageArgumentIterator it,
float f)
23 case oscpack::INT32_TYPE_TAG:
24 return it->AsInt32Unchecked();
25 case oscpack::INT64_TYPE_TAG:
26 return it->AsInt64Unchecked();
27 case oscpack::FLOAT_TYPE_TAG:
28 return it->AsFloatUnchecked();
29 case oscpack::DOUBLE_TYPE_TAG:
30 return it->AsDoubleUnchecked();
31 case oscpack::TIME_TAG_TYPE_TAG:
32 return it->AsTimeTagUnchecked();
33 case oscpack::CHAR_TYPE_TAG:
34 return it->AsCharUnchecked();
35 case oscpack::TRUE_TYPE_TAG:
37 case oscpack::FALSE_TYPE_TAG:
39 case oscpack::STRING_TYPE_TAG:
40 if(
auto res = parse_strict<float>(it->AsStringUnchecked()))
43 case oscpack::SYMBOL_TYPE_TAG:
44 if(
auto res = parse_strict<float>(it->AsSymbolUnchecked()))
52 static int get_int(oscpack::ReceivedMessageArgumentIterator it,
int i)
56 case oscpack::INT32_TYPE_TAG:
57 return it->AsInt32Unchecked();
58 case oscpack::INT64_TYPE_TAG:
59 return int32_t(it->AsInt64Unchecked());
60 case oscpack::FLOAT_TYPE_TAG:
61 return int32_t(it->AsFloatUnchecked());
62 case oscpack::DOUBLE_TYPE_TAG:
63 return int32_t(it->AsDoubleUnchecked());
64 case oscpack::TIME_TAG_TYPE_TAG:
65 return int32_t(it->AsTimeTagUnchecked());
66 case oscpack::CHAR_TYPE_TAG:
67 return int32_t(it->AsCharUnchecked());
68 case oscpack::TRUE_TYPE_TAG:
70 case oscpack::FALSE_TYPE_TAG:
72 case oscpack::STRING_TYPE_TAG:
73 if(
auto res = parse_strict<int>(it->AsStringUnchecked()))
76 case oscpack::SYMBOL_TYPE_TAG:
77 if(
auto res = parse_strict<int>(it->AsSymbolUnchecked()))
85 static bool get_bool(oscpack::ReceivedMessageArgumentIterator it,
bool b)
87 using namespace std::literals;
90 case oscpack::INT32_TYPE_TAG:
91 return it->AsInt32Unchecked();
92 case oscpack::INT64_TYPE_TAG:
93 return it->AsInt64Unchecked();
94 case oscpack::FLOAT_TYPE_TAG:
95 return it->AsFloatUnchecked();
96 case oscpack::DOUBLE_TYPE_TAG:
97 return it->AsDoubleUnchecked();
98 case oscpack::TIME_TAG_TYPE_TAG:
99 return it->AsTimeTagUnchecked();
100 case oscpack::CHAR_TYPE_TAG:
101 return it->AsCharUnchecked();
102 case oscpack::TRUE_TYPE_TAG:
104 case oscpack::FALSE_TYPE_TAG:
106 case oscpack::STRING_TYPE_TAG:
107 return (std::string_view(it->AsStringUnchecked()) ==
"1"sv);
108 case oscpack::SYMBOL_TYPE_TAG:
109 return (std::string_view(it->AsSymbolUnchecked()) ==
"1"sv);
115 static char get_char(oscpack::ReceivedMessageArgumentIterator it,
char c)
117 switch(it->TypeTag())
119 case oscpack::INT32_TYPE_TAG:
120 return char(it->AsInt32Unchecked());
121 case oscpack::INT64_TYPE_TAG:
122 return char(it->AsInt64Unchecked());
123 case oscpack::FLOAT_TYPE_TAG:
124 return char(it->AsFloatUnchecked());
125 case oscpack::DOUBLE_TYPE_TAG:
126 return char(it->AsDoubleUnchecked());
127 case oscpack::TIME_TAG_TYPE_TAG:
128 return char(it->AsTimeTagUnchecked());
129 case oscpack::CHAR_TYPE_TAG:
130 return char(it->AsCharUnchecked());
131 case oscpack::TRUE_TYPE_TAG:
133 case oscpack::FALSE_TYPE_TAG:
135 case oscpack::STRING_TYPE_TAG:
136 return char{it->AsStringUnchecked()[0]};
137 case oscpack::SYMBOL_TYPE_TAG:
138 return char{it->AsSymbolUnchecked()[0]};
144 static std::string get_blob(oscpack::ReceivedMessageArgumentIterator it)
147 oscpack::osc_bundle_element_size_t size{};
148 it->AsBlobUnchecked(data, size);
150 return std::string{(
const char*)data, (std::size_t)size};
151 return std::string{};
154 static ossia::value create_value(oscpack::ReceivedMessageArgumentIterator it)
156 switch(it->TypeTag())
158 case oscpack::INT32_TYPE_TAG:
159 return int32_t{it->AsInt32Unchecked()};
160 case oscpack::INT64_TYPE_TAG:
161 return int32_t{(int)it->AsInt64Unchecked()};
162 case oscpack::FLOAT_TYPE_TAG:
163 return float{it->AsFloatUnchecked()};
164 case oscpack::DOUBLE_TYPE_TAG:
165 return float{(float)it->AsDoubleUnchecked()};
166 case oscpack::TIME_TAG_TYPE_TAG:
167 return int32_t(it->AsTimeTagUnchecked());
168 case oscpack::CHAR_TYPE_TAG:
169 return char{it->AsCharUnchecked()};
170 case oscpack::TRUE_TYPE_TAG:
172 case oscpack::FALSE_TYPE_TAG:
174 case oscpack::STRING_TYPE_TAG:
175 return std::string{it->AsStringUnchecked()};
176 case oscpack::SYMBOL_TYPE_TAG:
177 return std::string{it->AsSymbolUnchecked()};
178 case oscpack::BLOB_TYPE_TAG:
180 case oscpack::RGBA_COLOR_TYPE_TAG: {
181 auto c = it->AsRgbaColorUnchecked();
183 uint8_t(c >> 24 & 0xFF), uint8_t(c >> 16 & 0xFF), uint8_t(c >> 8 & 0xFF),
187 return ossia::impulse{};
191 static std::vector<ossia::value> create_list_(
192 oscpack::ReceivedMessageArgumentIterator& it,
193 oscpack::ReceivedMessageArgumentIterator& end)
195 std::vector<ossia::value> t;
196 for(; it != end; ++it)
198 switch(it->TypeTag())
200 case oscpack::INT32_TYPE_TAG:
201 t.emplace_back(int32_t{it->AsInt32Unchecked()});
203 case oscpack::INT64_TYPE_TAG:
204 t.emplace_back(int32_t{(int)it->AsInt64Unchecked()});
206 case oscpack::FLOAT_TYPE_TAG:
207 t.emplace_back(
float{it->AsFloatUnchecked()});
209 case oscpack::DOUBLE_TYPE_TAG:
210 t.emplace_back(
float{(float)it->AsDoubleUnchecked()});
212 case oscpack::TIME_TAG_TYPE_TAG:
213 t.emplace_back(int32_t(it->AsTimeTagUnchecked()));
215 case oscpack::CHAR_TYPE_TAG:
216 t.emplace_back(
char{it->AsCharUnchecked()});
218 case oscpack::TRUE_TYPE_TAG:
219 t.emplace_back(
bool{
true});
221 case oscpack::FALSE_TYPE_TAG:
222 t.emplace_back(
bool{
false});
224 case oscpack::STRING_TYPE_TAG:
225 t.push_back(std::string{it->AsStringUnchecked()});
227 case oscpack::SYMBOL_TYPE_TAG:
228 t.push_back(std::string{it->AsSymbolUnchecked()});
230 case oscpack::BLOB_TYPE_TAG:
231 t.emplace_back(get_blob(it));
233 case oscpack::RGBA_COLOR_TYPE_TAG: {
234 auto c = it->AsRgbaColorUnchecked();
235 t.emplace_back(make_vec(
236 uint8_t(c >> 24 & 0xFF), uint8_t(c >> 16 & 0xFF), uint8_t(c >> 8 & 0xFF),
240 case oscpack::ARRAY_BEGIN_TYPE_TAG: {
242 t.emplace_back(create_list_(it, end));
245 case oscpack::ARRAY_END_TYPE_TAG: {
251 t.push_back(ossia::impulse{});
258 static std::vector<ossia::value> create_list(
259 oscpack::ReceivedMessageArgumentIterator it,
260 oscpack::ReceivedMessageArgumentIterator end)
262 return create_list_(it, end);
266 oscpack::ReceivedMessageArgumentIterator cur_it,
267 oscpack::ReceivedMessageArgumentIterator end,
int numArguments)
272 return ossia::impulse{};
274 return create_value(cur_it);
276 return value{create_list(cur_it, end)};
281struct osc_inbound_visitor
284 oscpack::ReceivedMessageArgumentIterator cur,
285 oscpack::ReceivedMessageArgumentIterator beg,
286 oscpack::ReceivedMessageArgumentIterator end,
int n = 1)
294 oscpack::ReceivedMessageArgumentIterator cur_it;
295 oscpack::ReceivedMessageArgumentIterator beg_it;
296 oscpack::ReceivedMessageArgumentIterator end_it;
297 int numArguments = 1;
299 ossia::value operator()(ossia::impulse imp)
const {
return imp; }
301 ossia::value operator()(int32_t i)
const {
return osc_utilities::get_int(cur_it, i); }
303 ossia::value operator()(
float f)
const {
return osc_utilities::get_float(cur_it, f); }
305 ossia::value operator()(
bool b)
const {
return osc_utilities::get_bool(cur_it, b); }
307 ossia::value operator()(
char c)
const {
return osc_utilities::get_char(cur_it, c); }
311 switch(cur_it->TypeTag())
313 case oscpack::INT32_TYPE_TAG:
314 return ossia::to_string(cur_it->AsInt32Unchecked());
315 case oscpack::INT64_TYPE_TAG:
316 return ossia::to_string(cur_it->AsInt64Unchecked());
317 case oscpack::FLOAT_TYPE_TAG:
318 return ossia::to_string(cur_it->AsFloatUnchecked());
319 case oscpack::DOUBLE_TYPE_TAG:
320 return ossia::to_string(cur_it->AsDoubleUnchecked());
321 case oscpack::CHAR_TYPE_TAG:
322 return std::string(1, cur_it->AsCharUnchecked());
323 case oscpack::TRUE_TYPE_TAG:
324 return std::string{
"true"};
325 case oscpack::FALSE_TYPE_TAG:
326 return std::string{
"false"};
327 case oscpack::STRING_TYPE_TAG:
328 return std::string{cur_it->AsStringUnchecked()};
329 case oscpack::SYMBOL_TYPE_TAG:
330 return std::string{cur_it->AsSymbolUnchecked()};
336 template <std::
size_t N>
339 if(numArguments == N)
341 std::array<float, N> ret;
343 auto vec_it = beg_it;
344 auto vec_end = end_it;
345 for(; vec_it != vec_end; ++vec_it)
347 ret[i] = osc_utilities::get_float(vec_it, vec[i]);
356 if(cur_it->TypeTag() == oscpack::RGBA_COLOR_TYPE_TAG)
358 auto c = cur_it->AsRgbaColorUnchecked();
360 uint8_t(c >> 24 & 0xFF), uint8_t(c >> 16 & 0xFF), uint8_t(c >> 8 & 0xFF),
368 ossia::value operator()(
const std::vector<ossia::value>&)
382 return value{osc_utilities::create_list(cur_it, end_it)};
385 ossia::value operator()(
const value_map_type&) {
return value{value_map_type{}}; }
390struct osc_inbound_impulse_visitor
393 template <
typename T>
400 ossia::value operator()(
const std::vector<ossia::value>& t)
const
409 const ossia::value& current, oscpack::ReceivedMessageArgumentIterator beg_it,
410 oscpack::ReceivedMessageArgumentIterator end_it,
int N)
413 return current.apply(osc_inbound_visitor{beg_it, beg_it, end_it, N});
415 return current.apply(osc_inbound_impulse_visitor{});
420 oscpack::ReceivedMessageArgumentIterator end_it,
int N)
423 addr.get_domain(), ossia::net::to_value(addr.
value(), beg_it, end_it, N),
424 addr.get_bounding());
430 return get_filtered_value(
431 addr, mess.ArgumentsBegin(), mess.ArgumentsEnd(), mess.ArgumentCount());
434struct osc_write_domain_visitor
436 ossia::net::osc_1_0_outbound_stream_visitor vis;
437 template <
typename T>
438 void operator()(
const T& dom)
440 if(dom.min && dom.max)
447 template <std::
size_t N>
448 void operator()(
const vecf_domain<N>& dom)
450 if(dom.min[0] && dom.max[0])
457 void operator()(
const vector_domain& dom)
459 if(!dom.min.empty() && !dom.max.empty() && dom.min[0].valid() && dom.max[0].valid())
461 vis(ossia::convert<float>(dom.min[0]));
462 vis(ossia::convert<float>(dom.max[0]));
466 void operator()(
const domain_base<ossia::value>& dom)
468 if(dom.min && dom.max)
470 vis(ossia::convert<float>(*dom.min));
471 vis(ossia::convert<float>(*dom.max));
475 void operator()(
const domain_base<bool>& dom)
481 void operator()(
const domain_base<ossia::impulse>& dom) { }
483 void operator()(
const domain_base<std::string>& dom) { }
485 void operator()() { }
500inline oscpack::OutboundPacketStream&
501operator<<(oscpack::OutboundPacketStream& p,
const ossia::domain& dom)
504 ossia::net::osc_write_domain_visitor{
505 ossia::net::osc_1_0_outbound_stream_visitor{p,
ossia::unit_t{}}},
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
virtual ossia::value value() const =0
Clone the current value without any network request.
The value class.
Definition value.hpp:173
value to_value(const value_with_unit &v)
convert Convert a value + unit to a simple value
Definition dataspace_visitors.cpp:232
domain A domain of values
Definition domain_base.hpp:23
Definition dataspace.hpp:24