summaryrefslogtreecommitdiffstats
path: root/src/engine/LV2EventBuffer.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-01-04 20:59:01 +0000
committerDavid Robillard <d@drobilla.net>2010-01-04 20:59:01 +0000
commitbfca1f3a2739c1c0148b0641d3bdb8f4ea16b431 (patch)
tree39ca3cffc0e404fe33fac66663444d9e1a603b96 /src/engine/LV2EventBuffer.cpp
parent29b77e922d7fd883795b04eadd528eca21a37a2f (diff)
downloadingen-bfca1f3a2739c1c0148b0641d3bdb8f4ea16b431.tar.gz
ingen-bfca1f3a2739c1c0148b0641d3bdb8f4ea16b431.tar.bz2
ingen-bfca1f3a2739c1c0148b0641d3bdb8f4ea16b431.zip
Remove redundant LV2EventBuffer class and merge with EventBuffer.
Refactor mixing from an in-place Buffer method (which doesn't work with EventBuffer) to a single function that takes an out of place destination and an array of sources. Fix audio buffer mixing for control<->audio. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2333 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/LV2EventBuffer.cpp')
-rw-r--r--src/engine/LV2EventBuffer.cpp238
1 files changed, 0 insertions, 238 deletions
diff --git a/src/engine/LV2EventBuffer.cpp b/src/engine/LV2EventBuffer.cpp
deleted file mode 100644
index cb157368..00000000
--- a/src/engine/LV2EventBuffer.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/* This file is part of Ingen.
- * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net>
- *
- * 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 <stdint.h>
-#include <iostream>
-#include "ingen-config.h"
-#include "LV2EventBuffer.hpp"
-#include "event.lv2/event.h"
-#include "event.lv2/event-helpers.h"
-
-using namespace std;
-
-namespace Ingen {
-
-
-/** Allocate a new event buffer.
- * \a capacity is in bytes (not number of events).
- */
-LV2EventBuffer::LV2EventBuffer(size_t capacity)
- : _latest_frames(0)
- , _latest_subframes(0)
-{
- if (capacity > UINT32_MAX) {
- cerr << "Event buffer size " << capacity << " too large, aborting." << endl;
- throw std::bad_alloc();
- }
-
-#ifdef HAVE_POSIX_MEMALIGN
- int ret = posix_memalign((void**)&_data, 16, sizeof(LV2_Event_Buffer) + capacity);
-#else
- _data = (LV2_Event_Buffer*)malloc(sizeof(LV2_Event_Buffer) + capacity);
- int ret = (_data != NULL) ? 0 : -1;
-#endif
-
- if (ret != 0) {
- cerr << "Failed to allocate event buffer. Aborting." << endl;
- exit(EXIT_FAILURE);
- }
-
- _data->header_size = sizeof(LV2_Event_Buffer);
- _data->data = reinterpret_cast<uint8_t*>(_data + _data->header_size);
- _data->stamp_type = 0;
- _data->event_count = 0;
- _data->capacity = (uint32_t)capacity;
- _data->size = 0;
-
- reset();
-
- //cerr << "Creating MIDI Buffer " << _data << ", capacity = " << _data->capacity << endl;
-}
-
-
-LV2EventBuffer::~LV2EventBuffer()
-{
- free(_data);
-}
-
-
-/** Increment the read position by one event.
- *
- * \return true if increment was successful, or false if end of buffer reached.
- */
-bool
-LV2EventBuffer::increment() const
-{
- if (lv2_event_is_valid(&_iter)) {
- lv2_event_increment(&_iter);
- return true;
- } else {
- return false;
- }
-}
-
-
-/** \return true iff the cursor is valid (ie get_event is safe)
- */
-bool
-LV2EventBuffer::is_valid() const
-{
- return lv2_event_is_valid(&_iter);
-}
-
-
-/** Read an event from the current position in the buffer
- *
- * \return true if read was successful, or false if end of buffer reached
- */
-bool
-LV2EventBuffer::get_event(uint32_t* frames,
- uint32_t* subframes,
- uint16_t* type,
- uint16_t* size,
- uint8_t** data) const
-{
- if (lv2_event_is_valid(&_iter)) {
- LV2_Event* ev = lv2_event_get(&_iter, data);
- *frames = ev->frames;
- *subframes = ev->subframes;
- *type = ev->type;
- *size = ev->size;
- return true;
- } else {
- return false;
- }
-}
-
-
-/** Get the object currently pointed to, or NULL if invalid.
- */
-LV2_Object*
-LV2EventBuffer::get_object() const
-{
- if (lv2_event_is_valid(&_iter)) {
- uint8_t* data;
- LV2_Event* ev = lv2_event_get(&_iter, &data);
- return LV2_OBJECT_FROM_EVENT(ev);
- }
- return NULL;
-}
-
-
-/** Get the event currently pointed to, or NULL if invalid.
- */
-LV2_Event*
-LV2EventBuffer::get_event() const
-{
- if (lv2_event_is_valid(&_iter)) {
- uint8_t* data;
- return lv2_event_get(&_iter, &data);
- }
- return NULL;
-}
-
-
-/** Append an event to the buffer.
- *
- * \a timestamp must be >= the latest event in the buffer.
- *
- * \return true on success
- */
-bool
-LV2EventBuffer::append(uint32_t frames,
- uint32_t subframes,
- uint16_t type,
- uint16_t size,
- const uint8_t* data)
-{
-#ifndef NDEBUG
- if (lv2_event_is_valid(&_iter)) {
- LV2_Event* last_event = lv2_event_get(&_iter, NULL);
- assert(last_event->frames < frames
- || (last_event->frames == frames && last_event->subframes <= subframes));
- }
-#endif
-
- /*cout << "Appending event type " << type << ", size " << size
- << " @ " << frames << "." << subframes << endl;*/
-
- if (!lv2_event_write(&_iter, frames, subframes, type, size, data)) {
- cerr << "ERROR: Failed to write event." << endl;
- return false;
- } else {
- _latest_frames = frames;
- _latest_subframes = subframes;
- return true;
- }
-}
-
-
-/** Append a buffer of events to the buffer.
- *
- * \a timestamp must be >= the latest event in the buffer.
- *
- * \return true on success
- */
-bool
-LV2EventBuffer::append(const LV2_Event_Buffer* buf)
-{
- uint8_t** data = NULL;
- bool ret = true;
-
- LV2_Event_Iterator iter;
- for (lv2_event_begin(&iter, _data); 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;
- }
-
- _latest_frames = ev->frames;
- _latest_subframes = ev->subframes;
- }
-
- return ret;
-}
-
-
-/** Clear this buffer and copy @a buf into it.
- * The capacity of this buffer must be >= the capacity of @a buf.
- */
-void
-LV2EventBuffer::copy(const LV2EventBuffer& buf)
-{
- assert(buf._data->header_size == _data->header_size);
- memcpy(_data, buf._data, _data->header_size + buf._data->size);
-
- _iter = buf._iter;
- _iter.buf = _data;
-
- _latest_frames = buf._latest_frames;
- _latest_subframes = buf._latest_subframes;
-}
-
-
-} // namespace Ingen
-