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 
225  {
230  ParameterTypeCount
231  };
232 
234  enum IOType
235  {
239  };
240 
242  {
243  ParameterType type;
244  IOType ioType = IOTypeUndefined;
245  ParameterValue min = 0.;
246  ParameterValue max = 1.;
247  ParameterValue initialValue = 0.;
248  ParameterValue exponent = 1.;
249  int steps = 0; // 0 = continuous, 1 = toggle, 2+ indicates steps in the normalized representation
250  bool debug = false;
251  bool saveable = false;
252  bool transmittable = false;
253  bool initialized = false;
254  bool visible = false;
255  const char **enumValues = nullptr;
256  const char *displayName = "";
257  const char *unit = "";
258  SignalIndex signalIndex = INVALID_INDEX;
259  };
260 
261  enum LogLevel
262  {
263  Info,
264  Warning,
265  Error
266  };
267 
269  template<typename T> T* addressOf(T& object) { return &object; }
270 
277  using MessageTag = uint32_t;
278 
279  // a simple SDBM Hash function http://www.partow.net/programming/hashfunctions/#SDBMHashFunction
291  constexpr MessageTag TAG(const char* str, MessageTag hash = 0) {
292  return (!(*str))
293  ? hash
294  : TAG(str + 1, static_cast<MessageTag>(*str) + (hash << 6) + (hash << 16) - hash);
295  }
296 
297  constexpr MessageTag ID(const char* str) { return TAG(str); }
298 
299  static_assert(TAG("test") == 1195757874, ""); // testing if the const expr can actually be evaluted at compile time
300  static_assert(TAG("") == 0, "");
301  static_assert(ID("test") == 1195757874, "");
302  static_assert(ID("") == 0, "");
303 
308  using MessageTagInfo = const char*;
309 
312  {
315  Undefined
316  };
317 
318  struct MessageInfo
319  {
320  MessageTagInfo tag;
321  MessagePortType type;
322  };
323 
324  static const MessageInfo NullMessageInfo = { "", MessagePortType::Undefined };
325 
326 // member funs macro as recommended by isocpp.org FAQ
327 #define CALL_MEMBER_FN(ptrToObject,ptrToMember) ((*ptrToObject).*(ptrToMember))
328 
329 // quoting magic from http://stackoverflow.com/questions/6671698/adding-quotes-to-argument-in-c-preprocessor
334 #define RNBO_Q(x) #x
335 #define RNBO_QUOTE(x) RNBO_Q(x)
336 
337 } // namespace RNBO
338 
339 #endif // #ifndef _RNBO_TYPES_H_