From a6fb6a0289ea47692d87f3e0200532a426f8e60d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 28 Jul 2008 21:56:03 +0000 Subject: Simply global memory management crap by using shared_ptr in the World struct (it's not C anyway, might as well). Properly support LV2 events from plugin UIs over OSC and directly (w/ monolithic UI/engine). Fix crashes on node destruction with monolithic UI/engine. Resolves ticket #177. git-svn-id: http://svn.drobilla.net/lad/ingen@1293 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/EventBuffer.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/libs/engine/EventBuffer.cpp') diff --git a/src/libs/engine/EventBuffer.cpp b/src/libs/engine/EventBuffer.cpp index 9985e2b7..dfeff610 100644 --- a/src/libs/engine/EventBuffer.cpp +++ b/src/libs/engine/EventBuffer.cpp @@ -178,6 +178,9 @@ EventBuffer::append(uint32_t frames, } #endif + /*cout << "Appending event type " << type << ", size " << size + << " @ " << frames << "." << subframes << endl;*/ + bool ret = lv2_event_write(&_iter, frames, subframes, type, size, data); if (!ret) @@ -190,6 +193,43 @@ EventBuffer::append(uint32_t frames, } +/** Append a buffer of events to the buffer. + * + * \a timestamp must be >= the latest event in the buffer, + * and < this_nframes() + * + * \return true on success + */ +bool +EventBuffer::append(const LV2_Event_Buffer* buf) +{ + uint8_t** data; + bool ret = true; + + LV2_Event_Iterator iter; + for (lv2_event_begin(&iter, _buf); lv2_event_is_valid(&iter); lv2_event_increment(&iter)) { + LV2_Event* ev = lv2_event_get(&iter, data); + +#ifndef NDEBUG + assert((ev->frames > _latest_frames) + || (ev->frames == _latest_frames + && ev->subframes >= _latest_subframes)); +#endif + + if (!(ret = append(ev->frames, ev->subframes, ev->type, ev->size, *data))) { + cerr << "ERROR: Failed to write event." << endl; + break; + } else { + } + + _latest_frames = ev->frames; + _latest_subframes = ev->subframes; + } + + return ret; +} + + /** Read an event from the current position in the buffer * * \return true if read was successful, or false if end of buffer reached -- cgit v1.2.1