From 3d89115a67a9c947a28539ffdd2399808a53279b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 16 Nov 2009 00:30:35 +0000 Subject: Rework objects extension to have "value ports" and "message ports". Make audio and control buffers in ingen actually object buffers (towards interop). Overhaul the hell out of ingen buffer and mixing stuff. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2266 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/ObjectBuffer.cpp | 97 +++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 44 deletions(-) (limited to 'src/engine/ObjectBuffer.cpp') diff --git a/src/engine/ObjectBuffer.cpp b/src/engine/ObjectBuffer.cpp index a26eaea5..f96c910f 100644 --- a/src/engine/ObjectBuffer.cpp +++ b/src/engine/ObjectBuffer.cpp @@ -34,56 +34,41 @@ namespace Ingen { using namespace Shared; -/** Allocate a new string buffer. - * \a capacity is in bytes. +/** Allocate a new object buffer. + * \a capacity is in bytes, including LV2_Object header */ ObjectBuffer::ObjectBuffer(size_t capacity) : Buffer(DataType(DataType::VALUE), capacity) { - capacity = std::max(capacity, (size_t)32); - cerr << "Creating Object Buffer " << _buf << " capacity = " << capacity << endl; - _local_buf = (LV2_Object*)malloc(sizeof(LV2_Object) + capacity); - _buf = _local_buf; - clear(); + //cerr << "Creating Object Buffer capacity = " << capacity << endl; + assert(capacity >= sizeof(LV2_Object)); + +#ifdef HAVE_POSIX_MEMALIGN + const int ret = posix_memalign((void**)&_buf, 16, capacity); +#else + _buf = (LV2_Object*)malloc(capacity); + const int ret = (_buf != NULL) ? 0 : -1; +#endif + + if (ret != 0) { + cerr << "Failed to allocate buffer. Aborting." << endl; + exit(EXIT_FAILURE); + } + + object()->type = 0; + object()->size = capacity; } void ObjectBuffer::clear() { - // nil + // null _buf->type = 0; _buf->size = 0; } -/** Use another buffer's data instead of the local one. - * - * This buffer will essentially be identical to @a buf after this call. - */ -bool -ObjectBuffer::join(Buffer* buf) -{ - assert(buf != this); - ObjectBuffer* sbuf = dynamic_cast(buf); - if (!sbuf) - return false; - - _buf = sbuf->_local_buf; - _joined_buf = sbuf; - - return true; -} - - -void -ObjectBuffer::unjoin() -{ - _joined_buf = NULL; - _buf = _local_buf; -} - - void ObjectBuffer::copy(Context& context, const Buffer* src_buf) { @@ -91,27 +76,51 @@ ObjectBuffer::copy(Context& context, const Buffer* src_buf) if (!src || src == this || src->_buf == _buf) return; - // Copy if src is a POD object only, that fits - if (src->_buf->type != 0 && src->_buf->size <= size()) - memcpy(_buf, src->_buf, sizeof(LV2_Object) + src->_buf->size); + // Copy only if src is a POD object that fits + if (src->_buf->type != 0 && src_buf->size() <= size()) + memcpy(_buf, src->_buf, sizeof(LV2_Object) + src_buf->size()); } void ObjectBuffer::resize(size_t size) { - const bool using_local_data = (_buf == _local_buf); - const uint32_t contents_size = sizeof(LV2_Object) + _buf->size; + const uint32_t contents_size = sizeof(LV2_Object) + _buf->size; - _local_buf = (LV2_Object*)realloc(_buf, sizeof(LV2_Object) + size); - _size = size; + _buf = (LV2_Object*)realloc(_buf, sizeof(LV2_Object) + size); + _size = size; // If we shrunk and chopped the current contents, clear corrupt data if (size < contents_size) clear(); +} + - if (using_local_data) - _buf = _local_buf; +void* +ObjectBuffer::port_data(DataType port_type) +{ + switch (port_type.symbol()) { + case DataType::CONTROL: + return object()->body; + case DataType::AUDIO: + return ((LV2_Vector_Body*)object()->body)->elems; + default: + return _buf; + } +} + + +const void* +ObjectBuffer::port_data(DataType port_type) const +{ + switch (port_type.symbol()) { + case DataType::CONTROL: + return _buf + sizeof(LV2_Object); + case DataType::AUDIO: + return _buf + sizeof(LV2_Object) + sizeof(LV2_Vector_Body); + default: + return _buf; + } } -- cgit v1.2.1