C++ API Reference RNBO: common/RNBO_Types.h Source File

RNBO: common/RNBO_Types.h Source File

Go to the documentation of this file.
1 #ifndef _RNBO_TYPES_H_
2 #define _RNBO_TYPES_H_
3 
4 #include "RNBO_CompilerMacros.h"
5 #include "RNBO_Std.h"
6 
13 namespace RNBO {
14 
15  // let RNBO use 32 bit float instead of double
16  // defining this here seems not to be ideal, we might want to have this is RNBO_LocalConfig.h or something similar
17  // #define RNBO_USE_FLOAT32
18 
19 #ifdef RNBO_USE_FLOAT32
20  using number = float;
21  using SampleValue = float;
22 #else
23 
27  using number = double;
28 
33  using SampleValue = double;
34 #endif // RNBO_USE_FLOAT32
35 
40  using signal = SampleValue *;
41 
42  // avoid denom test for genexpr statements - speeds up computation
43 #define RNBO_NO_DENORM_TEST
44 
45  using generic = number;
46 
52 
57  using Sample = SampleValue; // an alias of SampleValue, perhaps we can get rid of this?
58 
65  template <size_t L>
66  using SampleArray = Sample*[L];
67 
74  template <size_t L>
75  using ConstSampleArray = const Sample*[L];
76 
81  using MillisecondTime = double;
82 
83  // for now we need MillisecondTime to be 64 bit to avoid losing precision in long running patches
84  static_assert(sizeof(MillisecondTime) * 8 == 64, "MillisecondTime has to be 64 bit");
85 
90  using Tempo = number;
91 
98  using BeatTime = number;
99 
100  enum TransportState
101  {
102  STOPPED,
103  RUNNING
104  };
105 
115  using Int = intptr_t;
116 
117 #if defined(RNBO_USE_FLOAT32) || defined(RNBO_NO_INT64)
118  using UInt = uint32_t;
119  using Index = UInt;
120  const Index INVALID_INDEX = UINT32_MAX;
121 #else
122  using UInt = uint64_t;
123  using Index = UInt;
124  const Index INVALID_INDEX = UINT64_MAX;
125 #endif
126 
127  using UInt32 = uint32_t;
128  using UInt64 = uint64_t;
129 
135 
141 
147 
153 
158  using SampleIndex = Int;
159 
164  using SampleOffset = Int;
165 
170  using ClockId = Int;
171 
176  using ParameterInterfaceId = const void*;
177 
184  using DataRefIndex = Int;
185 
194  using ProbingIndex = Int;
195 
200  using ConstCharPointer = const char *;
201 
206  using ConstByteArray = const uint8_t *;
207 
208  //.*BinOpInt have to be 32 bit for javascript calculation parity
213  using BinOpInt = int32_t;
214 
219  using UBinOpInt = uint32_t;
220 
221  static const MillisecondTime RNBOTimeNow = 0;
222  static const MillisecondTime TimeNow = 0;
223 
226  {
231  ParameterTypeCount
232  };
233 
235  enum IOType
236  {
240  };
241 
243  {
244  ParameterType type;
245  IOType ioType = IOTypeUndefined;
246  ParameterValue min = 0.;
247  ParameterValue max = 1.;
248  ParameterValue initialValue = 0.;
249  ParameterValue exponent = 1.;
250  int steps = 0; // 0 = continuous, 1 = toggle, 2+ indicates steps in the normalized representation
251  bool debug = false;
252  bool saveable = false;
253  bool transmittable = false;
254  bool initialized = false;
255  bool visible = false;
256  const char **enumValues = nullptr;
257  const char *displayName = "";
258  const char *unit = "";
259  SignalIndex signalIndex = INVALID_INDEX;
260  };
261 
262  enum LogLevel
263  {
264  Info,
265  Warning,
266  Error
267  };
268 
270  template<typename T> T* addressOf(T& object) { return &object; }
271 
278  using MessageTag = uint32_t;
279 
280  // a simple SDBM Hash function http://www.partow.net/programming/hashfunctions/#SDBMHashFunction
292  constexpr MessageTag TAG(const char* str, MessageTag hash = 0) {
293  return (!(*str))
294  ? hash
295  : TAG(str + 1, static_cast<MessageTag>(*str) + (hash << 6) + (hash << 16) - hash);
296  }
297 
298  constexpr MessageTag ID(const char* str) { return TAG(str); }
299 
300  static_assert(TAG("test") == 1195757874, ""); // testing if the const expr can actually be evaluted at compile time
301  static_assert(TAG("") == 0, "");
302  static_assert(ID("test") == 1195757874, "");
303  static_assert(ID("") == 0, "");
304 
309  using MessageTagInfo = const char*;
310 
313  {
316  Undefined
317  };
318 
319  struct MessageInfo
320  {
321  MessageTagInfo tag;
322  MessagePortType type;
323  };
324 
325  static const MessageInfo NullMessageInfo = { "", MessagePortType::Undefined };
326 
327  enum class RuntimeError {
328  OutOfRange,
329  QueueOverflow
330  };
331 
332 
334  EXTERNALENGINE(void*) {}
335 };
336 
337 // member funs macro as recommended by isocpp.org FAQ
338 #define CALL_MEMBER_FN(ptrToObject,ptrToMember) ((*ptrToObject).*(ptrToMember))
339 
340 // quoting magic from http://stackoverflow.com/questions/6671698/adding-quotes-to-argument-in-c-preprocessor
345 #define RNBO_Q(x) #x
346 #define RNBO_QUOTE(x) RNBO_Q(x)
347 
348 } // namespace RNBO
349 
350 #endif // #ifndef _RNBO_TYPES_H_