diff options
author | David Robillard <d@drobilla.net> | 2012-07-31 15:12:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-07-31 15:12:38 +0000 |
commit | 8d559e4991a491b612e63d5a4deff0ab48a3d3dd (patch) | |
tree | 06da8b1d71f8068f12bc3f476b90734b67d9120c /src/server/Buffer.hpp | |
parent | a41af6e41d60f8724809486b94ce1e6281c3bc31 (diff) | |
download | ingen-8d559e4991a491b612e63d5a4deff0ab48a3d3dd.tar.gz ingen-8d559e4991a491b612e63d5a4deff0ab48a3d3dd.tar.bz2 ingen-8d559e4991a491b612e63d5a4deff0ab48a3d3dd.zip |
Merge AudioBuffer into Buffer and avoid all the casting.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4584 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server/Buffer.hpp')
-rw-r--r-- | src/server/Buffer.hpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index 84eaf516..d9c9b36f 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -43,9 +43,14 @@ class Buffer : public boost::noncopyable, public Raul::Deletable public: Buffer(BufferFactory& bufs, LV2_URID type, uint32_t capacity); + bool is_audio() const; + bool is_control() const; + bool is_sequence() const; + virtual void clear(); virtual void resize(uint32_t size); virtual void copy(Context& context, const Buffer* src); + virtual void set_block(Sample val, size_t start_offset, size_t end_offset); virtual void prepare_write(Context& context); void* port_data(PortType port_type, SampleCount offset); @@ -54,6 +59,35 @@ public: LV2_URID type() const { return _type; } uint32_t capacity() const { return _capacity; } + /// Audio buffers only + inline Sample* samples() const { + if (is_control()) { + return (Sample*)LV2_ATOM_BODY(atom()); + } else if (is_audio()) { + return (Sample*)LV2_ATOM_CONTENTS(LV2_Atom_Vector, atom()); + } + return NULL; + } + + /// Audio buffers only + inline SampleCount nframes() const { + if (is_control()) { + return 1; + } else if (is_audio()) { + return (_capacity - sizeof(LV2_Atom_Vector)) / sizeof(Sample); + } + return 0; + } + + /// Audio buffers only + inline Sample& value_at(size_t offset) const { + assert(offset < nframes()); + return samples()[offset]; + } + + /// Audio buffers only + float peak(const Context& context) const; + /// Sequence buffers only void prepare_output_write(Context& context); |