From d1e58b25654ab25607329afacc9a23d829267637 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 Nov 2015 19:22:09 -0500 Subject: Fix buffer copying for various types --- src/server/Buffer.cpp | 8 +++----- src/server/Buffer.hpp | 3 +++ src/server/InternalBlock.cpp | 12 +++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/server/Buffer.cpp b/src/server/Buffer.cpp index 4fbb44f9..97f1c308 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -158,12 +158,10 @@ Buffer::copy(const Context& context, const Buffer* src) { if (!_buf) { return; - } else if (is_audio() && src->is_audio()) { - memcpy(_buf, src->_buf, src->_capacity); } else if (_type == src->type()) { - const LV2_Atom* src_atom = src->get(); - if (lv2_atom_total_size(src_atom) <= _capacity) { - memcpy(_buf, src_atom, lv2_atom_total_size(src_atom)); + const uint32_t src_size = src->size(); + if (src_size <= _capacity) { + memcpy(_buf, src->_buf, src_size); } else { clear(); } diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index 11037dd1..aa732781 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -60,6 +60,9 @@ public: inline LV2_URID type() const { return _type; } inline LV2_URID value_type() const { return _value_type; } inline uint32_t capacity() const { return _capacity; } + inline uint32_t size() const { + return is_audio() ? _capacity : sizeof(LV2_Atom) + get()->size; + } void set_type(LV2_URID type, LV2_URID value_type); diff --git a/src/server/InternalBlock.cpp b/src/server/InternalBlock.cpp index 5fa0bdc0..308cb640 100644 --- a/src/server/InternalBlock.cpp +++ b/src/server/InternalBlock.cpp @@ -31,15 +31,17 @@ InternalBlock::InternalBlock(PluginImpl* plugin, void -InternalBlock::pre_process(ProcessContext& context) { - /* Output sequences are initialized in LV2 format, an atom:Chunk with size - set to the capacity of the buffer. Internal nodes don't care, so clear - to an empty sequences so appending events results in a valid output. */ +InternalBlock::pre_process(ProcessContext& context) +{ for (uint32_t i = 0; i < num_ports(); ++i) { PortImpl* const port = _ports->at(i); if (port->is_input()) { port->pre_process(context); - } else { + } else if (port->buffer_type() == _plugin->uris().atom_Sequence) { + /* Output sequences are initialized in LV2 format, an atom:Chunk + with size set to the capacity of the buffer. Internal nodes + don't care, so clear to an empty sequences so appending events + results in a valid output. */ for (uint32_t v = 0; v < port->poly(); ++v) { port->buffer(v)->clear(); } -- cgit v1.2.1