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__
23 #include <ardour/buffer.h>
24 #include <ardour/chan_count.h>
25 #include <ardour/data_type.h>
26 #include <ardour/port_set.h>
31 /** A set of buffers of various types.
33 * These are mainly accessed from Session and passed around as scratch buffers
34 * (eg as parameters to run() methods) to do in-place signal processing.
36 * There are two types of counts associated with a BufferSet - available,
37 * and the 'use count'. Available is the actual number of allocated buffers
38 * (and so is the maximum acceptable value for the use counts).
40 * The use counts are how things determine the form of their input and inform
41 * others the form of their output (eg what they did to the BufferSet).
42 * Setting the use counts is realtime safe.
47 BufferSet(const PortSet& ports);
53 void ensure_buffers(const ChanCount& chan_count, size_t buffer_capacity);
54 void ensure_buffers(size_t num_buffers, DataType type, size_t buffer_capacity);
57 //const ChanCount& available() const { return _count; }
58 //ChanCount& available() { return _count; }
60 const ChanCount& count() const { return _count; }
61 ChanCount& count() { return _count; }
63 size_t available_buffers(DataType type) const;
64 size_t buffer_capacity(DataType type) const;
66 Buffer& buffer(DataType type, size_t i)
68 assert(i <= _count.get(type));
69 return *_buffers[type.to_index()][i];
72 AudioBuffer& audio_buffer(size_t i)
74 return (AudioBuffer&)buffer(DataType::AUDIO, i);
77 /** See PortInsert::run for an example of usage */
80 IndexSet() { reset(); }
82 void reset() { _is[0] = 0; _is[1] = 0; }
84 size_t index(DataType type) { return _is[type.to_index()]; }
85 void increment(DataType type) { _is[type.to_index()] += 1; }
92 const ChanCount& chan_count() const { return _count; }
95 typedef std::vector<Buffer*> BufferVec;
97 /// Vector of vectors, indexed by DataType::to_index()
98 std::vector<BufferVec> _buffers;
100 /// Use counts (there may be more actual buffers than this)
103 /// Whether we (don't) 'own' the contained buffers (are a mirror of a PortSet)
108 } // namespace ARDOUR
110 #endif // __ardour_buffer_set_h__