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 "libardour-config.h"
28 #include "ardour/chan_count.h"
29 #include "ardour/data_type.h"
30 #include "ardour/types.h"
33 #include "evoral/MIDIEvent.hpp"
48 /** A set of buffers of various types.
50 * These are mainly accessed from Session and passed around as scratch buffers
51 * (eg as parameters to run() methods) to do in-place signal processing.
53 * There are two types of counts associated with a BufferSet - available,
54 * and the 'use count'. Available is the actual number of allocated buffers
55 * (and so is the maximum acceptable value for the use counts).
57 * The use counts are how things determine the form of their input and inform
58 * others the form of their output (eg what they did to the BufferSet).
59 * Setting the use counts is realtime safe.
69 void attach_buffers (PortSet& ports);
70 void get_jack_port_addresses (PortSet &, framecnt_t);
72 /* the capacity here is a size_t and has a different interpretation depending
73 on the DataType of the buffers. for audio, its a frame count. for MIDI
77 void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
78 void ensure_buffers(const ChanCount& chns, size_t buffer_capacity);
80 const ChanCount& available() const { return _available; }
81 ChanCount& available() { return _available; }
83 const ChanCount& count() const { return _count; }
84 ChanCount& count() { return _count; }
86 void is_silent(bool yn);
87 void silence (framecnt_t nframes, framecnt_t offset);
88 bool is_mirror() const { return _is_mirror; }
90 void set_count(const ChanCount& count) { assert(count <= _available); _count = count; }
92 size_t buffer_capacity(DataType type) const;
94 Buffer& get(DataType type, size_t i);
95 const Buffer& get(DataType type, size_t i) const;
97 AudioBuffer& get_audio(size_t i) {
98 return (AudioBuffer&)get(DataType::AUDIO, i);
100 const AudioBuffer& get_audio(size_t i) const {
101 return (const AudioBuffer&)get(DataType::AUDIO, i);
104 MidiBuffer& get_midi(size_t i) {
105 return (MidiBuffer&)get(DataType::MIDI, i);
107 const MidiBuffer& get_midi(size_t i) const {
108 return (const MidiBuffer&)get(DataType::MIDI, i);
112 /** Get a MIDI buffer translated into an LV2 MIDI buffer for use with plugins.
113 * The index here corresponds directly to MIDI buffer numbers (i.e. the index
114 * passed to get_midi), translation back and forth will happen as needed */
115 LV2EventBuffer& get_lv2_midi(bool input, size_t i);
117 /** Flush modified LV2 event output buffers back to Ardour buffers */
118 void flush_lv2_midi(bool input, size_t i);
122 VstEvents* get_vst_midi (size_t);
125 void read_from(const BufferSet& in, framecnt_t nframes);
126 void merge_from(const BufferSet& in, framecnt_t nframes);
128 template <typename BS, typename B>
129 class iterator_base {
131 B& operator*() { return (B&)_set.get(_type, _index); }
132 B* operator->() { return &(B&)_set.get(_type, _index); }
133 iterator_base<BS,B>& operator++() { ++_index; return *this; } // yes, prefix only
134 bool operator==(const iterator_base<BS,B>& other) { return (_index == other._index); }
135 bool operator!=(const iterator_base<BS,B>& other) { return (_index != other._index); }
136 iterator_base<BS,B> operator=(const iterator_base<BS,B>& other) {
137 _set = other._set; _type = other._type; _index = other._index; return *this;
141 friend class BufferSet;
143 iterator_base(BS& list, DataType type, size_t index)
144 : _set(list), _type(type), _index(index) {}
151 typedef iterator_base<BufferSet, Buffer> iterator;
152 iterator begin(DataType type) { return iterator(*this, type, 0); }
153 iterator end(DataType type) { return iterator(*this, type, _count.get(type)); }
155 typedef iterator_base<const BufferSet, const Buffer> const_iterator;
156 const_iterator begin(DataType type) const { return const_iterator(*this, type, 0); }
157 const_iterator end(DataType type) const { return const_iterator(*this, type, _count.get(type)); }
159 typedef iterator_base<BufferSet, AudioBuffer> audio_iterator;
160 audio_iterator audio_begin() { return audio_iterator(*this, DataType::AUDIO, 0); }
161 audio_iterator audio_end() { return audio_iterator(*this, DataType::AUDIO, _count.n_audio()); }
163 typedef iterator_base<BufferSet, MidiBuffer> midi_iterator;
164 midi_iterator midi_begin() { return midi_iterator(*this, DataType::MIDI, 0); }
165 midi_iterator midi_end() { return midi_iterator(*this, DataType::MIDI, _count.n_midi()); }
168 typedef std::vector<Buffer*> BufferVec;
170 /// Vector of vectors, indexed by DataType
171 std::vector<BufferVec> _buffers;
174 /// LV2 MIDI buffers (for conversion to/from MIDI buffers)
175 typedef std::vector< std::pair<bool, LV2EventBuffer*> > LV2Buffers;
176 LV2Buffers _lv2_buffers;
186 void push_back (Evoral::MIDIEvent<framepos_t> const &);
187 VstEvents* events () const {
192 /* prevent copy construction */
193 VSTBuffer (VSTBuffer const &);
195 VstEvents* _events; /// the parent VSTEvents struct
196 VstMidiEvent* _midi_events; ///< storage area for VSTMidiEvents
200 typedef std::vector<VSTBuffer*> VSTBuffers;
201 VSTBuffers _vst_buffers;
204 /// Use counts (there may be more actual buffers than this)
207 /// Available counts (number of buffers actually allocated)
208 ChanCount _available;
210 /// False if we 'own' the contained buffers, if true we mirror a PortSet)
215 } // namespace ARDOUR
217 #endif // __ardour_buffer_set_h__