34 #ifndef LV2_ATOM_HELPERS_H
35 #define LV2_ATOM_HELPERS_H
37 #include <lv2/lv2plug.in/ns/ext/atom/atom.h>
38 #include <lv2/lv2plug.in/ns/ext/atom/forge.h>
39 #include <lv2/lv2plug.in/ns/ext/atom/util.h>
53 static uint32_t sequence_type;
54 static uint32_t chunk_type;
57 alignas(8) LV2_Atom_Sequence atoms;
58 LV2_Atom_Buffer(uint32_t capacity, uint32_t ct, uint32_t seq_type,
bool input)
62 sequence_type = seq_type;
66 void reset(
bool input)
70 atoms.atom.size =
sizeof(LV2_Atom_Sequence_Body);
71 atoms.atom.type = sequence_type;
75 atoms.atom.size = capacity;
76 atoms.atom.type = chunk_type;
85 if(atoms.atom.type == sequence_type)
86 return atoms.atom.size -
sizeof(LV2_Atom_Sequence_Body);
92 LV2_Atom_Sequence* get_sequence(
LV2_Atom_Buffer* buf) {
return &buf->atoms; }
109 static uint32_t pad_size(uint32_t size) {
return (size + 7) & (~7); }
118 return (buf->atoms.atom.size > 0);
126 offset = pad_size(buf->get_size());
128 return (offset < buf->capacity -
sizeof(LV2_Atom_Event));
133 bool is_valid() {
return offset < buf->get_size(); }
142 LV2_Atom_Sequence* atoms = &buf->atoms;
144 = ((LV2_Atom_Event*)((
char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, atoms) + offset))
146 offset += pad_size(
sizeof(LV2_Atom_Event) + size);
153 LV2_Atom_Event* get(uint8_t** data)
158 auto atoms = &buf->atoms;
160 = (LV2_Atom_Event*)((
char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, atoms) + offset);
162 *data = (uint8_t*)LV2_ATOM_BODY(&ev->body);
169 uint32_t frames, uint32_t , uint32_t type, uint32_t size,
172 LV2_Atom_Sequence* atoms = &buf->atoms;
173 if(buf->capacity -
sizeof(LV2_Atom) - atoms->atom.size
174 <
sizeof(LV2_Atom_Event) + size)
178 = (LV2_Atom_Event*)((
char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, atoms) + offset);
180 ev->time.frames = frames;
181 ev->body.type = type;
182 ev->body.size = size;
184 memcpy(LV2_ATOM_BODY(&ev->body), data, size);
186 size = pad_size(
sizeof(LV2_Atom_Event) + size);
187 atoms->atom.size += size;
197 AtomBuffer(uint32_t capacity, uint32_t chunk_type, uint32_t seq_type,
bool input)
Definition: lv2_atom_helpers.hpp:195
Definition: lv2_atom_helpers.hpp:99
Definition: lv2_atom_helpers.hpp:52