OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
osc_1_1_policy.hpp
1#pragma once
2#include <ossia/network/osc/detail/osc_common_policy.hpp>
3#include <ossia/network/osc/detail/osc_utils.hpp>
4#include <ossia/network/value/value.hpp>
5
6#include <boost/endian/conversion.hpp>
7
8#include <oscpack/osc/OscOutboundPacketStream.h>
9#include <oscpack/osc/OscTypes.h>
10
11// OSC 1.1 adds T, F, I, N
12namespace ossia::net
13{
14
15struct osc_1_1_outbound_array_policy : osc_common_outbound_dynamic_policy
16{
17 using osc_common_outbound_dynamic_policy::operator();
18 void operator()(impulse) const { p << oscpack::Infinitum(); }
19
20 void operator()(bool b) const { p << b; }
21
22 void operator()(char c) const { p << int32_t(c); }
23
24 // Arrays are flattened
25 void operator()(const std::vector<value>& t) const
26 {
27 for(const auto& val : t)
28 {
29 val.apply(*this);
30 }
31 }
32
33 void operator()(const value_map_type& t) const
34 {
35 for(const auto& [k, v] : t)
36 {
37 (*this)(k);
38 v.apply(*this);
39 }
40 }
41};
42
43struct osc_1_1_outbound_value_policy : osc_common_outbound_static_policy
44{
45 using osc_common_outbound_static_policy::operator();
46 std::size_t operator()(
47 char* buffer, ossia::impulse v, const ossia::extended_type& t) const noexcept
48 {
49 // NOTE: this is a change wrt the old ossia::oscquery::osc_outbound_visitor
50 buffer[0] = ',';
51 if(t.empty())
52 buffer[1] = oscpack::INFINITUM_TYPE_TAG;
53 else if(t == "nil")
54 buffer[1] = oscpack::NIL_TYPE_TAG;
55 else if(t == "empty")
56 buffer[1] = '\0';
57 buffer[2] = '\0';
58 buffer[3] = '\0';
59
60 return 4;
61 }
62
63 std::size_t operator()(char* buffer, ossia::impulse v) const noexcept
64 {
65 // NOTE: this is a change wrt the old ossia::oscquery::osc_outbound_visitor
66 buffer[0] = ',';
67 buffer[1] = '\0';
68 buffer[2] = '\0';
69 buffer[3] = '\0';
70
71 return 4;
72 }
73
74 std::size_t operator()(char* buffer, bool v) const noexcept
75 {
76 buffer[0] = ',';
77 buffer[1] = v ? oscpack::TRUE_TYPE_TAG : oscpack::FALSE_TYPE_TAG;
78 buffer[2] = '\0';
79 buffer[3] = '\0';
80
81 return 4;
82 }
83
84 std::size_t operator()(char* buffer, char v) const noexcept
85 {
86 return osc_common_outbound_static_policy::operator()(buffer, int32_t{v});
87 }
88};
89
90struct osc_1_1_policy
91{
92 using static_policy = osc_1_1_outbound_value_policy;
93 using dynamic_policy = osc_1_1_outbound_array_policy;
94};
95
96}
std::string extended_type
How a low-level type should be interpreted.
Definition complex_type.hpp:9