aboutsummaryrefslogtreecommitdiffstats
path: root/lv2/lv2plug.in/ns/ext/atom
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-02-08 02:30:06 +0000
committerDavid Robillard <d@drobilla.net>2014-02-08 02:30:06 +0000
commit60eb52f31976763497cd0355cc0d6b46af6c465f (patch)
tree13783ae9948977c809d2907ee7b80aa0ebbdb2d9 /lv2/lv2plug.in/ns/ext/atom
parent6d41effb84c6663704d7f2ed562d7bbf4f5cc441 (diff)
downloadlv2-60eb52f31976763497cd0355cc0d6b46af6c465f.tar.xz
Add lv2_atom_sequence_clear() and lv2_atom_sequence_append_event() helper functions.
Add MIDI fifths example plugin for simple non-forge MIDI reading and writing.
Diffstat (limited to 'lv2/lv2plug.in/ns/ext/atom')
-rw-r--r--lv2/lv2plug.in/ns/ext/atom/lv2-atom.doap.ttl2
-rw-r--r--lv2/lv2plug.in/ns/ext/atom/util.h46
2 files changed, 48 insertions, 0 deletions
diff --git a/lv2/lv2plug.in/ns/ext/atom/lv2-atom.doap.ttl b/lv2/lv2plug.in/ns/ext/atom/lv2-atom.doap.ttl
index 251d998..f70a410 100644
--- a/lv2/lv2plug.in/ns/ext/atom/lv2-atom.doap.ttl
+++ b/lv2/lv2plug.in/ns/ext/atom/lv2-atom.doap.ttl
@@ -22,6 +22,8 @@
rdfs:label "Add lv2_atom_forge_is_object_type() and lv2_atom_forge_is_blank() to ease backwards compatibility."
] , [
rdfs:label "Add lv2_atom_forge_key() for terser object writing."
+ ] , [
+ rdfs:label "Add lv2_atom_sequence_clear() and lv2_atom_sequence_append_event() helper functions."
]
]
] , [
diff --git a/lv2/lv2plug.in/ns/ext/atom/util.h b/lv2/lv2plug.in/ns/ext/atom/util.h
index d306e1c..d7c020b 100644
--- a/lv2/lv2plug.in/ns/ext/atom/util.h
+++ b/lv2/lv2plug.in/ns/ext/atom/util.h
@@ -129,6 +129,52 @@ lv2_atom_sequence_next(const LV2_Atom_Event* i)
/**
@}
+ @name Sequence Utilities
+ @{
+*/
+
+/**
+ Clear all events from @p sequence.
+
+ This simply resets the size field, the other fields are left untouched.
+*/
+static inline void
+lv2_atom_sequence_clear(LV2_Atom_Sequence* seq)
+{
+ seq->atom.size = sizeof(LV2_Atom_Sequence_Body);
+}
+
+/**
+ Append an event at the end of @p sequence.
+
+ @param seq Sequence to append to.
+ @param capacity Total capacity of the sequence atom
+ (e.g. as set by the host for sequence output ports).
+ @param event Event to write.
+
+ @return A pointer to the newly written event in @p seq,
+ or NULL on failure (insufficient space).
+*/
+static inline LV2_Atom_Event*
+lv2_atom_sequence_append_event(LV2_Atom_Sequence* seq,
+ uint32_t capacity,
+ const LV2_Atom_Event* event)
+{
+ const uint32_t total_size = (uint32_t)sizeof(*event) + event->body.size;
+ if (capacity - seq->atom.size < total_size) {
+ return NULL;
+ }
+
+ LV2_Atom_Event* e = lv2_atom_sequence_end(&seq->body, seq->atom.size);
+ memcpy(e, event, total_size);
+
+ seq->atom.size += lv2_atom_pad_size(total_size);
+
+ return e;
+}
+
+/**
+ @}
@name Tuple Iterator
@{
*/