summaryrefslogtreecommitdiffstats
path: root/src/engine/AudioBuffer.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-11-18 01:20:52 +0000
committerDavid Robillard <d@drobilla.net>2009-11-18 01:20:52 +0000
commit58807f5840592959c31b415f7e2d64967594b5ee (patch)
tree6f666a1051f96b243c21a8195c549cd68d4d8f85 /src/engine/AudioBuffer.cpp
parent0487fd4a549d9eb9b04dbd19eecb1e3101311034 (diff)
downloadingen-58807f5840592959c31b415f7e2d64967594b5ee.tar.gz
ingen-58807f5840592959c31b415f7e2d64967594b5ee.tar.bz2
ingen-58807f5840592959c31b415f7e2d64967594b5ee.zip
Less reliance on Buffer::type() (which doesn't really make sense, since buffer type != port type...).
AudioBuffer copy improvements. Remove redundant AudioBuffer::_port_type (same as Buffer::_type). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2275 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/AudioBuffer.cpp')
-rw-r--r--src/engine/AudioBuffer.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/engine/AudioBuffer.cpp b/src/engine/AudioBuffer.cpp
index fbca1e7b..633a004b 100644
--- a/src/engine/AudioBuffer.cpp
+++ b/src/engine/AudioBuffer.cpp
@@ -39,7 +39,6 @@ using namespace Shared;
AudioBuffer::AudioBuffer(Shared::PortType type, size_t size)
: ObjectBuffer(size + sizeof(LV2_Object)
+ (type == PortType::AUDIO ? sizeof(LV2_Vector_Body) : 0))
- , _port_type(type)
, _state(OK)
, _set_value(0)
, _set_time(0)
@@ -75,7 +74,7 @@ AudioBuffer::AudioBuffer(Shared::PortType type, size_t size)
void
AudioBuffer::resize(size_t size)
{
- if (_port_type == PortType::AUDIO) {
+ if (_type == PortType::AUDIO) {
ObjectBuffer::resize(size + sizeof(LV2_Vector_Body));
vector()->elem_count = size / sizeof(Sample);
}
@@ -103,7 +102,7 @@ AudioBuffer::clear()
void
AudioBuffer::set_value(Sample val, FrameTime cycle_start, FrameTime time)
{
- if (_port_type == PortType::CONTROL)
+ if (is_control())
time = cycle_start;
const FrameTime offset = time - cycle_start;
@@ -163,10 +162,19 @@ AudioBuffer::copy(const Sample* src, size_t start_sample, size_t end_sample)
void
AudioBuffer::copy(Context& context, const Buffer* src)
{
- if (_type == src->type()) {
+ const AudioBuffer* src_abuf = dynamic_cast<const AudioBuffer*>(src);
+ if (!src_abuf) {
+ clear();
+ return;
+ }
+
+ // Control => Control or Audio => Audio
+ if (src_abuf->is_control() == is_control()) {
ObjectBuffer::copy(context, src);
- } else if (_type == PortType::AUDIO && src->type() == PortType::CONTROL) {
- set_block(((AudioBuffer*)src)->data()[0], 0, nframes());
+
+ // Control => Audio or Audio => Control
+ } else {
+ set_block(src_abuf->data()[0], 0, nframes());
}
}
@@ -179,11 +187,10 @@ AudioBuffer::copy(Context& context, const Buffer* src)
void
AudioBuffer::mix(Context& context, const Buffer* const src)
{
- if (src->type() != PortType::CONTROL && src->type() != PortType::AUDIO)
+ const AudioBuffer* src_abuf = dynamic_cast<const AudioBuffer*>(src);
+ if (!src_abuf)
return;
- AudioBuffer* src_abuf = (AudioBuffer*)src;
-
Sample* const buf = data();
const Sample* const src_buf = src_abuf->data();