LMMS
Loading...
Searching...
No Matches
atom-helpers.h
Go to the documentation of this file.
1// lv2_atom_helpers.h
2//
3/****************************************************************************
4 Copyright (C) 2005-2013, rncbc aka Rui Nuno Capela. All rights reserved.
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20*****************************************************************************/
21
22/* Helper functions for LV2 atom:Sequence event buffer.
23 *
24 * tentatively adapted from:
25 *
26 * - lv2_evbuf.h,c - An abstract/opaque LV2 event buffer implementation.
27 *
28 * - event-helpers.h - Helper functions for the LV2 Event extension.
29 * <http://lv2plug.in/ns/ext/event>
30 *
31 * Copyright 2008-2012 David Robillard <http://drobilla.net>
32 */
33
34#ifndef LV2_ATOM_HELPERS_H
35#define LV2_ATOM_HELPERS_H
36
37#include <stdint.h>
38#include <stdbool.h>
39#include <string.h>
40#include <stdlib.h>
41#include <assert.h>
42
43#include "atom-util.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49// An abstract/opaque LV2 atom:Sequence buffer.
50//
60
61
62// Clear and initialize an existing LV2 atom:Sequenece buffer.
63//
64static inline
65void lv2_atom_buffer_reset ( LV2_Atom_Buffer *buf, bool input )
66{
67 if (input) {
69 buf->atoms.atom.type = buf->sequence_type;
70 } else {
71 buf->atoms.atom.size = buf->capacity;
72 buf->atoms.atom.type = buf->chunk_type;
73 }
74}
75
76
77// Allocate a new, empty LV2 atom:Sequence buffer.
78//
79static inline
81 uint32_t capacity, uint32_t chunk_type, uint32_t sequence_type, bool input )
82{
84 malloc(sizeof(LV2_Atom_Buffer) + sizeof(LV2_Atom_Sequence) + capacity);
85
86 buf->capacity = capacity;
87 buf->chunk_type = chunk_type;
88 buf->sequence_type = sequence_type;
89
90 lv2_atom_buffer_reset(buf, input);
91
92 return buf;
93}
94
95
96// Free an LV2 atom:Sequenece buffer allocated with lv2_atome_buffer_new.
97//
98static inline
100{
101 free(buf);
102}
103
104
105// Return the total padded size of events stored in a LV2 atom:Sequence buffer.
106//
107static inline
109{
110 if (buf->atoms.atom.type == buf->sequence_type)
111 return buf->atoms.atom.size - uint32_t(sizeof(LV2_Atom_Sequence_Body));
112 else
113 return 0;
114}
115
116
117// Return the actual LV2 atom:Sequence implementation.
118//
119static inline
124
125
126// An iterator over an atom:Sequence buffer.
127//
135
136
137// Reset an iterator to point to the start of an LV2 atom:Sequence buffer.
138//
139static inline
142{
143 iter->buf = buf;
144 iter->offset = 0;
145
146 return (buf->atoms.atom.size > 0);
147}
148
149
150// Reset an iterator to point to the end of an LV2 atom:Sequence buffer.
151//
152static inline
155{
156 iter->buf = buf;
158
159 return (iter->offset < buf->capacity - sizeof(LV2_Atom_Event));
160}
161
162
163// Check if a LV2 atom:Sequenece buffer iterator is valid.
164//
165static inline
167{
168 return iter->offset < lv2_atom_buffer_get_size(iter->buf);
169}
170
171
172// Advance a LV2 atom:Sequenece buffer iterator forward one event.
173//
174static inline
176{
177 if (!lv2_atom_buffer_is_valid(iter))
178 return false;
179
180 LV2_Atom_Buffer *buf = iter->buf;
181 LV2_Atom_Sequence *atoms = &buf->atoms;
182 uint32_t size = ((LV2_Atom_Event *) ((char *)
183 LV2_ATOM_CONTENTS(LV2_Atom_Sequence, atoms) + iter->offset))->body.size;
185
186 return true;
187}
188
189
190// Get the event currently pointed at a LV2 atom:Sequence buffer iterator.
191//
192static inline
195{
196 if (!lv2_atom_buffer_is_valid(iter))
197 return NULL;
198
199 LV2_Atom_Buffer *buf = iter->buf;
200 LV2_Atom_Sequence *atoms = &buf->atoms;
201 LV2_Atom_Event *ev = (LV2_Atom_Event *) ((char *)
203
204 *data = (uint8_t *) LV2_ATOM_BODY(&ev->body);
205
206 return ev;
207}
208
209
210// Write an event at a LV2 atom:Sequence buffer iterator.
211
212static inline
215 uint32_t frames,
216 uint32_t /*subframes*/,
219 const uint8_t *data )
220{
221 LV2_Atom_Buffer *buf = iter->buf;
222 LV2_Atom_Sequence *atoms = &buf->atoms;
223 if (buf->capacity - sizeof(LV2_Atom) - atoms->atom.size
224 < sizeof(LV2_Atom_Event) + size)
225 return false;
226
227 LV2_Atom_Event *ev = (LV2_Atom_Event*) ((char *)
229
230 ev->time.frames = frames;
231 ev->body.type = type;
232 ev->body.size = size;
233
235
237 atoms->atom.size += size;
238 iter->offset += size;
239
240 return true;
241}
242
243#ifdef __cplusplus
244} /* extern "C" */
245#endif
246
247#endif // LV2_ATOM_HELPERS_H
248
249// end of lv2_atom_helpers.h
#define NULL
Definition CarlaBridgeFormat.cpp:30
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
static bool lv2_atom_buffer_is_valid(LV2_Atom_Buffer_Iterator *iter)
Definition atom-helpers.h:166
struct _LV2_Atom_Buffer_Iterator LV2_Atom_Buffer_Iterator
static void lv2_atom_buffer_free(LV2_Atom_Buffer *buf)
Definition atom-helpers.h:99
static bool lv2_atom_buffer_write(LV2_Atom_Buffer_Iterator *iter, uint32_t frames, uint32_t, uint32_t type, uint32_t size, const uint8_t *data)
Definition atom-helpers.h:213
static void lv2_atom_buffer_reset(LV2_Atom_Buffer *buf, bool input)
Definition atom-helpers.h:65
static bool lv2_atom_buffer_end(LV2_Atom_Buffer_Iterator *iter, LV2_Atom_Buffer *buf)
Definition atom-helpers.h:153
static bool lv2_atom_buffer_begin(LV2_Atom_Buffer_Iterator *iter, LV2_Atom_Buffer *buf)
Definition atom-helpers.h:140
static LV2_Atom_Sequence * lv2_atom_buffer_get_sequence(LV2_Atom_Buffer *buf)
Definition atom-helpers.h:120
static LV2_Atom_Buffer * lv2_atom_buffer_new(uint32_t capacity, uint32_t chunk_type, uint32_t sequence_type, bool input)
Definition atom-helpers.h:80
static uint32_t lv2_atom_buffer_get_size(LV2_Atom_Buffer *buf)
Definition atom-helpers.h:108
static LV2_Atom_Event * lv2_atom_buffer_get(LV2_Atom_Buffer_Iterator *iter, uint8_t **data)
Definition atom-helpers.h:193
struct _LV2_Atom_Buffer LV2_Atom_Buffer
static bool lv2_atom_buffer_increment(LV2_Atom_Buffer_Iterator *iter)
Definition atom-helpers.h:175
#define LV2_ATOM_BODY(atom)
Definition atom.h:98
#define LV2_ATOM_CONTENTS(type, atom)
Definition atom.h:85
static uint32_t lv2_atom_pad_size(uint32_t size)
Definition atom-util.h:48
JSAMPIMAGE data
Definition jpeglib.h:945
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
Definition atom-helpers.h:130
uint32_t offset
Definition atom-helpers.h:132
LV2_Atom_Buffer * buf
Definition atom-helpers.h:131
Definition atom-helpers.h:53
uint32_t chunk_type
Definition atom-helpers.h:55
uint32_t capacity
Definition atom-helpers.h:54
LV2_Atom_Sequence atoms
Definition atom-helpers.h:57
uint32_t sequence_type
Definition atom-helpers.h:56
Definition atom.h:210
union LV2_Atom_Event::@152045145256255172273117355230252206245037176275 time
int64_t frames
Definition atom.h:213
LV2_Atom body
Definition atom.h:216
Definition atom.h:236
Definition atom.h:243
LV2_Atom atom
Definition atom.h:244
Definition atom.h:106
uint32_t size
Definition atom.h:107
uint32_t type
Definition atom.h:108
memcpy(hh, h, RAND_HEAD_LEN)
ulg size
Definition extract.c:2350
char * malloc()