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.

295 lines
12KB

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