OSSIA
Open Scenario System for Interactive Application
minuit_common.hpp
1 #pragma once
3 #include <ossia/detail/string_view.hpp>
4 #include <ossia/network/exceptions.hpp>
5 #include <ossia/network/value/value.hpp>
6 
7 #include <exception>
8 
9 namespace ossia::minuit
10 {
11 enum class minuit_command : char
12 {
13  Request = '?',
14  Answer = ':',
15  Error = '!'
16 };
17 
18 enum class minuit_operation : char
19 {
20  Listen = 'l',
21  Namespace = 'n',
22  Get = 'g'
23 };
24 
25 enum class minuit_action : int
26 {
27  NamespaceRequest,
28  NamespaceReply,
29  NamespaceError,
30  GetRequest,
31  GetReply,
32  GetError,
33  ListenRequest,
34  ListenReply,
35  ListenError
36 };
37 
38 enum class minuit_type : char
39 {
40  Application = 'A',
41  Container = 'C',
42  Data = 'D',
43  None = 'n',
44  ModelInfo = 'M',
45  UiInfo = 'U',
46  PresetManager = 'P'
47 };
48 
49 enum class minuit_attribute
50 {
51  Value,
52  Type,
53  Service,
54  RangeBounds,
55  RangeClipMode,
56  Description,
57  RepetitionFilter,
58  Tags,
59  Active,
60  ValueDefault,
61  Priority,
62  Dataspace,
63  DataspaceUnit,
64  RampFunction,
65  RampDrive,
66  ValueStepSize,
67  RampFunctionParameters
68 };
69 
70 OSSIA_EXPORT
71 std::string_view to_minuit_attribute_text(minuit_attribute str);
72 
73 OSSIA_EXPORT
74 minuit_attribute get_attribute(std::string_view str);
75 
76 OSSIA_EXPORT
77 std::string_view to_minuit_type_text(const ossia::value& val);
78 
79 inline std::string_view to_minuit_type_text(ossia::val_type val)
80 {
81  // integer, decimal, string, generic, boolean, none, array.
82  switch(val)
83  {
84  case val_type::IMPULSE:
85  constexpr_return(ossia::make_string_view("none"));
86  case val_type::INT:
87  constexpr_return(ossia::make_string_view("integer"));
88  case val_type::FLOAT:
89  constexpr_return(ossia::make_string_view("decimal"));
90  case val_type::BOOL:
91  constexpr_return(ossia::make_string_view("boolean"));
92  case val_type::STRING:
93  constexpr_return(ossia::make_string_view("string"));
94  case val_type::VEC2F:
95  case val_type::VEC3F:
96  case val_type::VEC4F:
97  case val_type::LIST:
98  constexpr_return(ossia::make_string_view("array"));
99  case val_type::MAP:
100  constexpr_return(ossia::make_string_view("map"));
101  default:
102  throw invalid_value_type_error("to_minuit_type_text: Invalid type");
103  }
104  return {};
105 }
106 
107 inline ossia::value value_from_minuit_type_text(std::string_view str)
108 {
109  // integer, decimal, string, generic, boolean, none, array.
110  // we can differentiate them by the first character
111 
112  switch(str[0])
113  {
114  case 'i': // integer
115  return int32_t{};
116  case 'd': // decimal
117  return float{};
118  case 's': // string
119  return std::string{};
120  case 'b': // boolean
121  return bool{};
122  case 'n': // none
123  return ossia::impulse{};
124  case 'a': // array
125  case 'g': // generic
126  return value{std::vector<ossia::value>{}};
127  default:
128  return {};
129  }
130 }
131 
132 inline ossia::val_type type_from_minuit_type_text(std::string_view str)
133 {
134  // integer, decimal, string, generic, boolean, none, array.
135  // we can differentiate them by the first character
136 
137  switch(str[0])
138  {
139  case 'i': // integer
140  return ossia::val_type::INT;
141  case 'd': // decimal
142  return ossia::val_type::FLOAT;
143  case 's': // string
145  case 'b': // boolean
146  return ossia::val_type::BOOL;
147  case 'n': // none
149  case 'a': // array
150  case 'g': // generic
151  return ossia::val_type::LIST;
152  default:
153  return {};
154  }
155 }
156 
157 inline std::string_view to_minuit_service_text(ossia::access_mode acc)
158 {
159  switch(acc)
160  {
161  case ossia::access_mode::BI:
162  constexpr_return(ossia::make_string_view("parameter"));
164  constexpr_return(ossia::make_string_view("return"));
166  constexpr_return(ossia::make_string_view("message"));
167  default:
168  throw parse_error("to_minuit_service_text: Invalid access mode");
169  }
170  return {};
171 }
172 
173 inline ossia::access_mode from_minuit_service_text(std::string_view str)
174 {
175  switch(str[0])
176  {
177  case 'p':
178  return ossia::access_mode::BI;
179  case 'r':
181  case 'm':
183  default:
184  throw parse_error("from_minuit_service_text: Invalid access mode");
185  }
186  return {};
187 }
188 
189 inline std::string_view to_minuit_bounding_text(ossia::bounding_mode b)
190 {
191  switch(b)
192  {
193  case ossia::bounding_mode::FREE:
194  constexpr_return(ossia::make_string_view("none"));
196  constexpr_return(ossia::make_string_view("both"));
198  constexpr_return(ossia::make_string_view("wrap"));
200  constexpr_return(ossia::make_string_view("fold"));
202  constexpr_return(ossia::make_string_view("low"));
204  constexpr_return(ossia::make_string_view("high"));
205  default:
206  throw parse_error("to_minuit_bounding_text: Invalid bounding mode");
207  }
208  return {};
209 }
210 
211 inline ossia::bounding_mode from_minuit_bounding_text(std::string_view str)
212 {
213  switch(str[0])
214  {
215  case 'n': // none
216  return ossia::bounding_mode::FREE;
217  case 'b': // both
219  case 'w': // wrap
221  case 'f': // fold
223  case 'l': // low
225  case 'h': // high
227  default:
228  throw parse_error("from_minuit_bounding_text: Invalid bounding mode");
229  }
230  return {};
231 }
232 
233 inline minuit_command get_command(char str)
234 {
235  switch(str)
236  {
237  case '?':
238  case ':':
239  case '!':
240  return static_cast<minuit_command>(str);
241  default:
242  throw parse_error("get_command: unhandled command");
243  }
244  return {};
245 }
246 
247 inline minuit_type get_type(char str)
248 {
249  switch(str)
250  {
251  case 'A':
252  case 'C':
253  case 'D':
254  case 'n':
255  case 'M':
256  case 'U':
257  case 'P':
258  return static_cast<minuit_type>(str);
259  default:
260  return minuit_type::None;
261  }
262  return minuit_type::None;
263 }
264 
265 inline minuit_operation get_operation(char str)
266 {
267  switch(str)
268  {
269  case 'l':
270  case 'n':
271  case 'g':
272  return static_cast<minuit_operation>(str);
273  default:
274  throw parse_error("get_operation: unhandled operation");
275  }
276  return {};
277 }
278 
279 inline minuit_operation get_operation(std::string_view str)
280 {
281  return get_operation(str[0]);
282 }
283 }
The value class.
Definition: value.hpp:173
@ Get
Definition: ossia-cpp98.hpp:67
val_type
Enum to represent the types that a value can take.
Definition: parameter_properties.hpp:16
@ IMPULSE
array<float, 4>
@ VEC3F
array<float, 2>
@ LIST
std::string
@ VEC4F
array<float, 3>
@ MAP
std::vector<value>
@ BOOL
ossia::impulse
bounding_mode
Address behaviors at crossing domain boundaries.
Definition: parameter_properties.hpp:56
@ CLIP
The bounds are ignored.
auto get_attribute(const any_map &e, std::string_view name)
get_attribute Get an attribute of an any_map.
Definition: any_map.hpp:29
access_mode
Address behaviors at crossing domain boundaries time.
Definition: parameter_properties.hpp:46
@ GET
The value can be retrieved and changed.
@ SET
The value can be retrieved.