- Replaced integer port counts (and input/output maximum/minimum) with ChanCount...
[ardour.git] / libs / ardour / ardour / buffer_set.h
1 /*
2     Copyright (C) 2006 Paul Davis 
3     
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)
7     any later version.
8     
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
12     for more details.
13     
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.
17 */
18
19 #ifndef __ardour_buffer_set_h__
20 #define __ardour_buffer_set_h__
21
22 #include <vector>
23 #include <ardour/buffer.h>
24 #include <ardour/chan_count.h>
25 #include <ardour/data_type.h>
26 #include <ardour/port_set.h>
27
28 namespace ARDOUR {
29
30
31 /** A set of buffers of various types.
32  *
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.
35  *
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).
39  *
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.
43  */
44 class BufferSet
45 {
46 public:
47         BufferSet(const PortSet& ports);
48         BufferSet();
49         ~BufferSet();
50
51         void clear();
52         
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);
55
56         // FIXME: add these
57         //const ChanCount& available() const { return _count; }
58         //ChanCount&       available()       { return _count; }
59
60         const ChanCount& count() const { return _count; }
61         ChanCount&       count()       { return _count; }
62
63         size_t available_buffers(DataType type) const;
64         size_t buffer_capacity(DataType type) const;
65
66         Buffer& buffer(DataType type, size_t i)
67         {
68                 assert(i <= _count.get(type));
69                 return *_buffers[type.to_index()][i];
70         }
71
72         AudioBuffer& audio_buffer(size_t i)
73         {
74                 return (AudioBuffer&)buffer(DataType::AUDIO, i);
75         }
76         #if 0
77         /** See PortInsert::run for an example of usage */
78         class IndexSet {
79         public:
80                 IndexSet() { reset(); }
81                 
82                 void reset() { _is[0] = 0; _is[1] = 0; }
83
84                 size_t index(DataType type)     { return _is[type.to_index()]; }
85                 void   increment(DataType type) { _is[type.to_index()] += 1; }
86
87         private:
88                 int _is[2];
89         };
90         #endif
91         
92         const ChanCount& chan_count() const { return _count; }
93         
94 private:
95         typedef std::vector<Buffer*> BufferVec;
96
97         /// Vector of vectors, indexed by DataType::to_index()
98         std::vector<BufferVec> _buffers;
99
100         /// Use counts (there may be more actual buffers than this)
101         ChanCount _count;
102
103         /// Whether we (don't) 'own' the contained buffers (are a mirror of a PortSet)
104         bool _is_mirror;
105 };
106
107
108 } // namespace ARDOUR
109
110 #endif // __ardour_buffer_set_h__