Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #ifndef PB071_OSC_H
  2. #define PB071_OSC_H
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #define OSC_TIMETAG_IMMEDIATE(p_osc_timetag) ((p_osc_timetag)->sec = 0, (p_osc_timetag)->frac = 1)
  9. #define OSC_TIMETAG_NULL(p_osc_timetag) ((p_osc_timetag)->sec = 0, (p_osc_timetag)->frac = 0)
  10.  
  11. #define OSC_TT_INT 'i'
  12. #define OSC_TT_STRING 's'
  13. #define OSC_TT_FLOAT 'f'
  14. #define OSC_TT_TIMETAG 't'
  15. #define OSC_TYPETAG(...) (',', __ - VA_ARGS__, '\0')
  16.  
  17. #define OSC_MESSAGE_NULL(p_struct_osc_message) ((p_struct_osc_message)->raw_data = NULL, (p_struct_osc_message)->address = NULL, (p_struct_osc_message)->typetag = NULL)
  18. #define OSC_BUNDLE_NULL(p_struct_osc_bundle) ((p_struct_osc_bundle)->raw_data = NULL, (p_struct_osc_bundle)->timetag = NULL)
  19. struct osc_timetag
  20. {
  21. uint32_t sec;
  22. uint32_t frac;
  23. };
  24.  
  25. union osc_msg_argument
  26. {
  27. const int32_t i;
  28. const char s;
  29. const float f;
  30. const struct osc_timetag t;
  31. };
  32.  
  33. struct osc_message
  34. {
  35. char *address;
  36. char *typetag;
  37. void *raw_data;
  38. };
  39.  
  40. struct osc_bundle
  41. {
  42. struct osc_timetag *timetag;
  43. void *raw_data;
  44. };
  45.  
  46.  
  47. int osc_message_new(struct osc_message *msg);
  48.  
  49. void osc_message_destroy(struct osc_message *msg);
  50.  
  51. int osc_message_set_address(struct osc_message *msg, const char *address);
  52.  
  53. size_t get_raw_data_length(struct osc_message *msg);
  54.  
  55. size_t get_address_or_typetag_length(const char *address);
  56.  
  57. int osc_message_add_int32(struct osc_message *msg, int32_t data);
  58. int osc_message_add_float(struct osc_message *msg, float data);
  59. int osc_message_add_timetag(struct osc_message *msg, struct osc_timetag tag);
  60. int osc_message_add_string(struct osc_message *msg, const char *data);
  61.  
  62. size_t osc_message_argc(const struct osc_message *msg);
  63. size_t osc_message_serialized_length(const struct osc_message *msg);
  64.  
  65. const union osc_msg_argument *osc_message_arg(const struct osc_message *msg, size_t arg_index);
  66.  
  67. // OSC BUNDLE
  68. int osc_bundle_new(struct osc_bundle *bnd);
  69. void osc_bundle_destroy(struct osc_bundle *bn);
  70. void osc_bundle_set_timetag(struct osc_bundle *bn, struct osc_timetag tag);
  71. int osc_bundle_add_message(struct osc_bundle *bundle, const struct osc_message *msg);
  72. size_t osc_bundle_serialized_length(const struct osc_bundle *bundle);
  73. struct osc_message osc_bundle_next_message(const struct osc_bundle *bundle, struct osc_message prev);
  74. #endif // PB071_OSC_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement