Ardour  9.0-pre0-350-gf17a656217
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 #pragma once
23 
24 #ifdef WAF_BUILD
25 #include "libardour-config.h"
26 #endif
27 
28 #include <cassert>
29 #include <vector>
30 #include "ardour/chan_count.h"
31 #include "ardour/data_type.h"
33 #include "ardour/types.h"
34 
35 #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
36 #include "evoral/Event.h"
37 struct _VstEvents;
38 typedef struct _VstEvents VstEvents;
39 struct _VstMidiEvent;
40 typedef struct _VstMidiEvent VstMidiEvent;
41 #endif
42 
43 
44 namespace ARDOUR {
45 
46 class Buffer;
47 class AudioBuffer;
48 class MidiBuffer;
49 class PortSet;
50 
51 struct LV2_Evbuf;
52 
67 {
68 public:
71 
72  void clear();
73 
74  void attach_buffers (PortSet const& ports);
76 
77  /* the capacity here is a size_t and has a different interpretation depending
78  on the DataType of the buffers. for audio, its a sample count. for MIDI
79  its a byte count.
80  */
81 
82  void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
83  void ensure_buffers(const ChanCount& chns, size_t buffer_capacity);
84 
85  /* Returns true if Buffer::silent_data() is true for all buffers */
86  bool silent_data() const;
87 
88  const ChanCount& available() const { return _available; }
89  ChanCount& available() { return _available; }
90 
91  const ChanCount& count() const { return _count; }
92  ChanCount& count() { return _count; }
93 
94  void silence (samplecnt_t nframes, samplecnt_t offset);
95  bool is_mirror() const { return _is_mirror; }
96 
97  void set_count(const ChanCount& count) { assert(count <= _available); _count = count; }
98 
99  size_t buffer_capacity(DataType type) const;
100 
101  AudioBuffer& get_audio(size_t i) {
102  return (AudioBuffer&)get_available (DataType::AUDIO, i);
103  }
104  const AudioBuffer& get_audio(size_t i) const {
105  return (const AudioBuffer&)get_available(DataType::AUDIO, i);
106  }
107 
108  MidiBuffer& get_midi(size_t i) {
109  return (MidiBuffer&)get_available(DataType::MIDI, i);
110  }
111  const MidiBuffer& get_midi(size_t i) const {
112  return (const MidiBuffer&)get_available(DataType::MIDI, i);
113  }
114 
115  Buffer& get_available(DataType type, size_t i);
116  const Buffer& get_available(DataType type, size_t i) const;
117 
123  LV2_Evbuf* get_lv2_midi(bool input, size_t i);
124 
126  void ensure_lv2_bufsize(bool input, size_t i, size_t buffer_capacity);
127 
129  void flush_lv2_midi(bool input, size_t i, pframes_t, samplecnt_t);
130 
132  void forward_lv2_midi(LV2_Evbuf*, size_t, pframes_t, samplecnt_t);
133 
134 #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
136 #endif
137 
138  void read_from(const BufferSet& in, samplecnt_t nframes);
139  void read_from(const BufferSet& in, samplecnt_t nframes, DataType);
140  void merge_from(const BufferSet& in, samplecnt_t nframes);
141 
142  template <typename BS, typename B>
144  public:
146  : _set(other._set), _type(other._type), _index(other._index) {}
147  B& operator*() { return (B&)_set.get_available(_type, _index); }
148  B* operator->() { return &(B&)_set.get_available(_type, _index); }
149  iterator_base<BS,B>& operator++() { ++_index; return *this; } // yes, prefix only
150  bool operator==(const iterator_base<BS,B>& other) { return (_index == other._index); }
151  bool operator!=(const iterator_base<BS,B>& other) { return (_index != other._index); }
153  _set = other._set; _type = other._type; _index = other._index; return *this;
154  }
155 
156  private:
157  friend class BufferSet;
158 
159  iterator_base(BS& list, DataType type, size_t index)
160  : _set(list), _type(type), _index(index) {}
161 
162  BS& _set;
164  size_t _index;
165  };
166 
168  iterator begin(DataType type) { return iterator(*this, type, 0); }
169  iterator end(DataType type) { return iterator(*this, type, _count.get(type)); }
170 
172  const_iterator begin(DataType type) const { return const_iterator(*this, type, 0); }
173  const_iterator end(DataType type) const { return const_iterator(*this, type, _count.get(type)); }
174 
177  audio_iterator audio_end() { return audio_iterator(*this, DataType::AUDIO, _count.n_audio()); }
178 
181  midi_iterator midi_end() { return midi_iterator(*this, DataType::MIDI, _count.n_midi()); }
182 
183 private:
184  typedef std::vector<Buffer*> BufferVec;
185 
187  std::vector<BufferVec> _buffers;
188 
190  typedef std::vector< std::pair<bool, LV2_Evbuf*> > LV2Buffers;
192 
193 #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
194  class VSTBuffer {
195  public:
196  VSTBuffer (size_t);
198 
199  void clear ();
201  VstEvents* events () const {
202  return _events;
203  }
204 
205  private:
206  /* prevent copy construction */
207  VSTBuffer (VSTBuffer const &);
208 
211  size_t _capacity;
212  };
213 
214  typedef std::vector<VSTBuffer*> VSTBuffers;
216 #endif
217 
220 
223 
226 };
227 
228 
229 } // namespace ARDOUR
230 
VstMidiEvent * _midi_events
the parent VSTEvents struct
Definition: buffer_set.h:210
void push_back(Evoral::Event< samplepos_t > const &)
VSTBuffer(VSTBuffer const &)
VstEvents * events() const
Definition: buffer_set.h:201
iterator_base< BS, B > operator=(const iterator_base< BS, B > &other)
Definition: buffer_set.h:152
bool operator==(const iterator_base< BS, B > &other)
Definition: buffer_set.h:150
iterator_base(const iterator_base &other)
Definition: buffer_set.h:145
iterator_base(BS &list, DataType type, size_t index)
Definition: buffer_set.h:159
bool operator!=(const iterator_base< BS, B > &other)
Definition: buffer_set.h:151
iterator_base< BS, B > & operator++()
Definition: buffer_set.h:149
void ensure_buffers(const ChanCount &chns, size_t buffer_capacity)
void silence(samplecnt_t nframes, samplecnt_t offset)
ChanCount & count()
Definition: buffer_set.h:92
audio_iterator audio_begin()
Definition: buffer_set.h:176
midi_iterator midi_begin()
Definition: buffer_set.h:180
void forward_lv2_midi(LV2_Evbuf *, size_t, pframes_t, samplecnt_t)
iterator_base< BufferSet, Buffer > iterator
Definition: buffer_set.h:167
LV2Buffers _lv2_buffers
Definition: buffer_set.h:191
void get_backend_port_addresses(PortSet &, samplecnt_t)
std::vector< Buffer * > BufferVec
Definition: buffer_set.h:184
VstEvents * get_vst_midi(size_t)
void attach_buffers(PortSet const &ports)
AudioBuffer & get_audio(size_t i)
Definition: buffer_set.h:101
LV2_Evbuf * get_lv2_midi(bool input, size_t i)
bool is_mirror() const
Definition: buffer_set.h:95
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:111
const_iterator begin(DataType type) const
Definition: buffer_set.h:172
const AudioBuffer & get_audio(size_t i) const
Definition: buffer_set.h:104
iterator begin(DataType type)
Definition: buffer_set.h:168
const ChanCount & available() const
Definition: buffer_set.h:88
std::vector< VSTBuffer * > VSTBuffers
Definition: buffer_set.h:214
void ensure_lv2_bufsize(bool input, size_t i, size_t buffer_capacity)
ChanCount & available()
Definition: buffer_set.h:89
midi_iterator midi_end()
Definition: buffer_set.h:181
bool _is_mirror
False if we 'own' the contained buffers, if true we mirror a PortSet)
Definition: buffer_set.h:225
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:171
std::vector< BufferVec > _buffers
Vector of vectors, indexed by DataType.
Definition: buffer_set.h:187
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:190
audio_iterator audio_end()
Definition: buffer_set.h:177
size_t buffer_capacity(DataType type) const
iterator_base< BufferSet, AudioBuffer > audio_iterator
Definition: buffer_set.h:175
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:108
iterator end(DataType type)
Definition: buffer_set.h:169
ChanCount _available
Available counts (number of buffers actually allocated)
Definition: buffer_set.h:222
bool silent_data() const
VSTBuffers _vst_buffers
Definition: buffer_set.h:215
void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity)
iterator_base< BufferSet, MidiBuffer > midi_iterator
Definition: buffer_set.h:179
ChanCount _count
Use counts (there may be more actual buffers than this)
Definition: buffer_set.h:219
const ChanCount & count() const
Definition: buffer_set.h:91
void set_count(const ChanCount &count)
Definition: buffer_set.h:97
const_iterator end(DataType type) const
Definition: buffer_set.h:173
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t