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.

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