diff options
author | David Robillard <d@drobilla.net> | 2006-08-11 03:24:57 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-08-11 03:24:57 +0000 |
commit | 30c08ba655330232767554c48bda1975bfb5628c (patch) | |
tree | c6bf6b62de69afdd6b2a42ef3a7d9f80e0f65f7c /libs/ardour/ardour/buffer.h | |
parent | ab6f1ed9bafa869648b6e94ee5186ff317b32c3e (diff) |
- Changed IO's vector<Port*>'s to PortList
- Added new Port classes, code to drive them
- Added PortList, which is a filthy mess ATM (nevermind that, it's the interface that's important at this stage)
- Added ChanCount, though it isn't very thoroughly used yet. That's the next step....
- Fixed a few bugs relating to loading sessions saved with trunk
- Fixed a few random other bugs
Slowly working towards type agnosticism while keeping all the former code/logic intact is the name of the game here
Warning: Removing ports is currently (intentionally) broken due solely to laziness.
git-svn-id: svn://localhost/ardour2/branches/midi@786 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/buffer.h')
-rw-r--r-- | libs/ardour/ardour/buffer.h | 103 |
1 files changed, 66 insertions, 37 deletions
diff --git a/libs/ardour/ardour/buffer.h b/libs/ardour/ardour/buffer.h index 1321f6c107..981d941de7 100644 --- a/libs/ardour/ardour/buffer.h +++ b/libs/ardour/ardour/buffer.h @@ -19,19 +19,15 @@ #ifndef __ardour_buffer_h__ #define __ardour_buffer_h__ -#define _XOPEN_SOURCE 600 -#include <cstdlib> // for posix_memalign +#include <cstdlib> #include <cassert> +#include <iostream> #include <ardour/types.h> #include <ardour/data_type.h> namespace ARDOUR { -/* Yes, this is a bit of a mess right now. I'll clean it up when everything - * using it works out.. */ - - /** A buffer of recordable/playable data. * * This is a datatype-agnostic base class for all buffers (there are no @@ -44,12 +40,11 @@ namespace ARDOUR { class Buffer { public: - Buffer(DataType type, size_t capacity) - : _type(type), _capacity(capacity), _size(0) - {} - virtual ~Buffer() {} + /** Factory function */ + static Buffer* create(DataType type, size_t capacity); + /** Maximum capacity of buffer. * Note in some cases the entire buffer may not contain valid data, use size. */ size_t capacity() const { return _capacity; } @@ -61,10 +56,24 @@ public: * Based on this you can static cast a Buffer* to the desired type. */ DataType type() const { return _type; } + /** Clear (eg zero, or empty) buffer starting at TIME @a offset */ + virtual void clear(jack_nframes_t offset = 0) = 0; + + virtual void write(const Buffer& src, jack_nframes_t offset, jack_nframes_t len) = 0; + protected: + Buffer(DataType type, size_t capacity) + : _type(type), _capacity(capacity), _size(0) + {} + DataType _type; size_t _capacity; size_t _size; + +private: + // Prevent copies (undefined) + Buffer(const Buffer& copy); + void operator=(const Buffer& other); }; @@ -75,28 +84,51 @@ protected: class AudioBuffer : public Buffer { public: - AudioBuffer(size_t capacity) - : Buffer(DataType::AUDIO, capacity) - , _data(NULL) + AudioBuffer(size_t capacity); + + ~AudioBuffer(); + + void clear(jack_nframes_t offset=0) { memset(_data + offset, 0, sizeof (Sample) * _capacity); } + + /** Copy @a len frames starting at @a offset, from the start of @a src */ + void write(const Buffer& src, jack_nframes_t offset, jack_nframes_t len) + { + assert(src.type() == _type == DataType::AUDIO); + assert(offset + len <= _capacity); + memcpy(_data + offset, ((AudioBuffer&)src).data(len, offset), sizeof(Sample) * len); + } + + /** Copy @a len frames starting at @a offset, from the start of @a src */ + void write(const Sample* src, jack_nframes_t offset, jack_nframes_t len) + { + assert(offset + len <= _capacity); + memcpy(_data + offset, src, sizeof(Sample) * len); + } + + /** Set the data contained by this buffer manually (for setting directly to jack buffer). + * + * Constructor MUST have been passed capacity=0 or this will die (to prevent mem leaks). + */ + void set_data(Sample* data, size_t size) { - _size = capacity; // For audio buffers, size = capacity (always) -#ifdef NO_POSIX_MEMALIGN - _data = (Sample *) malloc(sizeof(Sample) * capacity); -#else - posix_memalign((void**)_data, 16, sizeof(Sample) * capacity); -#endif - assert(_data); - memset(_data, 0, sizeof(Sample) * capacity); + assert(!_owns_data); // prevent leaks + _capacity = size; + _size = size; + _data = data; } - const Sample* data() const { return _data; } - Sample* data() { return _data; } + const Sample* data(jack_nframes_t nframes, jack_nframes_t offset=0) const + { assert(offset + nframes <= _capacity); return _data + offset; } + + Sample* data(jack_nframes_t nframes, jack_nframes_t offset=0) + { assert(offset + nframes <= _capacity); return _data + offset; } private: // These are undefined (prevent copies) AudioBuffer(const AudioBuffer& copy); AudioBuffer& operator=(const AudioBuffer& copy); + bool _owns_data; Sample* _data; ///< Actual buffer contents }; @@ -106,19 +138,16 @@ private: class MidiBuffer : public Buffer { public: - MidiBuffer(size_t capacity) - : Buffer(DataType::MIDI, capacity) - , _data(NULL) - { - _size = capacity; // For audio buffers, size = capacity (always) -#ifdef NO_POSIX_MEMALIGN - _data = (RawMidi *) malloc(sizeof(RawMidi) * capacity); -#else - posix_memalign((void**)_data, 16, sizeof(RawMidi) * capacity); -#endif - assert(_data); - memset(_data, 0, sizeof(RawMidi) * capacity); - } + MidiBuffer(size_t capacity); + + ~MidiBuffer(); + + // FIXME: clear events starting at offset + void clear(jack_nframes_t offset=0) { assert(offset == 0); _size = 0; } + + void write(const Buffer& src, jack_nframes_t offset, jack_nframes_t nframes); + + void set_size(size_t size) { _size = size; } const RawMidi* data() const { return _data; } RawMidi* data() { return _data; } @@ -128,10 +157,10 @@ private: MidiBuffer(const MidiBuffer& copy); MidiBuffer& operator=(const MidiBuffer& copy); + bool _owns_data; RawMidi* _data; ///< Actual buffer contents }; - } // namespace ARDOUR #endif // __ardour_buffer_h__ |