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