2 Copyright (C) 2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __ardour_buffer_set_h__
20 #define __ardour_buffer_set_h__
24 #include "ardour/chan_count.h"
25 #include "ardour/data_type.h"
26 #include "ardour/types.h"
35 /** A set of buffers of various types.
37 * These are mainly accessed from Session and passed around as scratch buffers
38 * (eg as parameters to run() methods) to do in-place signal processing.
40 * There are two types of counts associated with a BufferSet - available,
41 * and the 'use count'. Available is the actual number of allocated buffers
42 * (and so is the maximum acceptable value for the use counts).
44 * The use counts are how things determine the form of their input and inform
45 * others the form of their output (eg what they did to the BufferSet).
46 * Setting the use counts is realtime safe.
56 void attach_buffers(PortSet& ports, nframes_t nframes, nframes_t offset);
58 void ensure_buffers(const ChanCount& count, size_t buffer_capacity);
59 void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
61 const ChanCount& available() const { return _available; }
62 ChanCount& available() { return _available; }
64 const ChanCount& count() const { return _count; }
65 ChanCount& count() { return _count; }
67 void set_count(const ChanCount& count) { _count = count; }
69 size_t buffer_capacity(DataType type) const;
71 Buffer& get(DataType type, size_t i) {
72 assert(i <= _count.get(type));
73 return *_buffers[type][i];
76 AudioBuffer& get_audio(size_t i) {
77 return (AudioBuffer&)get(DataType::AUDIO, i);
80 MidiBuffer& get_midi(size_t i) {
81 return (MidiBuffer&)get(DataType::MIDI, i);
84 void read_from(BufferSet& in, jack_nframes_t nframes, jack_nframes_t offset=0);
87 // FIXME: possible to combine these? templates?
89 class audio_iterator {
91 AudioBuffer& operator*() { return _set.get_audio(_index); }
92 AudioBuffer* operator->() { return &_set.get_audio(_index); }
93 audio_iterator& operator++() { ++_index; return *this; } // yes, prefix only
94 bool operator==(const audio_iterator& other) { return (_index == other._index); }
95 bool operator!=(const audio_iterator& other) { return (_index != other._index); }
98 friend class BufferSet;
100 audio_iterator(BufferSet& list, size_t index) : _set(list), _index(index) {}
106 audio_iterator audio_begin() { return audio_iterator(*this, 0); }
107 audio_iterator audio_end() { return audio_iterator(*this, _count.n_audio()); }
112 Buffer& operator*() { return _set.get(_type, _index); }
113 Buffer* operator->() { return &_set.get(_type, _index); }
114 iterator& operator++() { ++_index; return *this; } // yes, prefix only
115 bool operator==(const iterator& other) { return (_index == other._index); }
116 bool operator!=(const iterator& other) { return (_index != other._index); }
117 iterator operator=(const iterator& other) {
118 _set = other._set; _type = other._type; _index = other._index; return *this;
122 friend class BufferSet;
124 iterator(BufferSet& list, DataType type, size_t index)
125 : _set(list), _type(type), _index(index) {}
132 iterator begin(DataType type) { return iterator(*this, type, 0); }
133 iterator end(DataType type) { return iterator(*this, type, _count.get(type)); }
136 typedef std::vector<Buffer*> BufferVec;
138 /// Vector of vectors, indexed by DataType
139 std::vector<BufferVec> _buffers;
141 /// Use counts (there may be more actual buffers than this)
144 /// Available counts (number of buffers actually allocated)
145 ChanCount _available;
147 /// Whether we (don't) 'own' the contained buffers (otherwise we mirror a PortSet)
152 } // namespace ARDOUR
154 #endif // __ardour_buffer_set_h__