From 60eb52f31976763497cd0355cc0d6b46af6c465f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 8 Feb 2014 02:30:06 +0000 Subject: 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. --- lv2/lv2plug.in/ns/ext/atom/lv2-atom.doap.ttl | 2 ++ lv2/lv2plug.in/ns/ext/atom/util.h | 46 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'lv2') 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 @@ -127,6 +127,52 @@ lv2_atom_sequence_next(const LV2_Atom_Event* i) !lv2_atom_sequence_is_end(body, size, (iter)); \ (iter) = lv2_atom_sequence_next(iter)) +/** + @} + @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 -- cgit v1.2.1