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.

293 lines
11KB

  1. /*
  2. Copyright 2008-2011 David Robillard <http://drobilla.net>
  3. Copyright 2006-2007 Lars Luthman <lars.luthman@gmail.com>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. /**
  16. @defgroup event Event
  17. Generic time-stamped events, see <http://lv2plug.in/ns/ext/event> for
  18. details.
  19. @{
  20. */
  21. #ifndef LV2_EVENT_H
  22. #define LV2_EVENT_H
  23. #define LV2_EVENT_URI "http://lv2plug.in/ns/ext/event"
  24. #define LV2_EVENT_PREFIX LV2_EVENT_URI "#"
  25. #define LV2_EVENT__Event LV2_EVENT_PREFIX "Event"
  26. #define LV2_EVENT__EventPort LV2_EVENT_PREFIX "EventPort"
  27. #define LV2_EVENT__FrameStamp LV2_EVENT_PREFIX "FrameStamp"
  28. #define LV2_EVENT__TimeStamp LV2_EVENT_PREFIX "TimeStamp"
  29. #define LV2_EVENT__generatesTimeStamp LV2_EVENT_PREFIX "generatesTimeStamp"
  30. #define LV2_EVENT__generic LV2_EVENT_PREFIX "generic"
  31. #define LV2_EVENT__inheritsEvent LV2_EVENT_PREFIX "inheritsEvent"
  32. #define LV2_EVENT__inheritsTimeStamp LV2_EVENT_PREFIX "inheritsTimeStamp"
  33. #define LV2_EVENT__supportsEvent LV2_EVENT_PREFIX "supportsEvent"
  34. #define LV2_EVENT__supportsTimeStamp LV2_EVENT_PREFIX "supportsTimeStamp"
  35. #define LV2_EVENT_AUDIO_STAMP 0
  36. #include <stdint.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /**
  41. The best Pulses Per Quarter Note for tempo-based uint32_t timestamps.
  42. Equal to 2^12 * 5 * 7 * 9 * 11 * 13 * 17, which is evenly divisble
  43. by all integers from 1 through 18 inclusive, and powers of 2 up to 2^12.
  44. */
  45. static const uint32_t LV2_EVENT_PPQN = 3136573440U;
  46. /**
  47. An LV2 event (header only).
  48. LV2 events are generic time-stamped containers for any type of event.
  49. The type field defines the format of a given event's contents.
  50. This struct defines the header of an LV2 event. An LV2 event is a single
  51. chunk of POD (plain old data), usually contained in a flat buffer (see
  52. LV2_EventBuffer below). Unless a required feature says otherwise, hosts may
  53. assume a deep copy of an LV2 event can be created safely using a simple:
  54. memcpy(ev_copy, ev, sizeof(LV2_Event) + ev->size); (or equivalent)
  55. */
  56. typedef struct {
  57. /**
  58. The frames portion of timestamp. The units used here can optionally be
  59. set for a port (with the lv2ev:timeUnits property), otherwise this is
  60. audio frames, corresponding to the sample_count parameter of the LV2 run
  61. method (e.g. frame 0 is the first frame for that call to run).
  62. */
  63. uint32_t frames;
  64. /**
  65. The sub-frames portion of timestamp. The units used here can optionally
  66. be set for a port (with the lv2ev:timeUnits property), otherwise this is
  67. 1/(2^32) of an audio frame.
  68. */
  69. uint32_t subframes;
  70. /**
  71. The type of this event, as a number which represents some URI
  72. defining an event type. This value MUST be some value previously
  73. returned from a call to the uri_to_id function defined in the LV2
  74. URI map extension (see lv2_uri_map.h).
  75. There are special rules which must be followed depending on the type
  76. of an event. If the plugin recognizes an event type, the definition
  77. of that event type will describe how to interpret the event, and
  78. any required behaviour. Otherwise, if the type is 0, this event is a
  79. non-POD event and lv2_event_unref MUST be called if the event is
  80. 'dropped' (see above). Even if the plugin does not understand an event,
  81. it may pass the event through to an output by simply copying (and NOT
  82. calling lv2_event_unref). These rules are designed to allow for generic
  83. event handling plugins and large non-POD events, but with minimal hassle
  84. on simple plugins that "don't care" about these more advanced features.
  85. */
  86. uint16_t type;
  87. /**
  88. The size of the data portion of this event in bytes, which immediately
  89. follows. The header size (12 bytes) is not included in this value.
  90. */
  91. uint16_t size;
  92. /* size bytes of data follow here */
  93. } LV2_Event;
  94. /**
  95. A buffer of LV2 events (header only).
  96. Like events (which this contains) an event buffer is a single chunk of POD:
  97. the entire buffer (including contents) can be copied with a single memcpy.
  98. The first contained event begins sizeof(LV2_EventBuffer) bytes after the
  99. start of this struct.
  100. After this header, the buffer contains an event header (defined by struct
  101. LV2_Event), followed by that event's contents (padded to 64 bits), followed
  102. by another header, etc:
  103. | | | | | | |
  104. | | | | | | | | | | | | | | | | | | | | | | | | |
  105. |FRAMES |SUBFRMS|TYP|LEN|DATA..DATA..PAD|FRAMES | ...
  106. */
  107. typedef struct {
  108. /**
  109. The contents of the event buffer. This may or may not reside in the
  110. same block of memory as this header, plugins must not assume either.
  111. The host guarantees this points to at least capacity bytes of allocated
  112. memory (though only size bytes of that are valid events).
  113. */
  114. uint8_t* data;
  115. /**
  116. The size of this event header in bytes (including everything).
  117. This is to allow for extending this header in the future without
  118. breaking binary compatibility. Whenever this header is copied,
  119. it MUST be done using this field (and NOT the sizeof this struct).
  120. */
  121. uint16_t header_size;
  122. /**
  123. The type of the time stamps for events in this buffer.
  124. As a special exception, '0' always means audio frames and subframes
  125. (1/UINT32_MAX'th of a frame) in the sample rate passed to instantiate.
  126. INPUTS: The host must set this field to the numeric ID of some URI
  127. defining the meaning of the frames/subframes fields of contained events
  128. (obtained by the LV2 URI Map uri_to_id function with the URI of this
  129. extension as the 'map' argument, see lv2_uri_map.h). The host must
  130. never pass a plugin a buffer which uses a stamp type the plugin does not
  131. 'understand'. The value of this field must never change, except when
  132. connect_port is called on the input port, at which time the host MUST
  133. have set the stamp_type field to the value that will be used for all
  134. subsequent run calls.
  135. OUTPUTS: The plugin may set this to any value that has been returned
  136. from uri_to_id with the URI of this extension for a 'map' argument.
  137. When connected to a buffer with connect_port, output ports MUST set this
  138. field to the type of time stamp they will be writing. On any call to
  139. connect_port on an event input port, the plugin may change this field on
  140. any output port, it is the responsibility of the host to check if any of
  141. these values have changed and act accordingly.
  142. */
  143. uint16_t stamp_type;
  144. /**
  145. The number of events in this buffer.
  146. INPUTS: The host must set this field to the number of events contained
  147. in the data buffer before calling run(). The plugin must not change
  148. this field.
  149. OUTPUTS: The plugin must set this field to the number of events it has
  150. written to the buffer before returning from run(). Any initial value
  151. should be ignored by the plugin.
  152. */
  153. uint32_t event_count;
  154. /**
  155. The size of the data buffer in bytes.
  156. This is set by the host and must not be changed by the plugin.
  157. The host is allowed to change this between run() calls.
  158. */
  159. uint32_t capacity;
  160. /**
  161. The size of the initial portion of the data buffer containing data.
  162. INPUTS: The host must set this field to the number of bytes used
  163. by all events it has written to the buffer (including headers)
  164. before calling the plugin's run().
  165. The plugin must not change this field.
  166. OUTPUTS: The plugin must set this field to the number of bytes
  167. used by all events it has written to the buffer (including headers)
  168. before returning from run().
  169. Any initial value should be ignored by the plugin.
  170. */
  171. uint32_t size;
  172. } LV2_Event_Buffer;
  173. /**
  174. Opaque pointer to host data.
  175. */
  176. typedef void* LV2_Event_Callback_Data;
  177. /**
  178. Non-POD events feature.
  179. To support this feature the host must pass an LV2_Feature struct to the
  180. plugin's instantiate method with URI "http://lv2plug.in/ns/ext/event"
  181. and data pointed to an instance of this struct. Note this feature
  182. is not mandatory to support the event extension.
  183. */
  184. typedef struct {
  185. /**
  186. Opaque pointer to host data.
  187. The plugin MUST pass this to any call to functions in this struct.
  188. Otherwise, it must not be interpreted in any way.
  189. */
  190. LV2_Event_Callback_Data callback_data;
  191. /**
  192. Take a reference to a non-POD event.
  193. If a plugin receives an event with type 0, it means the event is a
  194. pointer to some object in memory and not a flat sequence of bytes
  195. in the buffer. When receiving a non-POD event, the plugin already
  196. has an implicit reference to the event. If the event is stored AND
  197. passed to an output, lv2_event_ref MUST be called on that event.
  198. If the event is only stored OR passed through, this is not necessary
  199. (as the plugin already has 1 implicit reference).
  200. @param event An event received at an input that will not be copied to
  201. an output or stored in any way.
  202. @param context The calling context. Like event types, this is a mapped
  203. URI, see lv2_context.h. Simple plugin with just a run() method should
  204. pass 0 here (the ID of the 'standard' LV2 run context). The host
  205. guarantees that this function is realtime safe iff the context is
  206. realtime safe.
  207. PLUGINS THAT VIOLATE THESE RULES MAY CAUSE CRASHES AND MEMORY LEAKS.
  208. */
  209. uint32_t (*lv2_event_ref)(LV2_Event_Callback_Data callback_data,
  210. LV2_Event* event);
  211. /**
  212. Drop a reference to a non-POD event.
  213. If a plugin receives an event with type 0, it means the event is a
  214. pointer to some object in memory and not a flat sequence of bytes
  215. in the buffer. If the plugin does not pass the event through to
  216. an output or store it internally somehow, it MUST call this function
  217. on the event (more information on using non-POD events below).
  218. @param event An event received at an input that will not be copied to an
  219. output or stored in any way.
  220. @param context The calling context. Like event types, this is a mapped
  221. URI, see lv2_context.h. Simple plugin with just a run() method should
  222. pass 0 here (the ID of the 'standard' LV2 run context). The host
  223. guarantees that this function is realtime safe iff the context is
  224. realtime safe.
  225. PLUGINS THAT VIOLATE THESE RULES MAY CAUSE CRASHES AND MEMORY LEAKS.
  226. */
  227. uint32_t (*lv2_event_unref)(LV2_Event_Callback_Data callback_data,
  228. LV2_Event* event);
  229. } LV2_Event_Feature;
  230. #ifdef __cplusplus
  231. } /* extern "C" */
  232. #endif
  233. #endif /* LV2_EVENT_H */
  234. /**
  235. @}
  236. */