Ardour  8.12
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 #ifndef __ardour_export_channel_h__
24 #define __ardour_export_channel_h__
25 
26 #include <list>
27 #include <memory>
28 #include <set>
29 
30 #include <boost/scoped_array.hpp>
31 
32 #include "pbd/ringbuffer.h"
33 #include "pbd/signals.h"
34 
35 #include "ardour/audio_buffer.h"
36 #include "ardour/buffer_set.h"
37 #include "ardour/export_pointers.h"
38 #include "ardour/fixed_delay.h"
39 #include "ardour/midi_buffer.h"
40 
41 namespace ARDOUR {
42 
43 class Session;
44 class AudioTrack;
45 class AudioPort;
46 class AudioRegion;
47 class CapturingProcessor;
48 class MidiPort;
49 
51 class LIBARDOUR_API ExportChannel : public boost::less_than_comparable<ExportChannel>
52 {
53 public:
54  virtual ~ExportChannel () {}
55 
56  virtual samplecnt_t common_port_playback_latency () const { return 0; }
57  virtual void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency) {}
58 
59  virtual void read (Buffer const*&, samplecnt_t samples) const = 0;
60 
61  virtual bool empty () const = 0;
62 
63  virtual bool audio () const { return true; }
64  virtual bool midi () const { return false; }
65 
66  virtual std::string state_node_name () const = 0;
67 
69  virtual void get_state (XMLNode* node) const = 0;
70 
72  virtual void set_state (XMLNode* node, Session& session) = 0;
73 
74  // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
75  virtual bool operator< (ExportChannel const& other) const = 0;
76 };
77 
80 {
81 public:
82  typedef std::set<std::weak_ptr<AudioPort>, std::owner_less<std::weak_ptr<AudioPort>>> PortSet;
83 
86 
88  void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency);
89 
90  void read (Buffer const*&, samplecnt_t samples) const;
91 
92  bool empty () const { return ports.empty (); }
93 
94  std::string state_node_name () const { return "PortExportChannel"; }
95 
96  void get_state (XMLNode* node) const;
97  void set_state (XMLNode* node, Session& session);
98 
99  bool operator< (ExportChannel const& other) const;
100 
101  void add_port (std::weak_ptr<AudioPort> port) { ports.insert (port); }
102  PortSet const& get_ports () const { return ports; }
103 
104 private:
107  boost::scoped_array<Sample> _buffer;
108  mutable AudioBuffer _buf;
109  std::list<std::shared_ptr<PBD::RingBuffer<Sample>>> _delaylines;
110 };
111 
114 {
115 public:
118 
119  /* ExportChannel interface */
121  void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency);
122 
123  void read (Buffer const*&, samplecnt_t samples) const;
124 
125  bool empty () const { return _port.expired (); }
126 
127  bool audio () const { return false; }
128  bool midi () const { return true; }
129 
130  std::string state_node_name () const { return "PortExportMIDI"; }
131 
132  void get_state (XMLNode* node) const;
134 
135  bool operator< (ExportChannel const& other) const;
136 
137  std::shared_ptr<MidiPort> port () const { return _port.lock (); }
138 
139  void set_port (std::weak_ptr<MidiPort> port)
140  {
141  _port = port;
142  }
143 
144 private:
145  std::weak_ptr<MidiPort> _port;
147  mutable MidiBuffer _buf;
148 };
149 
152 {
153 public:
154  enum Type {
158  };
159 
162 
163  ExportChannelPtr create (uint32_t channel);
164 
165  void read (uint32_t channel, Buffer const*&, samplecnt_t samples_to_read);
166 
167 private:
169  {
170  buffers_up_to_date = false;
171  return 0;
172  }
173 
174  void update_buffers (samplecnt_t samples);
175 
177 
180  size_t n_channels;
185 
186  boost::scoped_array<Sample> mixdown_buffer;
187  boost::scoped_array<Sample> gain_buffer;
188 
190 };
191 
194 {
196 
197 public:
198  void read (Buffer const*& buf, samplecnt_t samples_to_read) const
199  {
200  factory.read (channel, buf, samples_to_read);
201  }
202 
203  std::string state_node_name () const { return "RegionExportChannel"; }
204 
205  void get_state (XMLNode* /*node*/) const {};
206  void set_state (XMLNode* /*node*/, Session& /*session*/){};
207 
208  bool empty () const { return false; }
209 
210  // Region export should never have duplicate channels, so there need not be any semantics here
211  bool operator< (ExportChannel const& other) const
212  {
213  return this < &other;
214  }
215 
216 private:
217  RegionExportChannel (RegionExportChannelFactory& factory, uint32_t channel)
218  : factory (factory)
219  , channel (channel)
220  {
221  }
222 
224  uint32_t channel;
225 };
226 
229 {
230  class ProcessorRemover; // fwd declaration
231 
232 public:
233  RouteExportChannel (std::shared_ptr<CapturingProcessor> processor,
234  DataType type,
235  size_t channel,
236  std::shared_ptr<ProcessorRemover> remover);
237 
239 
240  static void create_from_route (std::list<ExportChannelPtr>& result, std::shared_ptr<Route> route);
241  static void create_from_state (std::list<ExportChannelPtr>& result, Session&, XMLNode*);
242 
243 public: // ExportChannel interface
244  void prepare_export (samplecnt_t max_samples, sampleoffset_t common_latency);
245 
246  void read (Buffer const*&, samplecnt_t samples) const;
247 
248  bool empty () const { return false; }
249 
250  bool audio () const;
251  bool midi () const;
252 
253  std::shared_ptr<Route> route () const { return _remover->route (); }
254 
255  std::string state_node_name () const { return "RouteExportChannel"; }
256 
257  void get_state (XMLNode* node) const;
259 
260  bool operator< (ExportChannel const& other) const;
261 
262 private:
263  // Removes the processor from the track when deleted
265  {
266  public:
267  ProcessorRemover (std::shared_ptr<Route> route, std::shared_ptr<CapturingProcessor> processor)
268  : _route (route)
269  , _processor (processor)
270  {
271  }
273 
274  std::shared_ptr<Route> route () const { return _route; }
275 
276  private:
277  std::shared_ptr<Route> _route;
278  std::shared_ptr<CapturingProcessor> _processor;
279  };
280 
281  std::shared_ptr<CapturingProcessor> _processor;
282 
284  size_t _channel;
285 
286  // Each channel keeps a ref to the remover. Last one alive
287  // will cause the processor to be removed on deletion.
288  std::shared_ptr<ProcessorRemover> _remover;
289 };
290 
291 } // namespace ARDOUR
292 
293 #endif
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)
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)
boost::scoped_array< Sample > _buffer
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)
boost::scoped_array< Sample > gain_buffer
RegionExportChannelFactory(Session *session, AudioRegion const &region, AudioTrack &track, Type type)
PBD::ScopedConnection export_connection
boost::scoped_array< Sample > mixdown_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)
Temporal::samplecnt_t samplecnt_t
Temporal::sampleoffset_t sampleoffset_t
Temporal::samplepos_t samplepos_t