aboutsummaryrefslogtreecommitdiffstats
path: root/src/lv2_evbuf.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-09-23 15:48:27 +0200
committerDavid Robillard <d@drobilla.net>2018-09-23 15:49:10 +0200
commit6f22ee045e7535c5961374d57453c39d1cee224c (patch)
tree0a2183f448ac57a790d6b44518e2b03b623266cd /src/lv2_evbuf.c
parentd776345e62907ca6e78e325f6f02200f21c82497 (diff)
downloadjalv-6f22ee045e7535c5961374d57453c39d1cee224c.tar.gz
jalv-6f22ee045e7535c5961374d57453c39d1cee224c.tar.bz2
jalv-6f22ee045e7535c5961374d57453c39d1cee224c.zip
Remove support for deprecated event and uri-map extensions
Diffstat (limited to 'src/lv2_evbuf.c')
-rw-r--r--src/lv2_evbuf.c186
1 files changed, 45 insertions, 141 deletions
diff --git a/src/lv2_evbuf.c b/src/lv2_evbuf.c
index 2307c12..d7012c7 100644
--- a/src/lv2_evbuf.c
+++ b/src/lv2_evbuf.c
@@ -1,5 +1,5 @@
/*
- Copyright 2008-2016 David Robillard <http://drobilla.net>
+ Copyright 2008-2018 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -19,19 +19,14 @@
#include <string.h>
#include "lv2/lv2plug.in/ns/ext/atom/atom.h"
-#include "lv2/lv2plug.in/ns/ext/event/event.h"
#include "lv2_evbuf.h"
struct LV2_Evbuf_Impl {
- LV2_Evbuf_Type type;
- uint32_t capacity;
- uint32_t atom_Chunk;
- uint32_t atom_Sequence;
- union {
- LV2_Event_Buffer event;
- LV2_Atom_Sequence atom;
- } buf;
+ uint32_t capacity;
+ uint32_t atom_Chunk;
+ uint32_t atom_Sequence;
+ LV2_Atom_Sequence buf;
};
static inline uint32_t
@@ -41,10 +36,7 @@ lv2_evbuf_pad_size(uint32_t size)
}
LV2_Evbuf*
-lv2_evbuf_new(uint32_t capacity,
- LV2_Evbuf_Type type,
- uint32_t atom_Chunk,
- uint32_t atom_Sequence)
+lv2_evbuf_new(uint32_t capacity, uint32_t atom_Chunk, uint32_t atom_Sequence)
{
// FIXME: memory must be 64-bit aligned
LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc(
@@ -52,7 +44,6 @@ lv2_evbuf_new(uint32_t capacity,
evbuf->capacity = capacity;
evbuf->atom_Chunk = atom_Chunk;
evbuf->atom_Sequence = atom_Sequence;
- lv2_evbuf_set_type(evbuf, type);
lv2_evbuf_reset(evbuf, true);
return evbuf;
}
@@ -64,67 +55,31 @@ lv2_evbuf_free(LV2_Evbuf* evbuf)
}
void
-lv2_evbuf_set_type(LV2_Evbuf* evbuf, LV2_Evbuf_Type type)
-{
- evbuf->type = type;
- switch (type) {
- case LV2_EVBUF_EVENT:
- evbuf->buf.event.data = (uint8_t*)(evbuf + 1);
- evbuf->buf.event.capacity = evbuf->capacity;
- break;
- case LV2_EVBUF_ATOM:
- break;
- }
- lv2_evbuf_reset(evbuf, true);
-}
-
-void
lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input)
{
- switch (evbuf->type) {
- case LV2_EVBUF_EVENT:
- evbuf->buf.event.header_size = sizeof(LV2_Event_Buffer);
- evbuf->buf.event.stamp_type = LV2_EVENT_AUDIO_STAMP;
- evbuf->buf.event.event_count = 0;
- evbuf->buf.event.size = 0;
- break;
- case LV2_EVBUF_ATOM:
- if (input) {
- evbuf->buf.atom.atom.size = sizeof(LV2_Atom_Sequence_Body);
- evbuf->buf.atom.atom.type = evbuf->atom_Sequence;
- } else {
- evbuf->buf.atom.atom.size = evbuf->capacity;
- evbuf->buf.atom.atom.type = evbuf->atom_Chunk;
- }
+ if (input) {
+ evbuf->buf.atom.size = sizeof(LV2_Atom_Sequence_Body);
+ evbuf->buf.atom.type = evbuf->atom_Sequence;
+ } else {
+ evbuf->buf.atom.size = evbuf->capacity;
+ evbuf->buf.atom.type = evbuf->atom_Chunk;
}
}
uint32_t
lv2_evbuf_get_size(LV2_Evbuf* evbuf)
{
- switch (evbuf->type) {
- case LV2_EVBUF_EVENT:
- return evbuf->buf.event.size;
- case LV2_EVBUF_ATOM:
- assert(evbuf->buf.atom.atom.type != evbuf->atom_Sequence
- || evbuf->buf.atom.atom.size >= sizeof(LV2_Atom_Sequence_Body));
- return evbuf->buf.atom.atom.type == evbuf->atom_Sequence
- ? evbuf->buf.atom.atom.size - sizeof(LV2_Atom_Sequence_Body)
- : 0;
- }
- return 0;
+ assert(evbuf->buf.atom.type != evbuf->atom_Sequence
+ || evbuf->buf.atom.size >= sizeof(LV2_Atom_Sequence_Body));
+ return evbuf->buf.atom.type == evbuf->atom_Sequence
+ ? evbuf->buf.atom.size - sizeof(LV2_Atom_Sequence_Body)
+ : 0;
}
void*
lv2_evbuf_get_buffer(LV2_Evbuf* evbuf)
{
- switch (evbuf->type) {
- case LV2_EVBUF_EVENT:
- return &evbuf->buf.event;
- case LV2_EVBUF_ATOM:
- return &evbuf->buf.atom;
- }
- return NULL;
+ return &evbuf->buf;
}
LV2_Evbuf_Iterator
@@ -158,18 +113,10 @@ lv2_evbuf_next(LV2_Evbuf_Iterator iter)
LV2_Evbuf* evbuf = iter.evbuf;
uint32_t offset = iter.offset;
uint32_t size;
- switch (evbuf->type) {
- case LV2_EVBUF_EVENT:
- size = ((LV2_Event*)(evbuf->buf.event.data + offset))->size;
- offset += lv2_evbuf_pad_size(sizeof(LV2_Event) + size);
- break;
- case LV2_EVBUF_ATOM:
- size = ((LV2_Atom_Event*)
- ((char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, &evbuf->buf.atom)
- + offset))->body.size;
- offset += lv2_evbuf_pad_size(sizeof(LV2_Atom_Event) + size);
- break;
- }
+ size = ((LV2_Atom_Event*)
+ ((char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, &evbuf->buf.atom)
+ + offset))->body.size;
+ offset += lv2_evbuf_pad_size(sizeof(LV2_Atom_Event) + size);
LV2_Evbuf_Iterator next = { evbuf, offset };
return next;
@@ -190,32 +137,15 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter,
return false;
}
- LV2_Event_Buffer* ebuf;
- LV2_Event* ev;
- LV2_Atom_Sequence* aseq;
- LV2_Atom_Event* aev;
- switch (iter.evbuf->type) {
- case LV2_EVBUF_EVENT:
- ebuf = &iter.evbuf->buf.event;
- ev = (LV2_Event*)((char*)ebuf->data + iter.offset);
- *frames = ev->frames;
- *subframes = ev->subframes;
- *type = ev->type;
- *size = ev->size;
- *data = (uint8_t*)ev + sizeof(LV2_Event);
- break;
- case LV2_EVBUF_ATOM:
- aseq = &iter.evbuf->buf.atom;
- aev = (LV2_Atom_Event*)(
- (char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, aseq)
- + iter.offset);
- *frames = aev->time.frames;
- *subframes = 0;
- *type = aev->body.type;
- *size = aev->body.size;
- *data = (uint8_t*)LV2_ATOM_BODY(&aev->body);
- break;
- }
+ LV2_Atom_Sequence* aseq = &iter.evbuf->buf;
+ LV2_Atom_Event* aev = (LV2_Atom_Event*)(
+ (char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, aseq) + iter.offset);
+
+ *frames = aev->time.frames;
+ *subframes = 0;
+ *type = aev->body.type;
+ *size = aev->body.size;
+ *data = (uint8_t*)LV2_ATOM_BODY(&aev->body);
return true;
}
@@ -228,49 +158,23 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter,
uint32_t size,
const uint8_t* data)
{
- LV2_Event_Buffer* ebuf;
- LV2_Event* ev;
- LV2_Atom_Sequence* aseq;
- LV2_Atom_Event* aev;
- switch (iter->evbuf->type) {
- case LV2_EVBUF_EVENT:
- ebuf = &iter->evbuf->buf.event;
- if (ebuf->capacity - ebuf->size < sizeof(LV2_Event) + size) {
- return false;
- }
-
- ev = (LV2_Event*)(ebuf->data + iter->offset);
- ev->frames = frames;
- ev->subframes = subframes;
- ev->type = type;
- ev->size = size;
- memcpy((uint8_t*)ev + sizeof(LV2_Event), data, size);
+ LV2_Atom_Sequence* aseq = &iter->evbuf->buf;
+ if (iter->evbuf->capacity - sizeof(LV2_Atom) - aseq->atom.size <
+ sizeof(LV2_Atom_Event) + size) {
+ return false;
+ }
- size = lv2_evbuf_pad_size(sizeof(LV2_Event) + size);
- ebuf->size += size;
- ebuf->event_count += 1;
- iter->offset += size;
- break;
- case LV2_EVBUF_ATOM:
- aseq = &iter->evbuf->buf.atom;
- if (iter->evbuf->capacity - sizeof(LV2_Atom) - aseq->atom.size
- < sizeof(LV2_Atom_Event) + size) {
- return false;
- }
+ LV2_Atom_Event* aev = (LV2_Atom_Event*)(
+ (char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, aseq) + iter->offset);
- aev = (LV2_Atom_Event*)(
- (char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, aseq)
- + iter->offset);
- aev->time.frames = frames;
- aev->body.type = type;
- aev->body.size = size;
- memcpy(LV2_ATOM_BODY(&aev->body), data, size);
+ aev->time.frames = frames;
+ aev->body.type = type;
+ aev->body.size = size;
+ memcpy(LV2_ATOM_BODY(&aev->body), data, size);
- size = lv2_evbuf_pad_size(sizeof(LV2_Atom_Event) + size);
- aseq->atom.size += size;
- iter->offset += size;
- break;
- }
+ size = lv2_evbuf_pad_size(sizeof(LV2_Atom_Event) + size);
+ aseq->atom.size += size;
+ iter->offset += size;
return true;
}