LMMS
Loading...
Searching...
No Matches
event-helpers.h
Go to the documentation of this file.
1/*
2 Copyright 2008-2015 David Robillard <http://drobilla.net>
3
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
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
21
22#ifndef LV2_EVENT_HELPERS_H
23#define LV2_EVENT_HELPERS_H
24
25#include <stdint.h>
26#include <stdlib.h>
27#include <string.h>
28
29#include "event.h"
30
31#ifdef __cplusplus
32extern "C" {
33#else
34# include <stdbool.h>
35#endif
36
47
48
50static inline uint16_t
52{
53 return (uint16_t)(size + 7U) & (uint16_t)(~7U);
54}
55
56
60static inline void
62 uint16_t stamp_type,
64{
65 buf->data = data;
66 buf->header_size = sizeof(LV2_Event_Buffer);
67 buf->stamp_type = stamp_type;
68 buf->event_count = 0;
69 buf->size = 0;
70}
71
72
74static inline LV2_Event_Buffer*
76{
77 const size_t size = sizeof(LV2_Event_Buffer) + capacity;
79 if (buf != NULL) {
80 buf->capacity = capacity;
81 lv2_event_buffer_reset(buf, stamp_type, (uint8_t *)(buf + 1));
82 return buf;
83 } else {
84 return NULL;
85 }
86}
87
88
97
98
101static inline bool
103 LV2_Event_Buffer* buf)
104{
105 iter->buf = buf;
106 iter->offset = 0;
107 return (buf->size > 0);
108}
109
110
113static inline bool
115{
116 return (iter->buf && (iter->offset < iter->buf->size));
117}
118
119
123static inline bool
125{
126 if (!lv2_event_is_valid(iter)) {
127 return false;
128 }
129
130 LV2_Event* const ev = (LV2_Event*)(
131 (uint8_t*)iter->buf->data + iter->offset);
132
133 iter->offset += lv2_event_pad_size(
134 (uint16_t)((uint16_t)sizeof(LV2_Event) + ev->size));
135
136 return true;
137}
138
139
147static inline LV2_Event*
149 uint8_t** data)
150{
151 if (!lv2_event_is_valid(iter)) {
152 return NULL;
153 }
154
155 LV2_Event* const ev = (LV2_Event*)(
156 (uint8_t*)iter->buf->data + iter->offset);
157
158 if (data)
159 *data = (uint8_t*)ev + sizeof(LV2_Event);
160
161 return ev;
162}
163
164
170static inline bool
172 uint32_t frames,
173 uint32_t subframes,
176 const uint8_t* data)
177{
178 if (!iter->buf)
179 return false;
180
181 if (iter->buf->capacity - iter->buf->size < sizeof(LV2_Event) + size)
182 return false;
183
184 LV2_Event* const ev = (LV2_Event*)(
185 (uint8_t*)iter->buf->data + iter->offset);
186
187 ev->frames = frames;
188 ev->subframes = subframes;
189 ev->type = type;
190 ev->size = size;
191 memcpy((uint8_t*)ev + sizeof(LV2_Event), data, size);
192 ++iter->buf->event_count;
193
195 iter->buf->size += size;
196 iter->offset += size;
197
198 return true;
199}
200
201
205static inline uint8_t*
207 uint32_t frames,
208 uint32_t subframes,
211{
212 const uint16_t total_size = (uint16_t)(sizeof(LV2_Event) + size);
213 if (iter->buf->capacity - iter->buf->size < total_size)
214 return NULL;
215
216 LV2_Event* const ev = (LV2_Event*)(
217 (uint8_t*)iter->buf->data + iter->offset);
218
219 ev->frames = frames;
220 ev->subframes = subframes;
221 ev->type = type;
222 ev->size = size;
223 ++iter->buf->event_count;
224
225 const uint16_t padded_size = lv2_event_pad_size(total_size);
226 iter->buf->size += padded_size;
227 iter->offset += padded_size;
228
229 return (uint8_t*)ev + sizeof(LV2_Event);
230}
231
232
238static inline bool
240 const LV2_Event* ev,
241 const uint8_t* data)
242{
243 const uint16_t total_size = (uint16_t)(sizeof(LV2_Event) + ev->size);
244 if (iter->buf->capacity - iter->buf->size < total_size)
245 return false;
246
247 LV2_Event* const write_ev = (LV2_Event*)(
248 (uint8_t*)iter->buf->data + iter->offset);
249
250 *write_ev = *ev;
251 memcpy((uint8_t*)write_ev + sizeof(LV2_Event), data, ev->size);
252 ++iter->buf->event_count;
253
254 const uint16_t padded_size = lv2_event_pad_size(total_size);
255 iter->buf->size += padded_size;
256 iter->offset += padded_size;
257
258 return true;
259}
260
261#ifdef __cplusplus
262} /* extern "C" */
263#endif
264
265#endif /* LV2_EVENT_HELPERS_H */
#define NULL
Definition CarlaBridgeFormat.cpp:30
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
static uint16_t lv2_event_pad_size(uint16_t size)
Definition event-helpers.h:51
static void lv2_event_buffer_reset(LV2_Event_Buffer *buf, uint16_t stamp_type, uint8_t *data)
Definition event-helpers.h:61
static bool lv2_event_increment(LV2_Event_Iterator *iter)
Definition event-helpers.h:124
static bool lv2_event_begin(LV2_Event_Iterator *iter, LV2_Event_Buffer *buf)
Definition event-helpers.h:102
static LV2_Event_Buffer * lv2_event_buffer_new(uint32_t capacity, uint16_t stamp_type)
Definition event-helpers.h:75
static uint8_t * lv2_event_reserve(LV2_Event_Iterator *iter, uint32_t frames, uint32_t subframes, uint16_t type, uint16_t size)
Definition event-helpers.h:206
static LV2_Event * lv2_event_get(LV2_Event_Iterator *iter, uint8_t **data)
Definition event-helpers.h:148
static bool lv2_event_write_event(LV2_Event_Iterator *iter, const LV2_Event *ev, const uint8_t *data)
Definition event-helpers.h:239
static bool lv2_event_is_valid(LV2_Event_Iterator *iter)
Definition event-helpers.h:114
static bool lv2_event_write(LV2_Event_Iterator *iter, uint32_t frames, uint32_t subframes, uint16_t type, uint16_t size, const uint8_t *data)
Definition event-helpers.h:171
JSAMPIMAGE data
Definition jpeglib.h:945
unsigned short uint16_t
Definition mid.cpp:99
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
Definition event.h:132
uint32_t event_count
Definition event.h:186
uint16_t stamp_type
Definition event.h:173
uint32_t capacity
Definition event.h:193
uint32_t size
Definition event.h:208
uint16_t header_size
Definition event.h:148
uint8_t * data
Definition event.h:139
Definition event-helpers.h:93
LV2_Event_Buffer * buf
Definition event-helpers.h:94
uint32_t offset
Definition event-helpers.h:95
Definition event.h:72
uint16_t size
Definition event.h:110
uint16_t type
Definition event.h:104
uint32_t subframes
Definition event.h:86
uint32_t frames
Definition event.h:79
memcpy(hh, h, RAND_HEAD_LEN)
ulg size
Definition extract.c:2350
char * malloc()