diff options
author | David Robillard <d@drobilla.net> | 2006-08-12 08:20:24 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-08-12 08:20:24 +0000 |
commit | 30ab1fd61569f9d7fb7410d483fa68cbf9865c37 (patch) | |
tree | 60cf9b5228a2728cda6608d517528066253d1a17 /libs/ardour/ardour/buffer_set.h | |
parent | cbdf686e391bc2e7b93f37a5d3fa9197cb178078 (diff) |
Towards MIDI:
- Converted vector<Sample*> to BufferList and numerous counts from int to ChanCount (and related changes)
- Added fancy type-generic iterators to BufferList, PortIterator (see IO::collect_input for a good example of the idea - the same code will work to read all input (of various types in a single IO, eg instruments) without modification no matter how many types we add)
- Fixed comparison operator bugs with ChanCount (screwed up metering among other things)
- Moved peak metering into it's own object, and moved most of the pan related code out of IO to panner (still a touch more to be done here for MIDI playback)
Not directly MIDI related fixes for problems in trunk:
- Fixed varispeed gain/pan automation to work properly (was reading the wrong range of automation data, probably causing nasty clicks?)
- Fixed crash on varispeed looping (possibly only a 64-bit problem). It still doesn't work, but at least it doesn't die
Quite a few things broken, and the new classes are pretty filthy still, but I think the direction is a lot better than all my previous plans...
git-svn-id: svn://localhost/ardour2/branches/midi@795 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/buffer_set.h')
-rw-r--r-- | libs/ardour/ardour/buffer_set.h | 93 |
1 files changed, 69 insertions, 24 deletions
diff --git a/libs/ardour/ardour/buffer_set.h b/libs/ardour/ardour/buffer_set.h index 1799858794..dfb5dd3611 100644 --- a/libs/ardour/ardour/buffer_set.h +++ b/libs/ardour/ardour/buffer_set.h @@ -19,14 +19,17 @@ #ifndef __ardour_buffer_set_h__ #define __ardour_buffer_set_h__ +#include <cassert> #include <vector> -#include <ardour/buffer.h> #include <ardour/chan_count.h> #include <ardour/data_type.h> -#include <ardour/port_set.h> namespace ARDOUR { +class Buffer; +class AudioBuffer; +class PortSet; + /** A set of buffers of various types. * @@ -44,52 +47,91 @@ namespace ARDOUR { class BufferSet { public: - BufferSet(const PortSet& ports); BufferSet(); ~BufferSet(); void clear(); - void ensure_buffers(const ChanCount& chan_count, size_t buffer_capacity); - void ensure_buffers(size_t num_buffers, DataType type, size_t buffer_capacity); + void attach_buffers(PortSet& ports); + + void ensure_buffers(const ChanCount& count, size_t buffer_capacity); + void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity); - // FIXME: add these - //const ChanCount& available() const { return _count; } - //ChanCount& available() { return _count; } + const ChanCount& available() const { return _available; } + ChanCount& available() { return _available; } const ChanCount& count() const { return _count; } ChanCount& count() { return _count; } - size_t available_buffers(DataType type) const; + void set_count(const ChanCount& count) { _count = count; } + size_t buffer_capacity(DataType type) const; - Buffer& buffer(DataType type, size_t i) + Buffer& get(DataType type, size_t i) { assert(i <= _count.get(type)); return *_buffers[type.to_index()][i]; } - AudioBuffer& audio_buffer(size_t i) + AudioBuffer& get_audio(size_t i) + { + return (AudioBuffer&)get(DataType::AUDIO, i); + } + + void read_from(BufferSet& in, jack_nframes_t nframes, jack_nframes_t offset=0) { - return (AudioBuffer&)buffer(DataType::AUDIO, i); + throw; // FIXME: implement this with spiffy DataType iterator etc. } - #if 0 - /** See PortInsert::run for an example of usage */ - class IndexSet { + + // ITERATORS + + // FIXME: this is a filthy copy-and-paste mess + // FIXME: litter these with assertions + + class audio_iterator { public: - IndexSet() { reset(); } - - void reset() { _is[0] = 0; _is[1] = 0; } - size_t index(DataType type) { return _is[type.to_index()]; } - void increment(DataType type) { _is[type.to_index()] += 1; } + AudioBuffer& operator*() { return _set.get_audio(_index); } + AudioBuffer* operator->() { return &_set.get_audio(_index); } + audio_iterator& operator++() { ++_index; return *this; } // yes, prefix only + bool operator==(const audio_iterator& other) { return (_index == other._index); } + bool operator!=(const audio_iterator& other) { return (_index != other._index); } private: - int _is[2]; + friend class BufferSet; + + audio_iterator(BufferSet& list, size_t index) : _set(list), _index(index) {} + + BufferSet& _set; + size_t _index; }; - #endif - - const ChanCount& chan_count() const { return _count; } + + audio_iterator audio_begin() { return audio_iterator(*this, 0); } + audio_iterator audio_end() { return audio_iterator(*this, _count.get(DataType::AUDIO)); } + + class iterator { + public: + + Buffer& operator*() { return _set.get(_type, _index); } + Buffer* operator->() { return &_set.get(_type, _index); } + iterator& operator++() { ++_index; return *this; } // yes, prefix only + bool operator==(const iterator& other) { return (_index == other._index); } + bool operator!=(const iterator& other) { return (_index != other._index); } + + private: + friend class BufferSet; + + iterator(BufferSet& list, DataType type, size_t index) + : _set(list), _type(type), _index(index) {} + + BufferSet& _set; + DataType _type; + size_t _index; + }; + + iterator begin(DataType type) { return iterator(*this, type, 0); } + iterator end(DataType type) { return iterator(*this, type, _count.get(type)); } + private: typedef std::vector<Buffer*> BufferVec; @@ -100,6 +142,9 @@ private: /// Use counts (there may be more actual buffers than this) ChanCount _count; + /// Available counts (number of buffers actually allocated) + ChanCount _available; + /// Whether we (don't) 'own' the contained buffers (are a mirror of a PortSet) bool _is_mirror; }; |