From 64bd557e75113743f179086b365ea7d97b72ee3e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 12 Nov 2009 06:56:26 +0000 Subject: String port support. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2255 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/StringBuffer.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/engine/StringBuffer.cpp (limited to 'src/engine/StringBuffer.cpp') diff --git a/src/engine/StringBuffer.cpp b/src/engine/StringBuffer.cpp new file mode 100644 index 00000000..a6cec9f1 --- /dev/null +++ b/src/engine/StringBuffer.cpp @@ -0,0 +1,121 @@ +/* This file is part of Ingen. + * Copyright (C) 2009 Dave Robillard + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define __STDC_LIMIT_MACROS 1 +#include +#include +#include +#include "ingen-config.h" +#include "StringBuffer.hpp" + +using namespace std; + +namespace Ingen { + +using namespace Shared; + +/** Allocate a new string buffer. + * \a capacity is in bytes. + */ +StringBuffer::StringBuffer(size_t capacity) + : Buffer(DataType(DataType::EVENT), capacity) +{ + memset(&_local_buf, '\0', sizeof(LV2_String_Data)); + _local_buf.data = (char*)malloc(capacity); + _local_buf.storage = capacity; + + _buf = &_local_buf; + clear(); + + cerr << "Creating String Buffer " << _buf << ", capacity = " << capacity << endl; +} + + +void +StringBuffer::clear() +{ + static const string default_val("2\n0 1\n1 1\n"); + if (_buf && _buf->data && _buf->storage > default_val.length()) + strncpy(_buf->data, default_val.c_str(), default_val.length()); +} + + +/** Use another buffer's data instead of the local one. + * + * This buffer will essentially be identical to @a buf after this call. + */ +bool +StringBuffer::join(Buffer* buf) +{ + assert(buf != this); + StringBuffer* sbuf = dynamic_cast(buf); + if (!sbuf) + return false; + + _buf = &sbuf->_local_buf; + _joined_buf = sbuf; + + return true; +} + + +void +StringBuffer::unjoin() +{ + _joined_buf = NULL; + _buf = &_local_buf; +} + + +void +StringBuffer::prepare_read(FrameTime start, SampleCount nframes) +{ + _this_nframes = nframes; +} + + +void +StringBuffer::prepare_write(FrameTime start, SampleCount nframes) +{ +} + + +void +StringBuffer::copy(const Buffer* src_buf, size_t start_sample, size_t end_sample) +{ + const StringBuffer* src = dynamic_cast(src_buf); + assert(src); + assert(src != this); + assert(src->_buf != _buf); + assert(src->_buf->data != _buf->data); + + strncpy(_buf->data, src->_buf->data, std::min(_buf->len, src->_buf->len)); + _this_nframes = end_sample - start_sample; +} + + +void +StringBuffer::resize(size_t size) +{ + _buf->data = (char*)realloc(_buf->data, size); + _buf->storage = size; + _size = size; +} + + +} // namespace Ingen + -- cgit v1.2.1