OSSIA
Open Scenario System for Interactive Application
node_attributes.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
5 #include <ossia/detail/hash_map.hpp>
6 #include <ossia/detail/optional.hpp>
8 #include <ossia/network/base/parameter.hpp>
9 #include <ossia/network/common/extended_types.hpp>
10 #include <ossia/network/common/parameter_properties.hpp>
11 #include <ossia/network/value/value.hpp>
12 
13 #include <string>
14 #include <vector>
15 
27 namespace ossia
28 {
29 namespace net
30 {
31 class node_base;
32 struct parameter_data;
33 
35 struct OSSIA_EXPORT instance_bounds
36 {
37  instance_bounds() = default;
38  instance_bounds(const instance_bounds&) = default;
39  instance_bounds(instance_bounds&&) = default;
40  instance_bounds& operator=(const instance_bounds&) = default;
41  instance_bounds& operator=(instance_bounds&&) = default;
42 
43  instance_bounds(int32_t min, int32_t max)
44  : min_instances{min}
45  , max_instances{max}
46  {
47  }
48 
49  int32_t min_instances = 0;
50  int32_t max_instances = std::numeric_limits<int32_t>::max();
51 
52  friend bool operator==(const instance_bounds& lhs, const instance_bounds& rhs)
53  {
54  return lhs.min_instances == rhs.min_instances
55  && lhs.max_instances == rhs.max_instances;
56  }
57  friend bool operator!=(const instance_bounds& lhs, const instance_bounds& rhs)
58  {
59  return !(lhs == rhs);
60  }
61 
62  // TODO, currently only here for ossia::any
63  friend std::ostream& operator<<(std::ostream& os, const instance_bounds& c)
64  {
65  return os;
66  }
67  friend std::istream& operator>>(std::istream& is, instance_bounds& c) { return is; }
68 };
69 
71 using tags = std::vector<std::string>;
72 
74 using description = std::string;
75 
77 using priority = float;
78 
80 using refresh_rate = int32_t;
81 
83 using recall_safe = bool;
84 
86 using value_step_size = double;
87 
90 
92 using critical = bool;
93 
95 using disabled = bool;
96 
98 using zombie = bool;
99 
101 using hidden = bool;
102 
104 using muted = bool;
105 
107 using app_name = std::string;
108 
110 using app_version = std::string;
111 
113 using app_creator = std::string;
114 
115 OSSIA_EXPORT std::string_view text_instance_bounds();
116 OSSIA_EXPORT std::optional<instance_bounds>
117 get_instance_bounds(const extended_attributes& n);
118 OSSIA_EXPORT void
119 set_instance_bounds(extended_attributes& n, std::optional<instance_bounds>);
120 OSSIA_EXPORT void
121 set_instance_bounds(ossia::net::node_base& n, std::optional<instance_bounds>);
122 
123 OSSIA_EXPORT std::string_view text_tags();
124 OSSIA_EXPORT std::optional<tags> get_tags(const extended_attributes& n);
125 OSSIA_EXPORT void set_tags(extended_attributes& n, std::optional<tags> v);
126 OSSIA_EXPORT void set_tags(ossia::net::node_base& n, std::optional<tags> v);
127 
128 OSSIA_EXPORT std::string_view text_description();
129 OSSIA_EXPORT std::optional<description> get_description(const extended_attributes& n);
130 OSSIA_EXPORT void set_description(extended_attributes& n, std::optional<description> v);
131 OSSIA_EXPORT void set_description(extended_attributes& n, const char* v);
132 OSSIA_EXPORT void
133 set_description(ossia::net::node_base& n, std::optional<description> v);
134 OSSIA_EXPORT void set_description(ossia::net::node_base& n, const char* v);
135 
136 OSSIA_EXPORT std::string_view text_priority();
137 OSSIA_EXPORT std::optional<priority> get_priority(const extended_attributes& n);
138 OSSIA_EXPORT void set_priority(extended_attributes& n, std::optional<priority> v);
139 OSSIA_EXPORT void set_priority(ossia::net::node_base& n, std::optional<priority> v);
140 
141 OSSIA_EXPORT std::string_view text_refresh_rate();
142 OSSIA_EXPORT std::optional<refresh_rate> get_refresh_rate(const extended_attributes& n);
143 OSSIA_EXPORT void
144 set_refresh_rate(extended_attributes& n, std::optional<refresh_rate> v);
145 OSSIA_EXPORT void
146 set_refresh_rate(ossia::net::node_base& n, std::optional<refresh_rate> v);
147 
148 OSSIA_EXPORT std::string_view text_value_step_size();
149 OSSIA_EXPORT std::optional<value_step_size>
150 get_value_step_size(const extended_attributes& n);
151 OSSIA_EXPORT void
152 set_value_step_size(extended_attributes& n, std::optional<value_step_size> v);
153 OSSIA_EXPORT void
154 set_value_step_size(ossia::net::node_base& n, std::optional<value_step_size> v);
155 
156 OSSIA_EXPORT std::string_view text_zombie();
157 OSSIA_EXPORT zombie get_zombie(const extended_attributes& n);
158 OSSIA_EXPORT void set_zombie(extended_attributes& n, zombie v);
159 OSSIA_EXPORT void set_zombie(ossia::net::node_base& n, zombie v);
160 
161 OSSIA_EXPORT std::string_view text_hidden();
162 OSSIA_EXPORT hidden get_hidden(const extended_attributes& n);
163 OSSIA_EXPORT void set_hidden(extended_attributes& n, hidden v);
164 OSSIA_EXPORT void set_hidden(ossia::net::node_base& n, hidden v);
165 
166 OSSIA_EXPORT std::string_view text_recall_safe();
167 OSSIA_EXPORT recall_safe get_recall_safe(const extended_attributes& n);
168 OSSIA_EXPORT void set_recall_safe(extended_attributes& n, recall_safe v);
169 OSSIA_EXPORT void set_recall_safe(ossia::net::node_base& n, recall_safe v);
170 
171 OSSIA_EXPORT std::string_view text_extended_type();
172 OSSIA_EXPORT std::optional<extended_type>
173 get_extended_type(const ossia::net::node_base& n);
174 OSSIA_EXPORT std::optional<extended_type>
175 get_extended_type(const ossia::net::parameter_base& n);
176 OSSIA_EXPORT std::optional<extended_type>
177 get_extended_type(const extended_attributes& n);
178 OSSIA_EXPORT void
179 set_extended_type(extended_attributes& n, std::optional<extended_type> v);
180 OSSIA_EXPORT void
181 set_extended_type(ossia::net::node_base& n, std::optional<extended_type> v);
182 
183 OSSIA_EXPORT std::string_view text_app_name();
184 OSSIA_EXPORT std::optional<app_name> get_app_name(const extended_attributes& n);
185 OSSIA_EXPORT void set_app_name(extended_attributes& n, std::optional<app_name> v);
186 OSSIA_EXPORT void set_app_name(ossia::net::node_base& n, std::optional<app_name> v);
187 OSSIA_EXPORT void set_app_name(extended_attributes& n, const char* v); // to please clang
188 OSSIA_EXPORT void set_app_name(ossia::net::node_base& n, const char* v);
189 
190 OSSIA_EXPORT std::string_view text_app_version();
191 OSSIA_EXPORT std::optional<app_version> get_app_version(const extended_attributes& n);
192 OSSIA_EXPORT void set_app_version(extended_attributes& n, std::optional<app_version> v);
193 OSSIA_EXPORT void
194 set_app_version(ossia::net::node_base& n, std::optional<app_version> v);
195 OSSIA_EXPORT void
196 set_app_version(extended_attributes& n, const char* v); // to please clang
197 OSSIA_EXPORT void set_app_version(ossia::net::node_base& n, const char* v);
198 
199 OSSIA_EXPORT std::string_view text_app_creator();
200 OSSIA_EXPORT std::optional<app_creator> get_app_creator(const extended_attributes& n);
201 OSSIA_EXPORT void set_app_creator(extended_attributes& n, std::optional<app_creator> v);
202 OSSIA_EXPORT void
203 set_app_creator(ossia::net::node_base& n, std::optional<app_creator> v);
204 OSSIA_EXPORT void
205 set_app_creator(extended_attributes& n, const char* v); // to please clang
206 OSSIA_EXPORT void set_app_creator(ossia::net::node_base& n, const char* v);
207 
208 OSSIA_EXPORT std::string_view text_default_value();
209 OSSIA_EXPORT std::optional<ossia::value> get_default_value(const extended_attributes& n);
210 OSSIA_EXPORT void set_default_value(extended_attributes& n, const ossia::value& v);
211 OSSIA_EXPORT void set_default_value(extended_attributes& n, ossia::value&& v);
212 OSSIA_EXPORT void set_default_value(extended_attributes& n, int v);
213 OSSIA_EXPORT void set_default_value(extended_attributes& n, long v);
214 OSSIA_EXPORT void set_default_value(extended_attributes& n, bool v);
215 OSSIA_EXPORT void set_default_value(extended_attributes& n, char v);
216 OSSIA_EXPORT void set_default_value(extended_attributes& n, float v);
217 OSSIA_EXPORT void set_default_value(extended_attributes& n, double v);
218 OSSIA_EXPORT void set_default_value(extended_attributes& n, const char* v);
219 OSSIA_EXPORT void set_default_value(extended_attributes& n, std::nullopt_t v);
220 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, const ossia::value& v);
221 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, ossia::value&& v);
222 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, int v);
223 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, long v);
224 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, bool v);
225 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, char v);
226 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, float v);
227 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, double v);
228 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, const char* v);
229 OSSIA_EXPORT void set_default_value(ossia::net::node_base& n, std::nullopt_t v);
230 
231 // These attributes require a parameter
232 OSSIA_EXPORT std::string_view text_value();
233 OSSIA_EXPORT value clone_value(const ossia::net::node_base& n);
234 OSSIA_EXPORT void set_value(ossia::net::node_base& n, value v);
235 OSSIA_EXPORT void set_value(ossia::net::parameter_data& n, value v);
236 
237 OSSIA_EXPORT std::string_view text_value_type();
238 OSSIA_EXPORT std::optional<val_type> get_value_type(const ossia::net::node_base& n);
239 OSSIA_EXPORT void set_value_type(ossia::net::node_base& n, val_type v);
240 
241 OSSIA_EXPORT std::string_view text_domain();
242 OSSIA_EXPORT domain get_domain(const ossia::net::node_base& n);
243 OSSIA_EXPORT void set_domain(ossia::net::node_base& n, const domain& v);
244 OSSIA_EXPORT void set_domain(ossia::net::parameter_data& n, const domain& v);
245 
246 OSSIA_EXPORT std::string_view text_access_mode();
247 OSSIA_EXPORT std::optional<access_mode> get_access_mode(const ossia::net::node_base& n);
248 OSSIA_EXPORT void set_access_mode(ossia::net::node_base& n, access_mode v);
249 OSSIA_EXPORT void set_access_mode(ossia::net::parameter_data& n, access_mode v);
250 
251 OSSIA_EXPORT std::string_view text_bounding_mode();
252 OSSIA_EXPORT std::optional<bounding_mode>
253 get_bounding_mode(const ossia::net::node_base& n);
254 OSSIA_EXPORT void set_bounding_mode(ossia::net::node_base& n, bounding_mode v);
255 OSSIA_EXPORT void set_bounding_mode(ossia::net::parameter_data& n, bounding_mode v);
256 
257 OSSIA_EXPORT std::string_view text_repetition_filter();
258 OSSIA_EXPORT repetition_filter get_repetition_filter(const ossia::net::node_base& n);
259 OSSIA_EXPORT void set_repetition_filter(ossia::net::node_base& n, repetition_filter v);
260 OSSIA_EXPORT void
261 set_repetition_filter(ossia::net::parameter_data& n, repetition_filter v);
262 
263 OSSIA_EXPORT std::string_view text_unit();
264 OSSIA_EXPORT unit_t get_unit(const ossia::net::node_base& n);
265 OSSIA_EXPORT void set_unit(ossia::net::node_base& n, unit_t v);
266 OSSIA_EXPORT void set_unit(ossia::net::parameter_data& n, unit_t v);
267 
268 OSSIA_EXPORT std::string_view text_muted();
269 OSSIA_EXPORT muted get_muted(const ossia::net::node_base& n);
270 OSSIA_EXPORT void set_muted(ossia::net::node_base& n, muted v);
271 OSSIA_EXPORT void set_muted(ossia::net::parameter_data& n, muted v);
272 
273 OSSIA_EXPORT std::string_view text_disabled();
274 OSSIA_EXPORT disabled get_disabled(const ossia::net::node_base& n);
275 OSSIA_EXPORT void set_disabled(ossia::net::node_base& n, disabled v);
276 OSSIA_EXPORT void set_disabled(ossia::net::parameter_data& n, disabled v);
277 
278 OSSIA_EXPORT std::string_view text_critical();
279 OSSIA_EXPORT critical get_critical(const ossia::net::node_base& n);
280 OSSIA_EXPORT void set_critical(ossia::net::node_base& n, critical v);
281 OSSIA_EXPORT void set_critical(ossia::net::parameter_data& n, critical v);
282 
283 template <typename T>
284 struct is_parameter_attribute : public std::false_type
285 {
286 };
287 // Some macros to have minimal reflection facilities...
288 #define OSSIA_ATTRIBUTE(Type, Name) \
289  struct OSSIA_EXPORT Name##_attribute \
290  { \
291  using type = Type; \
292  static auto text() \
293  { \
294  return ossia::net::text_##Name(); \
295  } \
296  template <typename... Args> \
297  static auto getter(Args&&... args) \
298  { \
299  return ossia::net::get_##Name(std::forward<Args>(args)...); \
300  } \
301  template <typename... Args> \
302  static auto setter(Args&&... args) \
303  { \
304  return ossia::net::set_##Name(std::forward<Args>(args)...); \
305  } \
306  };
307 
308 #define OSSIA_PARAM_ATTRIBUTE(Type, Name) \
309  OSSIA_ATTRIBUTE(Type, Name) \
310  template <> \
311  struct is_parameter_attribute<Name##_attribute> : public std::true_type \
312  { \
313  };
314 
315 #define OSSIA_ATTRIBUTE_2(Type, Name, Text, Get, Set) \
316  struct OSSIA_EXPORT Name##_attribute \
317  { \
318  using type = Type; \
319  static auto text() \
320  { \
321  return Text(); \
322  } \
323  template <typename... Args> \
324  static auto getter(Args&&... args) \
325  { \
326  return Get(std::forward<Args>(args)...); \
327  } \
328  template <typename... Args> \
329  static auto setter(Args&&... args) \
330  { \
331  return Set(std::forward<Args>(args)...); \
332  } \
333  };
334 
335 // Attributes of a parameter
336 OSSIA_ATTRIBUTE_2(
337  ossia::value, value, ossia::net::text_value, ossia::net::clone_value,
338  ossia::net::push_value)
339 
340 template <>
341 struct is_parameter_attribute<value_attribute> : public std::true_type
342 {
343 };
344 
345 OSSIA_PARAM_ATTRIBUTE(ossia::val_type, value_type)
346 OSSIA_PARAM_ATTRIBUTE(ossia::domain, domain)
347 OSSIA_PARAM_ATTRIBUTE(ossia::access_mode, access_mode)
348 OSSIA_PARAM_ATTRIBUTE(ossia::bounding_mode, bounding_mode)
349 OSSIA_PARAM_ATTRIBUTE(ossia::unit_t, unit)
350 OSSIA_PARAM_ATTRIBUTE(ossia::value, default_value)
351 OSSIA_PARAM_ATTRIBUTE(ossia::net::disabled, disabled)
352 OSSIA_PARAM_ATTRIBUTE(ossia::net::muted, muted)
353 OSSIA_PARAM_ATTRIBUTE(ossia::net::critical, critical)
354 
355 // Metadata attributes
356 OSSIA_ATTRIBUTE(ossia::net::tags, tags)
357 OSSIA_ATTRIBUTE(ossia::net::description, description)
358 OSSIA_ATTRIBUTE(ossia::net::refresh_rate, refresh_rate)
359 OSSIA_ATTRIBUTE(ossia::net::priority, priority)
360 OSSIA_ATTRIBUTE(ossia::net::value_step_size, value_step_size)
361 OSSIA_ATTRIBUTE(ossia::net::instance_bounds, instance_bounds)
362 OSSIA_ATTRIBUTE(ossia::extended_type, extended_type)
364 OSSIA_ATTRIBUTE(ossia::net::app_name, app_name)
365 OSSIA_ATTRIBUTE(ossia::net::app_creator, app_creator)
366 OSSIA_ATTRIBUTE(ossia::net::app_version, app_version)
367 OSSIA_ATTRIBUTE(ossia::net::hidden, hidden)
368 
369 template <typename T, typename U>
370 bool compare_optional(const T& t, const U& u)
371 {
372  return !t || (t && *t != u);
373 }
374 inline bool compare_optional(const ossia::value& t, const ossia::value& u)
375 {
376  return t != u;
377 }
378 template <typename U>
379 inline bool compare_optional(const ossia::domain& t, const U& u)
380 {
381  return t != u;
382 }
383 template <typename U>
384 inline bool compare_optional(const ossia::unit_t& t, const U& u)
385 {
386  return t != u;
387 }
388 inline bool compare_optional(bool t, bool u)
389 {
390  return t != u;
391 }
392 inline bool compare_optional(ossia::repetition_filter t, ossia::repetition_filter u)
393 {
394  return t != u;
395 }
396 
397 inline bool valid(const ossia::value& v)
398 {
399  return v.valid();
400 }
401 template <typename T>
402 inline bool valid(const T& v)
403 {
404  return bool(v);
405 }
406 }
407 }
The node_base class.
Definition: network/base/node.hpp:48
The parameter_base class.
Definition: ossia/network/base/parameter.hpp:48
The value class.
Definition: value.hpp:173
Definition: git_info.h:7
val_type
Enum to represent the types that a value can take.
Definition: parameter_properties.hpp:16
repetition_filter
If enabled, sending twice the same value will only send it once by network.
Definition: parameter_properties.hpp:70
bounding_mode
Address behaviors at crossing domain boundaries.
Definition: parameter_properties.hpp:56
constexpr OSSIA_INLINE auto min(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
min function tailored for values
Definition: math.hpp:125
std::string extended_type
How a low-level type should be interpreted.
Definition: complex_type.hpp:9
access_mode
Address behaviors at crossing domain boundaries time.
Definition: parameter_properties.hpp:46
constexpr OSSIA_INLINE auto max(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
max function tailored for values
Definition: math.hpp:96
std::string description
Human-readable description of a node.
Definition: node_attributes.hpp:74
std::string app_creator
Device attribute : the creator of the software managed by this device.
Definition: node_attributes.hpp:113
bool disabled
A disabled node.
Definition: node_attributes.hpp:95
bool recall_safe
Should the value be untouched on preset loading.
Definition: node_attributes.hpp:83
int32_t refresh_rate
How often a node is refreshed.
Definition: node_attributes.hpp:80
bool critical
Means that the node is very important, e.g. a "play" message.
Definition: node_attributes.hpp:92
bool hidden
Means that the node should not be advertised by default.
Definition: node_attributes.hpp:101
std::string app_name
Device attribute : the name of the software managed by this device.
Definition: node_attributes.hpp:107
double value_step_size
Granularity of the space.
Definition: node_attributes.hpp:86
std::vector< std::string > tags
Tags applied to a node: {"model", "interesting", ...}.
Definition: node_attributes.hpp:71
float priority
When a node must be sent before other.
Definition: node_attributes.hpp:77
bool zombie
Means that the node is not present on the "host" device.
Definition: node_attributes.hpp:98
std::string app_version
Device attribute : the version of the software managed by this device.
Definition: node_attributes.hpp:110
bool muted
Means that the node should not send / receives network messages.
Definition: node_attributes.hpp:104
domain A domain of values
Definition: domain_base.hpp:23
How many instances a node can have.
Definition: node_attributes.hpp:36
The data that can be found inside a parameter.
Definition: parameter_data.hpp:21
Definition: dataspace.hpp:24