Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
5.7KB

  1. /*
  2. Copyright 2012 David Robillard <http://drobilla.net>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. /**
  15. @file sratom.h API for Sratom, an LV2 Atom RDF serialisation library.
  16. */
  17. #ifndef SRATOM_SRATOM_H
  18. #define SRATOM_SRATOM_H
  19. #include <stdint.h>
  20. #include "lv2/urid.h"
  21. #include "lv2/atom.h"
  22. #include "lv2/atom-forge.h"
  23. #include "serd/serd.h"
  24. #include "sord/sord.h"
  25. #ifdef SRATOM_SHARED
  26. # ifdef _WIN32
  27. # define SRATOM_LIB_IMPORT __declspec(dllimport)
  28. # define SRATOM_LIB_EXPORT __declspec(dllexport)
  29. # else
  30. # define SRATOM_LIB_IMPORT __attribute__((visibility("default")))
  31. # define SRATOM_LIB_EXPORT __attribute__((visibility("default")))
  32. # endif
  33. # ifdef SRATOM_INTERNAL
  34. # define SRATOM_API SRATOM_LIB_EXPORT
  35. # else
  36. # define SRATOM_API SRATOM_LIB_IMPORT
  37. # endif
  38. #else
  39. # define SRATOM_API
  40. #endif
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. @defgroup sratom Sratom
  46. An LV2 Atom RDF serialisation library.
  47. @{
  48. */
  49. /**
  50. Atom serialiser.
  51. */
  52. typedef struct SratomImpl Sratom;
  53. /**
  54. Mode for reading resources to LV2 Objects.
  55. This affects how resources (which are either blank nodes or have URIs) are
  56. read by sratom_read(), since they may be read as simple references (a URI or
  57. blank node ID) or a complete description (an atom "Object").
  58. Currently, blank nodes are always read as Objects, but support for reading
  59. blank node IDs may be added in the future.
  60. */
  61. typedef enum {
  62. /**
  63. Read blank nodes as Objects, and named resources as URIs.
  64. */
  65. SRATOM_OBJECT_MODE_BLANK,
  66. /**
  67. Read blank nodes and the main subject as Objects, and any other named
  68. resources as URIs. The "main subject" is the subject parameter passed
  69. to sratom_read(); if this is a resource it will be read as an Object,
  70. but all other named resources encountered will be read as URIs.
  71. */
  72. SRATOM_OBJECT_MODE_BLANK_SUBJECT
  73. } SratomObjectMode;
  74. /**
  75. Create a new Atom serialiser.
  76. */
  77. SRATOM_API
  78. Sratom*
  79. sratom_new(LV2_URID_Map* map);
  80. /**
  81. Free an Atom serialisation.
  82. */
  83. SRATOM_API
  84. void
  85. sratom_free(Sratom* sratom);
  86. /**
  87. Set the sink(s) where sratom will write its output.
  88. This must be called before calling sratom_write().
  89. */
  90. SRATOM_API
  91. void
  92. sratom_set_sink(Sratom* sratom,
  93. const char* base_uri,
  94. SerdStatementSink sink,
  95. SerdEndSink end_sink,
  96. void* handle);
  97. /**
  98. Write pretty numeric literals.
  99. If `pretty_numbers` is true, numbers will be written as pretty Turtle
  100. literals, rather than string literals with precise types. The cost of this
  101. is that the types might get fudged on a round-trip to RDF and back.
  102. */
  103. SRATOM_API
  104. void
  105. sratom_set_pretty_numbers(Sratom* sratom,
  106. bool pretty_numbers);
  107. /**
  108. Configure how resources will be read to form LV2 Objects.
  109. */
  110. SRATOM_API
  111. void
  112. sratom_set_object_mode(Sratom* sratom,
  113. SratomObjectMode object_mode);
  114. /**
  115. Write an Atom to RDF.
  116. The serialised atom is written to the sink set by sratom_set_sink().
  117. @return 0 on success, or a non-zero error code otherwise.
  118. */
  119. SRATOM_API
  120. int
  121. sratom_write(Sratom* sratom,
  122. LV2_URID_Unmap* unmap,
  123. uint32_t flags,
  124. const SerdNode* subject,
  125. const SerdNode* predicate,
  126. uint32_t type,
  127. uint32_t size,
  128. const void* body);
  129. /**
  130. Read an Atom from RDF.
  131. The resulting atom will be written to `forge`.
  132. */
  133. SRATOM_API
  134. void
  135. sratom_read(Sratom* sratom,
  136. LV2_Atom_Forge* forge,
  137. SordWorld* world,
  138. SordModel* model,
  139. const SordNode* subject);
  140. /**
  141. Serialise an Atom to a Turtle string.
  142. The returned string must be free()'d by the caller.
  143. */
  144. SRATOM_API
  145. char*
  146. sratom_to_turtle(Sratom* sratom,
  147. LV2_URID_Unmap* unmap,
  148. const char* base_uri,
  149. const SerdNode* subject,
  150. const SerdNode* predicate,
  151. uint32_t type,
  152. uint32_t size,
  153. const void* body);
  154. /**
  155. Read an Atom from a Turtle string.
  156. The returned atom must be free()'d by the caller.
  157. */
  158. SRATOM_API
  159. LV2_Atom*
  160. sratom_from_turtle(Sratom* sratom,
  161. const char* base_uri,
  162. const SerdNode* subject,
  163. const SerdNode* predicate,
  164. const char* str);
  165. /**
  166. A convenient resizing sink for LV2_Atom_Forge.
  167. The handle must point to an initialized SerdChunk.
  168. */
  169. SRATOM_API
  170. LV2_Atom_Forge_Ref
  171. sratom_forge_sink(LV2_Atom_Forge_Sink_Handle handle,
  172. const void* buf,
  173. uint32_t size);
  174. /**
  175. The corresponding deref function for sratom_forge_sink.
  176. */
  177. SRATOM_API
  178. LV2_Atom*
  179. sratom_forge_deref(LV2_Atom_Forge_Sink_Handle handle,
  180. LV2_Atom_Forge_Ref ref);
  181. /**
  182. @}
  183. */
  184. #ifdef __cplusplus
  185. } /* extern "C" */
  186. #endif
  187. #endif /* SRATOM_SRATOM_H */