Ardour  8.12
buffer_set.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2016 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013-2016 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __ardour_buffer_set_h__
23 #define __ardour_buffer_set_h__
24 
25 #ifdef WAF_BUILD
26 #include "libardour-config.h"
27 #endif
28 
29 #include <cassert>
30 #include <vector>
31 #include "ardour/chan_count.h"
32 #include "ardour/data_type.h"
34 #include "ardour/types.h"
35 
36 #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
37 #include "evoral/Event.h"
38 struct _VstEvents;
39 typedef struct _VstEvents VstEvents;
40 struct _VstMidiEvent;
41 typedef struct _VstMidiEvent VstMidiEvent;
42 #endif
43 
44 
45 namespace ARDOUR {
46 
47 class Buffer;
48 class AudioBuffer;
49 class MidiBuffer;
50 class PortSet;
51 
52 struct LV2_Evbuf;
53 
68 {
69 public:
72 
73  void clear();
74 
75  void attach_buffers (PortSet const& ports);
77 
78  /* the capacity here is a size_t and has a different interpretation depending
79  on the DataType of the buffers. for audio, its a sample count. for MIDI
80  its a byte count.
81  */
82 
83  void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
84  void ensure_buffers(const ChanCount& chns, size_t buffer_capacity);
85 
86  /* Returns true if Buffer::silent_data() is true for all buffers */
87  bool silent_data() const;
88 
89  const ChanCount& available() const { return _available; }
90  ChanCount& available() { return _available; }
91 
92  const ChanCount& count() const { return _count; }
93  ChanCount& count() { return _count; }
94 
95  void silence (samplecnt_t nframes, samplecnt_t offset);
96  bool is_mirror() const { return _is_mirror; }
97 
98  void set_count(const ChanCount& count) { assert(count <= _available); _count = count; }
99 
100  size_t buffer_capacity(DataType type) const;
101 
102  AudioBuffer& get_audio(size_t i) {
103  return (AudioBuffer&)get_available (DataType::AUDIO, i);
104  }
105  const AudioBuffer& get_audio(size_t i) const {
106  return (const AudioBuffer&)get_available(DataType::AUDIO, i);
107  }
108 
109  MidiBuffer& get_midi(size_t i) {
110  return (MidiBuffer&)get_available(DataType::MIDI, i);
111  }
112  const MidiBuffer& get_midi(size_t i) const {
113  return (const MidiBuffer&)get_available(DataType::MIDI, i);
114  }
115 
116  Buffer& get_available(DataType type, size_t i);
117  const Buffer& get_available(DataType type, size_t i) const;
118 
124  LV2_Evbuf* get_lv2_midi(bool input, size_t i);
125 
127  void ensure_lv2_bufsize(bool input, size_t i, size_t buffer_capacity);
128 
130  void flush_lv2_midi(bool input, size_t i, pframes_t, samplecnt_t);
131 
133  void forward_lv2_midi(LV2_Evbuf*, size_t, pframes_t, samplecnt_t);
134 
135 #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
137 #endif
138 
139  void read_from(const BufferSet& in, samplecnt_t nframes);
140  void read_from(const BufferSet& in, samplecnt_t nframes, DataType);
141  void merge_from(const BufferSet& in, samplecnt_t nframes);
142 
143  template <typename BS, typename B>
145  public:
147  : _set(other._set), _type(other._type), _index(other._index) {}
148  B& operator*() { return (B&)_set.get_available(_type, _index); }
149  B* operator->() { return &(B&)_set.get_available(_type, _index); }
150  iterator_base<BS,B>& operator++() { ++_index; return *this; } // yes, prefix only
151  bool operator==(const iterator_base<BS,B>& other) { return (_index == other._index); }
152  bool operator!=(const iterator_base<BS,B>& other) { return (_index != other._index); }
154  _set = other._set; _type = other._type; _index = other._index; return *this;
155  }
156 
157  private:
158  friend class BufferSet;
159 
160  iterator_base(BS& list, DataType type, size_t index)
161  : _set(list), _type(type), _index(index) {}
162 
163  BS& _set;
165  size_t _index;
166  };
167 
169  iterator begin(DataType type) { return iterator(*this, type, 0); }
170  iterator end(DataType type) { return iterator(*this, type, _count.get(type)); }
171 
173  const_iterator begin(DataType type) const { return const_iterator(*this, type, 0); }
174  const_iterator end(DataType type) const { return const_iterator(*this, type, _count.get(type)); }
175 
178  audio_iterator audio_end() { return audio_iterator(*this, DataType::AUDIO, _count.n_audio()); }
179 
182  midi_iterator midi_end() { return midi_iterator(*this, DataType::MIDI, _count.n_midi()); }
183 
184 private:
185  typedef std::vector<Buffer*> BufferVec;
186 
188  std::vector<BufferVec> _buffers;
189 
191  typedef std::vector< std::pair<bool, LV2_Evbuf*> > LV2Buffers;
193 
194 #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
195  class VSTBuffer {
196  public:
197  VSTBuffer (size_t);
199 
200  void clear ();
202  VstEvents* events () const {
203  return _events;
204  }
205 
206  private:
207  /* prevent copy construction */
208  VSTBuffer (VSTBuffer const &);
209 
212  size_t _capacity;
213  };
214 
215  typedef std::vector<VSTBuffer*> VSTBuffers;
217 #endif
218 
221 
224 
227 };
228 
229 
230 } // namespace ARDOUR
231 
232 #endif // __ardour_buffer_set_h__
VstMidiEvent * _midi_events
the parent VSTEvents struct
Definition: buffer_set.h:211
void push_back(Evoral::Event< samplepos_t > const &)
VSTBuffer(VSTBuffer const &)
VstEvents * events() const
Definition: buffer_set.h:202
iterator_base< BS, B > operator=(const iterator_base< BS, B > &other)
Definition: buffer_set.h:153
bool operator==(const iterator_base< BS, B > &other)
Definition: buffer_set.h:151
iterator_base(const iterator_base &other)
Definition: buffer_set.h:146
iterator_base(BS &list, DataType type, size_t index)
Definition: buffer_set.h:160
bool operator!=(const iterator_base< BS, B > &other)
Definition: buffer_set.h:152
iterator_base< BS, B > & operator++()
Definition: buffer_set.h:150
void ensure_buffers(const ChanCount &chns, size_t buffer_capacity)
void silence(samplecnt_t nframes, samplecnt_t offset)
ChanCount & count()
Definition: buffer_set.h:93
audio_iterator audio_begin()
Definition: buffer_set.h:177
midi_iterator midi_begin()
Definition: buffer_set.h:181
void forward_lv2_midi(LV2_Evbuf *, size_t, pframes_t, samplecnt_t)
iterator_base< BufferSet, Buffer > iterator
Definition: buffer_set.h:168
LV2Buffers _lv2_buffers
Definition: buffer_set.h:192
void get_backend_port_addresses(PortSet &, samplecnt_t)
std::vector< Buffer * > BufferVec
Definition: buffer_set.h:185
VstEvents * get_vst_midi(size_t)
void attach_buffers(PortSet const &ports)
AudioBuffer & get_audio(size_t i)
Definition: buffer_set.h:102
LV2_Evbuf * get_lv2_midi(bool input, size_t i)
bool is_mirror() const
Definition: buffer_set.h:96
void flush_lv2_midi(bool input, size_t i, pframes_t, samplecnt_t)
const MidiBuffer & get_midi(size_t i) const
Definition: buffer_set.h:112
const_iterator begin(DataType type) const
Definition: buffer_set.h:173
const AudioBuffer & get_audio(size_t i) const
Definition: buffer_set.h:105
iterator begin(DataType type)
Definition: buffer_set.h:169
const ChanCount & available() const
Definition: buffer_set.h:89
std::vector< VSTBuffer * > VSTBuffers
Definition: buffer_set.h:215
void ensure_lv2_bufsize(bool input, size_t i, size_t buffer_capacity)
ChanCount & available()
Definition: buffer_set.h:90
midi_iterator midi_end()
Definition: buffer_set.h:182
bool _is_mirror
False if we 'own' the contained buffers, if true we mirror a PortSet)
Definition: buffer_set.h:226
const Buffer & get_available(DataType type, size_t i) const
void read_from(const BufferSet &in, samplecnt_t nframes)
iterator_base< const BufferSet, const Buffer > const_iterator
Definition: buffer_set.h:172
std::vector< BufferVec > _buffers
Vector of vectors, indexed by DataType.
Definition: buffer_set.h:188
void merge_from(const BufferSet &in, samplecnt_t nframes)
std::vector< std::pair< bool, LV2_Evbuf * > > LV2Buffers
LV2 MIDI buffers (for conversion to/from MIDI buffers)
Definition: buffer_set.h:191
audio_iterator audio_end()
Definition: buffer_set.h:178
size_t buffer_capacity(DataType type) const
iterator_base< BufferSet, AudioBuffer > audio_iterator
Definition: buffer_set.h:176
void read_from(const BufferSet &in, samplecnt_t nframes, DataType)
Buffer & get_available(DataType type, size_t i)
MidiBuffer & get_midi(size_t i)
Definition: buffer_set.h:109
iterator end(DataType type)
Definition: buffer_set.h:170
ChanCount _available
Available counts (number of buffers actually allocated)
Definition: buffer_set.h:223
bool silent_data() const
VSTBuffers _vst_buffers
Definition: buffer_set.h:216
void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity)
iterator_base< BufferSet, MidiBuffer > midi_iterator
Definition: buffer_set.h:180
ChanCount _count
Use counts (there may be more actual buffers than this)
Definition: buffer_set.h:220
const ChanCount & count() const
Definition: buffer_set.h:92
void set_count(const ChanCount &count)
Definition: buffer_set.h:98
const_iterator end(DataType type) const
Definition: buffer_set.h:174
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t