Ardour  9.2-129-gdf5e1050bd
export_graph_builder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2012 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2010-2012 David Robillard <d@drobilla.net>
4  * Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2016-2019 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 #include "pbd/thread_pool.h"
25 
26 #include "ardour/export_handler.h"
27 #include "ardour/export_analysis.h"
29 
31 
32 #include <boost/ptr_container/ptr_list.hpp>
33 
34 namespace AudioGrapher {
35  class SampleRateConverter;
36  class PeakReader;
37  class LoudnessReader;
38  class Normalizer;
39  class Limiter;
40  class Analyser;
41  class DemoNoiseAdder;
42  template <typename T> class Chunker;
43  template <typename T> class SampleFormatConverter;
44  template <typename T> class Interleaver;
45  template <typename T> class SndfileWriter;
46  template <typename T> class CmdPipeWriter;
47  template <typename T> class SilenceTrimmer;
48  template <typename T> class TmpFile;
49  template <typename T> class Threader;
50  template <typename T> class AllocatingProcessContext;
51 }
52 
53 namespace ARDOUR
54 {
55 
56 class ExportTimespan;
57 class MidiBuffer;
58 class Session;
59 
61 {
62  private:
64 
65  typedef std::shared_ptr<AudioGrapher::Sink<Sample> > FloatSinkPtr;
66  typedef std::shared_ptr<AudioGrapher::Analyser> AnalysisPtr;
67  typedef std::map<std::string, AnalysisPtr> AnalysisMap;
68 
69  struct AnyExport {
70  /* Audio export */
73  audio.add_output (output);
74  }
76  audio.process (c);
77  }
78  /* MIDI Export */
80  void process (MidiBuffer const& buf, sampleoffset_t off, samplecnt_t cnt, bool last_cycle) {
81  midi.process (buf, off, cnt, last_cycle);
82  }
83  };
84 
85  typedef std::shared_ptr<AnyExport> AnyExportPtr;
86  typedef std::map<ExportChannelPtr, AnyExportPtr> ChannelMap;
87 
88  public:
89 
90  ExportGraphBuilder (Session const & session);
92 
93  samplecnt_t process (samplecnt_t samples, bool last_cycle);
94  bool post_process (); // returns true when finished
95  bool need_postprocessing () const { return !intermediates.empty(); }
96  bool realtime() const { return _realtime; }
98 
99  void reset ();
100  void cleanup (bool remove_out_files = false);
101  void set_current_timespan (std::shared_ptr<ExportTimespan> span);
102  void add_config (FileSpec const & config, bool rt);
104 
105  std::vector<std::string> exported_files () const {
106  return _exported_files;
107  }
108 
109  private:
110 
111  void add_analyser (const std::string& fn, AnalysisPtr ap) {
112  analysis_map.insert (std::make_pair (fn, ap));
113  }
114 
115  void add_export_fn (std::string const& fn) {
116  _exported_files.push_back (fn);
117  }
118 
119  std::vector<std::string> _exported_files;
120 
121  void add_split_config (FileSpec const & config);
122 
123  class Encoder {
124  public:
126  template <typename T> std::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
127  void add_child (FileSpec const & new_config);
129  void destroy_writer (bool delete_out_file);
130  bool operator== (FileSpec const & other_config) const;
131 
132  static int get_real_format (FileSpec const & config);
133 
134  private:
135  typedef std::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
136  typedef std::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
137  typedef std::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
138 
139  typedef std::shared_ptr<AudioGrapher::CmdPipeWriter<Sample> > FloatPipePtr;
140 
141  template<typename T> void init_writer (std::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
142  template<typename T> void init_writer (std::shared_ptr<AudioGrapher::CmdPipeWriter<T> > & writer);
143 
144  void copy_files (std::string orig_path);
145 
147  std::list<ExportFilenamePtr> filenames;
149 
150  std::string writer_filename;
151 
152  // Only one of these should be available at a time
157  };
158 
159  // sample format converter
160  class SFC {
161  public:
162  // This constructor so that this can be constructed like a Normalizer
163  SFC (ExportGraphBuilder &, FileSpec const & new_config, samplecnt_t max_samples);
165  void add_child (FileSpec const & new_config);
166  void remove_children (bool remove_out_files);
167  bool operator== (FileSpec const & other_config) const;
168 
170  void set_peak_dbfs (float, bool force = false);
172 
173  private:
174  typedef std::shared_ptr<AudioGrapher::Chunker<float> > ChunkerPtr;
175  typedef std::shared_ptr<AudioGrapher::DemoNoiseAdder> DemoNoisePtr;
176  typedef std::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
177  typedef std::shared_ptr<AudioGrapher::Limiter> LimiterPtr;
178  typedef std::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
179  typedef std::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
180  typedef std::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
181 
184  std::list<Encoder> children;
185 
191  bool _analyse;
192  // Only one of these should be available at a time
196  };
197 
198  class Intermediate {
199  public:
200  Intermediate (ExportGraphBuilder & parent, FileSpec const & new_config, samplecnt_t max_samples);
202  void add_child (FileSpec const & new_config);
203  void remove_children (bool remove_out_files);
204  bool operator== (FileSpec const & other_config) const;
205 
207 
209  bool process ();
210 
211  private:
212  typedef std::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
213  typedef std::shared_ptr<AudioGrapher::LoudnessReader> LoudnessReaderPtr;
214  typedef std::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
215  typedef std::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
216  typedef std::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
217 
220 
222 
226  bool use_peak;
231 
233  std::list<SFC> children;
234 
236  };
237 
238  // sample rate converter
239  class SRC {
240  public:
241  SRC (ExportGraphBuilder & parent, FileSpec const & new_config, samplecnt_t max_samples);
243  void add_child (FileSpec const & new_config);
244  void remove_children (bool remove_out_files);
245 
246  bool operator== (FileSpec const & other_config) const;
247 
248  private:
249  typedef std::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
250 
251  template<typename T>
252  void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
253 
256  boost::ptr_list<SFC> children;
257  boost::ptr_list<Intermediate> intermediate_children;
260  };
261 
262  // Silence trimmer + adder
264  public:
265  SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, samplecnt_t max_samples);
267  void add_child (FileSpec const & new_config);
268  void remove_children (bool remove_out_files);
269  bool operator== (FileSpec const & other_config) const;
270 
271  private:
272  typedef std::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
273 
276  boost::ptr_list<SRC> children;
279  };
280 
281  // channel configuration
283  public:
285  void add_child (FileSpec const & new_config);
286  void remove_children (bool remove_out_files);
287  bool operator== (FileSpec const & other_config) const;
288 
289  private:
290  typedef std::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
291  typedef std::shared_ptr<AudioGrapher::Chunker<Sample> > ChunkerPtr;
292 
295  boost::ptr_list<SilenceHandler> children;
299  };
300 
301  Session const & session;
302  std::shared_ptr<ExportTimespan> timespan;
303 
304  // Roots for export processor trees
305  typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
307 
308  // The sources of all data, each channel is read only once
310 
312 
313  std::list<Intermediate *> intermediates;
314 
316 
317  bool _realtime;
319 
322 };
323 
324 } // namespace ARDOUR
325 
std::shared_ptr< AudioGrapher::Interleaver< Sample > > InterleaverPtr
void remove_children(bool remove_out_files)
ChannelConfig(ExportGraphBuilder &parent, FileSpec const &new_config, ChannelMap &channel_map)
boost::ptr_list< SilenceHandler > children
void add_child(FileSpec const &new_config)
std::shared_ptr< AudioGrapher::Chunker< Sample > > ChunkerPtr
void destroy_writer(bool delete_out_file)
std::list< ExportFilenamePtr > filenames
void copy_files(std::string orig_path)
static int get_real_format(FileSpec const &config)
std::shared_ptr< AudioGrapher::SndfileWriter< short > > ShortWriterPtr
std::shared_ptr< AudioGrapher::Sink< T > > init(FileSpec const &new_config)
void add_child(FileSpec const &new_config)
std::shared_ptr< AudioGrapher::CmdPipeWriter< Sample > > FloatPipePtr
void init_writer(std::shared_ptr< AudioGrapher::SndfileWriter< T > > &writer)
std::shared_ptr< AudioGrapher::SndfileWriter< int > > IntWriterPtr
void init_writer(std::shared_ptr< AudioGrapher::CmdPipeWriter< T > > &writer)
std::shared_ptr< AudioGrapher::SndfileWriter< Sample > > FloatWriterPtr
bool process()
Returns true when finished.
void add_child(FileSpec const &new_config)
std::shared_ptr< AudioGrapher::LoudnessReader > LoudnessReaderPtr
std::shared_ptr< AudioGrapher::Threader< Sample > > ThreaderPtr
std::shared_ptr< AudioGrapher::PeakReader > PeakReaderPtr
Intermediate(ExportGraphBuilder &parent, FileSpec const &new_config, samplecnt_t max_samples)
PBD::ScopedConnectionList post_processing_connection
std::shared_ptr< AudioGrapher::AllocatingProcessContext< Sample > > BufferPtr
std::shared_ptr< AudioGrapher::TmpFile< Sample > > TmpFilePtr
void remove_children(bool remove_out_files)
std::shared_ptr< AudioGrapher::DemoNoiseAdder > DemoNoisePtr
std::shared_ptr< AudioGrapher::Chunker< float > > ChunkerPtr
std::shared_ptr< AudioGrapher::Limiter > LimiterPtr
void set_peak_dbfs(float, bool force=false)
void add_child(FileSpec const &new_config)
std::shared_ptr< AudioGrapher::SampleFormatConverter< Sample > > FloatConverterPtr
void set_peak_lufs(AudioGrapher::LoudnessReader const &)
SFC(ExportGraphBuilder &, FileSpec const &new_config, samplecnt_t max_samples)
std::shared_ptr< AudioGrapher::SampleFormatConverter< short > > ShortConverterPtr
void set_duration(samplecnt_t)
void remove_children(bool remove_out_files)
std::shared_ptr< AudioGrapher::Normalizer > NormalizerPtr
std::shared_ptr< AudioGrapher::SampleFormatConverter< int > > IntConverterPtr
void add_child_to_list(FileSpec const &new_config, boost::ptr_list< T > &list)
SRC(ExportGraphBuilder &parent, FileSpec const &new_config, samplecnt_t max_samples)
void add_child(FileSpec const &new_config)
std::shared_ptr< AudioGrapher::SampleRateConverter > SRConverterPtr
void remove_children(bool remove_out_files)
boost::ptr_list< Intermediate > intermediate_children
std::shared_ptr< AudioGrapher::SilenceTrimmer< Sample > > SilenceTrimmerPtr
SilenceHandler(ExportGraphBuilder &parent, FileSpec const &new_config, samplecnt_t max_samples)
void add_child(FileSpec const &new_config)
void remove_children(bool remove_out_files)
void add_export_fn(std::string const &fn)
void add_config(FileSpec const &config, bool rt)
std::vector< std::string > _exported_files
boost::ptr_list< ChannelConfig > ChannelConfigList
std::shared_ptr< AudioGrapher::Sink< Sample > > FloatSinkPtr
std::map< ExportChannelPtr, AnyExportPtr > ChannelMap
void add_analyser(const std::string &fn, AnalysisPtr ap)
unsigned get_postprocessing_cycle_count() const
std::map< std::string, AnalysisPtr > AnalysisMap
void get_analysis_results(AnalysisResults &results)
ExportGraphBuilder(Session const &session)
void cleanup(bool remove_out_files=false)
samplecnt_t process(samplecnt_t samples, bool last_cycle)
std::shared_ptr< ExportTimespan > timespan
void set_current_timespan(std::shared_ptr< ExportTimespan > span)
void add_split_config(FileSpec const &config)
std::shared_ptr< AnyExport > AnyExportPtr
ExportHandler::FileSpec FileSpec
std::list< Intermediate * > intermediates
std::shared_ptr< AudioGrapher::Analyser > AnalysisPtr
std::vector< std::string > exported_files() const
void process(MidiBuffer const &, sampleoffset_t, samplecnt_t, bool)
void process(ProcessContext< T > const &c)
void add_output(typename Source< T >::SinkPtr output)
Definition: listed_source.h:19
std::shared_ptr< Sink< T > > SinkPtr
#define LIBARDOUR_API
PBD::PropertyDescriptor< bool > channel_map
std::map< std::string, ExportAnalysisPtr > AnalysisResults
Temporal::samplecnt_t samplecnt_t
Temporal::sampleoffset_t sampleoffset_t
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
void add_output(AudioGrapher::Source< Sample >::SinkPtr output)
void process(AudioGrapher::ProcessContext< Sample > const &c)
AudioGrapher::IdentityVertex< Sample > audio
void process(MidiBuffer const &buf, sampleoffset_t off, samplecnt_t cnt, bool last_cycle)