From 8d559e4991a491b612e63d5a4deff0ab48a3d3dd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 31 Jul 2012 15:12:38 +0000 Subject: 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 --- src/server/Buffer.hpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/server/Buffer.hpp') 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); -- cgit v1.2.1