Ardour  9.0-pre0-582-g084a23a80d
export_channel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2012 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
6  * Copyright (C) 2017-2022 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <list>
26 #include <memory>
27 #include <set>
28 
29 #include "pbd/ringbuffer.h"
30 #include "pbd/signals.h"
31 
32 #include "ardour/audio_buffer.h"
33 #include "ardour/buffer_set.h"
34 #include "ardour/export_pointers.h"
35 #include "ardour/fixed_delay.h"
36 #include "ardour/midi_buffer.h"
37 
38 namespace ARDOUR {
39 
40 class Session;
41 class AudioTrack;
42 class AudioPort;
43 class AudioRegion;
44 class CapturingProcessor;
45 class MidiPort;
46 
48 class LIBARDOUR_API ExportChannel : public boost::less_than_comparable<ExportChannel>
49 {
50 public:
51  virtual ~ExportChannel () {}
52 
53  virtual samplecnt_t common_port_playback_latency () const { return 0; }
54  virtual void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency) {}
55 
56  virtual void read (Buffer const*&, samplecnt_t samples) const = 0;
57 
58  virtual bool empty () const = 0;
59 
60  virtual bool audio () const { return true; }
61  virtual bool midi () const { return false; }
62 
63  virtual std::string state_node_name () const = 0;
64 
66  virtual void get_state (XMLNode* node) const = 0;
67 
69  virtual void set_state (XMLNode* node, Session& session) = 0;
70 
71  // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
72  virtual bool operator< (ExportChannel const& other) const = 0;
73 };
74 
77 {
78 public:
79  typedef std::set<std::weak_ptr<AudioPort>, std::owner_less<std::weak_ptr<AudioPort>>> PortSet;
80 
83 
85  void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency);
86 
87  void read (Buffer const*&, samplecnt_t samples) const;
88 
89  bool empty () const { return ports.empty (); }
90 
91  std::string state_node_name () const { return "PortExportChannel"; }
92 
93  void get_state (XMLNode* node) const;
94  void set_state (XMLNode* node, Session& session);
95 
96  bool operator< (ExportChannel const& other) const;
97 
98  void add_port (std::weak_ptr<AudioPort> port) { ports.insert (port); }
99  PortSet const& get_ports () const { return ports; }
100 
101 private:
104  std::unique_ptr<Sample[]> _buffer;
105  mutable AudioBuffer _buf;
106  std::list<std::shared_ptr<PBD::RingBuffer<Sample>>> _delaylines;
107 };
108 
111 {
112 public:
115 
116  /* ExportChannel interface */
118  void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency);
119 
120  void read (Buffer const*&, samplecnt_t samples) const;
121 
122  bool empty () const { return _port.expired (); }
123 
124  bool audio () const { return false; }
125  bool midi () const { return true; }
126 
127  std::string state_node_name () const { return "PortExportMIDI"; }
128 
129  void get_state (XMLNode* node) const;
131 
132  bool operator< (ExportChannel const& other) const;
133 
134  std::shared_ptr<MidiPort> port () const { return _port.lock (); }
135 
136  void set_port (std::weak_ptr<MidiPort> port)
137  {
138  _port = port;
139  }
140 
141 private:
142  std::weak_ptr<MidiPort> _port;
144  mutable MidiBuffer _buf;
145 };
146 
149 {
150 public:
151  enum Type {
155  };
156 
159 
160  ExportChannelPtr create (uint32_t channel);
161 
162  void read (uint32_t channel, Buffer const*&, samplecnt_t samples_to_read);
163 
164 private:
166  {
167  buffers_up_to_date = false;
168  return 0;
169  }
170 
171  void update_buffers (samplecnt_t samples);
172 
174 
177  size_t n_channels;
182 
183  std::unique_ptr<Sample[]> mixdown_buffer;
184  std::unique_ptr<Sample[]> gain_buffer;
185 
187 };
188 
191 {
193 
194 public:
195  void read (Buffer const*& buf, samplecnt_t samples_to_read) const
196  {
197  factory.read (channel, buf, samples_to_read);
198  }
199 
200  std::string state_node_name () const { return "RegionExportChannel"; }
201 
202  void get_state (XMLNode* /*node*/) const {};
203  void set_state (XMLNode* /*node*/, Session& /*session*/){};
204 
205  bool empty () const { return false; }
206 
207  // Region export should never have duplicate channels, so there need not be any semantics here
208  bool operator< (ExportChannel const& other) const
209  {
210  return this < &other;
211  }
212 
213 private:
214  RegionExportChannel (RegionExportChannelFactory& factory, uint32_t channel)
215  : factory (factory)
216  , channel (channel)
217  {
218  }
219 
221  uint32_t channel;
222 };
223 
226 {
227  class ProcessorRemover; // fwd declaration
228 
229 public:
230  RouteExportChannel (std::shared_ptr<CapturingProcessor> processor,
231  DataType type,
232  size_t channel,
233  std::shared_ptr<ProcessorRemover> remover);
234 
236 
237  static void create_from_route (std::list<ExportChannelPtr>& result, std::shared_ptr<Route> route);
238  static void create_from_state (std::list<ExportChannelPtr>& result, Session&, XMLNode*);
239 
240 public: // ExportChannel interface
241  void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency);
242 
243  void read (Buffer const*&, samplecnt_t samples) const;
244 
245  bool empty () const { return false; }
246 
247  bool audio () const;
248  bool midi () const;
249 
250  std::shared_ptr<Route> route () const { return _remover->route (); }
251 
252  std::string state_node_name () const { return "RouteExportChannel"; }
253 
254  void get_state (XMLNode* node) const;
256 
257  bool operator< (ExportChannel const& other) const;
258 
259 private:
260  // Removes the processor from the track when deleted
262  {
263  public:
264  ProcessorRemover (std::shared_ptr<Route> route, std::shared_ptr<CapturingProcessor> processor)
265  : _route (route)
266  , _processor (processor)
267  {
268  }
270 
271  std::shared_ptr<Route> route () const { return _route; }
272 
273  private:
274  std::shared_ptr<Route> _route;
275  std::shared_ptr<CapturingProcessor> _processor;
276  };
277 
278  std::shared_ptr<CapturingProcessor> _processor;
279 
281  size_t _channel;
282 
283  // Each channel keeps a ref to the remover. Last one alive
284  // will cause the processor to be removed on deletion.
285  std::shared_ptr<ProcessorRemover> _remover;
286 };
287 
288 } // namespace ARDOUR
289 
Export channel base class interface for different source types.
virtual void read(Buffer const *&, samplecnt_t samples) const =0
virtual void get_state(XMLNode *node) const =0
Adds state to node passed.
virtual void prepare_export(samplecnt_t max_samples, sampleoffset_t common_latency)
virtual std::string state_node_name() const =0
virtual samplecnt_t common_port_playback_latency() const
virtual bool audio() const
virtual bool empty() const =0
virtual void set_state(XMLNode *node, Session &session)=0
Sets state from node passed.
virtual bool midi() const
Basic export channel that reads from AudioPorts.
PortSet const & get_ports() const
void read(Buffer const *&, samplecnt_t samples) const
std::set< std::weak_ptr< AudioPort >, std::owner_less< std::weak_ptr< AudioPort > > > PortSet
std::string state_node_name() const
void add_port(std::weak_ptr< AudioPort > port)
std::unique_ptr< Sample[]> _buffer
samplecnt_t common_port_playback_latency() const
void get_state(XMLNode *node) const
Adds state to node passed.
void prepare_export(samplecnt_t max_samples, sampleoffset_t common_latency)
void set_state(XMLNode *node, Session &session)
Sets state from node passed.
std::list< std::shared_ptr< PBD::RingBuffer< Sample > > > _delaylines
Basic export channel that reads from MIDIPorts.
void set_state(XMLNode *node, Session &session)
Sets state from node passed.
void read(Buffer const *&, samplecnt_t samples) const
void prepare_export(samplecnt_t max_samples, sampleoffset_t common_latency)
std::string state_node_name() const
void set_port(std::weak_ptr< MidiPort > port)
samplecnt_t common_port_playback_latency() const
std::shared_ptr< MidiPort > port() const
void get_state(XMLNode *node) const
Adds state to node passed.
std::weak_ptr< MidiPort > _port
Handles RegionExportChannels and does actual reading from region.
void update_buffers(samplecnt_t samples)
RegionExportChannelFactory(Session *session, AudioRegion const &region, AudioTrack &track, Type type)
PBD::ScopedConnection export_connection
std::unique_ptr< Sample[]> mixdown_buffer
std::unique_ptr< Sample[]> gain_buffer
void read(uint32_t channel, Buffer const *&, samplecnt_t samples_to_read)
ExportChannelPtr create(uint32_t channel)
Export channel that reads from region channel.
void read(Buffer const *&buf, samplecnt_t samples_to_read) const
RegionExportChannelFactory & factory
void set_state(XMLNode *, Session &)
Sets state from node passed.
RegionExportChannel(RegionExportChannelFactory &factory, uint32_t channel)
std::string state_node_name() const
void get_state(XMLNode *) const
Adds state to node passed.
ProcessorRemover(std::shared_ptr< Route > route, std::shared_ptr< CapturingProcessor > processor)
std::shared_ptr< CapturingProcessor > _processor
std::shared_ptr< Route > route() const
Export channel for exporting from different positions in a route.
std::shared_ptr< CapturingProcessor > _processor
void read(Buffer const *&, samplecnt_t samples) const
RouteExportChannel(std::shared_ptr< CapturingProcessor > processor, DataType type, size_t channel, std::shared_ptr< ProcessorRemover > remover)
std::shared_ptr< Route > route() const
std::shared_ptr< ProcessorRemover > _remover
void prepare_export(samplecnt_t max_samples, sampleoffset_t common_latency)
std::string state_node_name() const
void set_state(XMLNode *node, Session &session)
Sets state from node passed.
void get_state(XMLNode *node) const
Adds state to node passed.
static void create_from_state(std::list< ExportChannelPtr > &result, Session &, XMLNode *)
static void create_from_route(std::list< ExportChannelPtr > &result, std::shared_ptr< Route > route)
Definition: xml++.h:114
#define LIBARDOUR_API
void session(lua_State *L)
PBD::PropertyDescriptor< bool > region
Temporal::samplecnt_t samplecnt_t
Temporal::sampleoffset_t sampleoffset_t
Temporal::samplepos_t samplepos_t