remove cruft - unused _size in audio-buffers
[ardour.git] / libs / ardour / ardour / buffer.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_h__
20 #define __ardour_buffer_h__
21
22 #include <stddef.h>
23
24 #include <boost/utility.hpp>
25
26 #include "ardour/types.h"
27 #include "ardour/data_type.h"
28
29 namespace ARDOUR {
30
31
32 /** A buffer of recordable/playable data.
33  *
34  * This is a datatype-agnostic base class for all buffers (there are no
35  * methods to actually access the data).  This provides a way for code that
36  * doesn't care about the data type to still deal with buffers (which is
37  * why the base class can't be a template).
38  *
39  * To actually read/write buffer contents, use the appropriate derived class.
40  */
41 class Buffer : public boost::noncopyable
42 {
43 public:
44         virtual ~Buffer() {}
45
46         /** Factory function */
47         static Buffer* create(DataType type, size_t capacity);
48
49         /** Maximum capacity of buffer. */
50         size_t capacity() const { return _capacity; }
51
52         /** Type of this buffer.
53          * Based on this you can static cast a Buffer* to the desired type. */
54         DataType type() const { return _type; }
55
56         bool silent() const { return _silent; }
57
58         /** Reallocate the buffer used internally to handle at least @a size_t units of data.
59          *
60          * The buffer is not silent after this operation. the @a capacity argument
61          * passed to the constructor must have been non-zero.
62          */
63         virtual void resize (size_t) = 0;
64
65         /** Clear (eg zero, or empty) buffer */
66         virtual void silence (framecnt_t len, framecnt_t offset = 0) = 0;
67
68         /** Clear the entire buffer */
69         virtual void clear() { silence(_capacity, 0); }
70
71         virtual void read_from (const Buffer& src, framecnt_t len, framecnt_t dst_offset = 0, framecnt_t src_offset = 0) = 0;
72         virtual void merge_from (const Buffer& src, framecnt_t len, framecnt_t dst_offset = 0, framecnt_t src_offset = 0) = 0;
73
74   protected:
75         Buffer(DataType type)
76                 : _type(type), _capacity(0), _silent (true)
77         {}
78
79         DataType  _type;
80         pframes_t _capacity;
81         bool      _silent;
82 };
83
84
85 } // namespace ARDOUR
86
87 #endif // __ardour_buffer_h__