30 #include <lv2/lv2plug.in/ns/ext/atom/atom.h> 31 #include <lv2/lv2plug.in/ns/ext/atom/forge.h> 32 #include <lv2/lv2plug.in/ns/ext/atom/util.h> 38 typedef LV2_Atom_Property_Body PropertyBody;
39 typedef LV2_Atom_Forge_Frame ForgeFrame;
40 typedef LV2_Atom_Forge_Ref ForgeRef;
41 typedef LV2_Atom_Object_Query ObjectQuery;
49 AtomObject (
const void* atom) : p_obj ((LV2_Atom_Object*) atom) { }
52 AtomObject (ForgeRef ref) : p_obj ((LV2_Atom_Object*) ref) { }
60 return p_obj->body.otype;
67 return p_obj->body.id;
74 return lv2_atom_total_size ((LV2_Atom*) p_obj);
91 lv2_atom_object_query (p_obj, &query);
95 inline LV2_Atom_Object*
cobj()
const {
return p_obj; }
98 inline operator LV2_Atom_Object*() {
return p_obj; }
113 iterator (LV2_Atom_Object* o, LV2_Atom_Property_Body* i)
114 : index (i), obj (o) { }
116 const PropertyBody& operator*()
const { assert (index);
return *index; }
117 const PropertyBody* operator->()
const { assert (index);
return index; }
121 index = lv2_atom_object_next (index);
122 if (lv2_atom_object_is_end (&obj->body, obj->atom.size, index))
134 bool operator== (
const iterator& other)
const {
return index == other.index; }
135 bool operator!= (
const iterator& other)
const {
return index != other.index; }
140 LV2_Atom_Property_Body* index;
141 LV2_Atom_Object* obj;
145 iterator begin()
const {
return iterator (p_obj, lv2_atom_object_begin (&p_obj->body)); }
150 LV2_Atom_Object* p_obj;
163 Atom (
const void* atom) : p_atom ((LV2_Atom*) atom) { }
166 Atom (ForgeRef ref) : p_atom ((LV2_Atom*) ref) { }
169 Atom (AtomEvent* ev) : p_atom (&ev->body) { }
172 inline static uint32_t
175 return lv2_atom_pad_size (size);
182 return lv2_atom_is_null (p_atom);
189 return LV2_ATOM_BODY (p_atom);
196 return ((LV2_Atom_Bool*)p_atom)->body > 0;
203 return ((LV2_Atom_Float*)p_atom)->body;
209 return AtomObject ((LV2_Atom_Object* ) p_atom);
216 return (
const char*) LV2_ATOM_BODY (p_atom);
223 return ((LV2_Atom_Int*)p_atom)->body;
230 return ((LV2_Atom_Long*)p_atom)->body;
237 return ((LV2_Atom_URID*)p_atom)->body;
251 return lv2_atom_total_size (p_atom);
262 inline const LV2_Atom*
269 inline operator const LV2_Atom*() {
return cobj(); }
273 operator= (
const Atom& other)
275 p_atom = other.p_atom;
281 operator== (
Atom& other)
283 return lv2_atom_equals (
cobj(), other.
cobj());
288 const LV2_Atom* p_atom;
297 typedef AtomEvent* pointer;
298 typedef AtomEvent& reference;
299 typedef const AtomEvent* const_pointer;
300 typedef const AtomEvent& const_reference;
317 return p_seq->body.pad;
324 return p_seq->atom.size;
331 return p_seq->body.unit;
335 inline LV2_Atom_Sequence*
342 inline operator bool()
const {
return p_seq != 0; }
345 inline operator LV2_Atom_Sequence*()
const {
return p_seq; }
348 inline operator uint8_t*()
const {
return (uint8_t*) p_seq; }
355 if (AtomEvent* pos = lv2_atom_sequence_end (&p_seq->body, p_seq->atom.size))
357 memcpy (pos, &ev,
sizeof (AtomEvent));
358 memcpy (pos + 1, LV2_ATOM_BODY_CONST (&ev.body), ev.body.size);
359 ((LV2_Atom*) p_seq)->size +=
sizeof (LV2_Atom_Event) + lv2_atom_pad_size (ev.body.size);
368 const uint32_t evsize =
sizeof (LV2_Atom_Event) + lv2_atom_pad_size (ev.body.size);
369 AtomEvent* pos = lv2_atom_sequence_end (&p_seq->body, p_seq->atom.size);
370 LV2_ATOM_SEQUENCE_FOREACH (p_seq, iter)
372 if (iter->time.frames > ev.time.frames)
374 memmove ((uint8_t*)iter + evsize, iter,
375 (uint8_t*)pos - (uint8_t*)iter);
383 memcpy (pos, &ev,
sizeof (AtomEvent));
384 memcpy (pos + 1, LV2_ATOM_BODY_CONST (&ev.body), ev.body.size);
385 ((LV2_Atom*) p_seq)->size += evsize;
394 iterator (LV2_Atom_Sequence *seq, AtomEvent* ev) : p_event (ev), p_seq (seq) { }
395 AtomEvent& operator*() {
return *p_event; }
396 const AtomEvent* operator->()
const {
return p_event; }
400 p_event = lv2_atom_sequence_next (p_event);
411 inline bool operator== (
const iterator& other)
const {
return p_event == other.p_event; }
412 inline bool operator!= (
const iterator& other)
const {
return p_event != other.p_event; }
417 LV2_Atom_Event* p_event;
418 LV2_Atom_Sequence* p_seq;
425 inline iterator end()
const {
return iterator (p_seq, lv2_atom_sequence_end (&p_seq->body, p_seq->atom.size)); }
429 LV2_Atom_Sequence* p_seq;
459 lv2_atom_forge_init (
this, map);
465 inline LV2_Atom_Forge*
468 return (LV2_Atom_Forge*)
this;
475 return lv2_atom_forge_sequence_head (
this, &frame, unit);
478 inline operator LV2_Atom_Forge* () {
return cobj(); }
488 lv2_atom_forge_set_buffer (
this, buf, size);
495 return lv2_atom_forge_beat_time (
this, beats);
504 return lv2_atom_forge_frame_time (
this, frames);
514 return lv2_atom_forge_property_head (
this, key, context);
523 lv2_atom_forge_pop (
this, &frame);
535 return lv2_atom_forge_atom (
this, size, type);
546 return lv2_atom_forge_path (
this, path.c_str(), path.size());
559 return lv2_atom_forge_resource (
this, &frame,
id, otype);
570 return lv2_atom_forge_blank (
this, &frame,
id, otype);
579 return lv2_atom_forge_bool (
this, val);
588 return lv2_atom_forge_int (
this, val);
597 return lv2_atom_forge_float (
this, val);
606 return lv2_atom_forge_long (
this, val);
615 return lv2_atom_forge_string (
this, str, strlen (str));
624 return lv2_atom_forge_uri (
this, uri, strlen (uri));
634 return lv2_atom_forge_raw (
this, data, size);
643 return lv2_atom_forge_urid (
this,
id);
653 inline AtomVector (ForgeRef ref) : vec ((LV2_Atom_Vector*) ref) { }
656 inline size_t size()
const {
return vec->atom.size / vec->body.child_size; }
657 inline uint32_t child_size()
const {
return vec->body.child_size; }
658 inline uint32_t child_type()
const {
return vec->body.child_type; }
660 inline operator LV2_Atom_Vector* ()
const {
return vec; }
669 offset += vec->body.child_size;
671 if (vec && offset >= vec->atom.size)
672 offset = vec->atom.size;
684 inline bool operator== (
const iterator& other)
const {
return vec == other.vec && offset == other.offset; }
685 inline bool operator!= (
const iterator& other)
const {
return vec != other.vec && offset != other.offset; }
690 this->vec = other.vec;
691 this->offset = other.offset;
697 iterator (LV2_Atom_Vector *v, uint32_t os = 0) : vec (v), offset (os) { }
698 LV2_Atom_Vector* vec;
709 LV2_Atom_Vector* vec;
ForgeRef write_urid(LV2_URID id)
Definition: atom.hpp:641
uint32_t size() const
Definition: atom.hpp:256
uint32_t type() const
Definition: atom.hpp:242
iterator begin() const
Definition: atom.hpp:422
int32_t as_int() const
Definition: atom.hpp:221
AtomObject(const void *atom)
Definition: atom.hpp:49
ForgeRef write_raw(const void *data, uint32_t size)
Definition: atom.hpp:632
bool is_null()
Definition: atom.hpp:180
AtomForge()
Definition: atom.hpp:444
const AtomObject as_object() const
Definition: atom.hpp:208
uint32_t id() const
Definition: atom.hpp:65
LV2_Atom_Forge * cobj()
Definition: atom.hpp:466
uint32_t unit() const
Definition: atom.hpp:329
void * body() const
Definition: atom.hpp:187
void set_buffer(uint8_t *buf, uint32_t size)
Definition: atom.hpp:486
iterator end() const
Definition: atom.hpp:706
ForgeRef write_resource(ForgeFrame &frame, uint32_t id, uint32_t otype)
Definition: atom.hpp:557
Atom()
Definition: atom.hpp:160
int64_t as_long() const
Definition: atom.hpp:228
AtomSequence(LV2_Atom_Sequence *seq)
Definition: atom.hpp:308
void insert(const AtomEvent &ev)
Definition: atom.hpp:366
AtomSequence(ForgeRef ref)
Definition: atom.hpp:311
AtomSequence(const void *seq)
Definition: atom.hpp:304
float as_float() const
Definition: atom.hpp:201
LV2_Atom_Sequence * cobj()
Definition: atom.hpp:336
const char * as_string() const
Definition: atom.hpp:214
AtomForge(LV2_URID_Map *map)
Definition: atom.hpp:448
void init(LV2_URID_Map *map)
Definition: atom.hpp:457
LV2_Atom_Object * cobj() const
Definition: atom.hpp:95
LV2_Atom_Event AtomEvent
Definition: atom.hpp:37
ForgeRef sequence_head(ForgeFrame &frame, uint32_t unit)
Definition: atom.hpp:473
ForgeRef write_uri(const char *uri)
Definition: atom.hpp:622
ForgeRef property_head(uint32_t key, uint32_t context)
Definition: atom.hpp:512
ForgeRef write_atom(uint32_t size, uint32_t type)
Definition: atom.hpp:533
static uint32_t pad_size(uint32_t size)
Definition: atom.hpp:173
Atom(AtomEvent *ev)
Definition: atom.hpp:169
ForgeRef write_string(const char *str)
Definition: atom.hpp:613
ForgeRef frame_time(int64_t frames)
Definition: atom.hpp:502
ForgeRef write_long(const int64_t val)
Definition: atom.hpp:604
const LV2_Atom * cobj() const
Definition: atom.hpp:263
Definition: feature.hpp:34
void pop(ForgeFrame &frame)
Definition: atom.hpp:521
void append(const AtomEvent &ev)
Definition: atom.hpp:353
uint32_t as_urid() const
Definition: atom.hpp:235
void query(ObjectQuery &query)
Definition: atom.hpp:89
ForgeRef write_int(const int val)
Definition: atom.hpp:586
iterator begin() const
Definition: atom.hpp:703
uint32_t total_size() const
Definition: atom.hpp:72
bool as_bool() const
Definition: atom.hpp:194
ForgeRef write_bool(const bool val)
Definition: atom.hpp:577
ForgeRef write_path(const std::string &path)
Definition: atom.hpp:544
ForgeRef beat_time(double beats)
Definition: atom.hpp:493
uint32_t pad() const
Definition: atom.hpp:315
uint32_t total_size() const
Definition: atom.hpp:249
Atom(const void *atom)
Definition: atom.hpp:163
Atom(ForgeRef ref)
Definition: atom.hpp:166
uint32_t otype() const
Definition: atom.hpp:58
uint32_t size() const
Definition: atom.hpp:322
AtomObject(ForgeRef ref)
Definition: atom.hpp:52
iterator end() const
Definition: atom.hpp:425
ForgeRef write_float(const float val)
Definition: atom.hpp:595
ForgeRef write_blank(ForgeFrame &frame, uint32_t id, uint32_t otype)
Definition: atom.hpp:568