ardour
export_graph_builder.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Paul Davis
3  Author: Sakari Bergen
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 
21 #ifndef __ardour_export_graph_builder_h__
22 #define __ardour_export_graph_builder_h__
23 
24 #include "ardour/export_handler.h"
25 
26 #include "audiographer/utils/identity_vertex.h"
27 
28 #include <boost/ptr_container/ptr_list.hpp>
29 #include <glibmm/threadpool.h>
30 
31 namespace AudioGrapher {
32  class SampleRateConverter;
33  class PeakReader;
34  class Normalizer;
35  template <typename T> class Chunker;
36  template <typename T> class SampleFormatConverter;
37  template <typename T> class Interleaver;
38  template <typename T> class SndfileWriter;
39  template <typename T> class SilenceTrimmer;
40  template <typename T> class TmpFile;
41  template <typename T> class Threader;
42  template <typename T> class AllocatingProcessContext;
43 }
44 
45 namespace ARDOUR
46 {
47 
48 class ExportTimespan;
49 class Session;
50 
52 {
53  private:
55 
58  typedef std::map<ExportChannelPtr, IdentityVertexPtr> ChannelMap;
59 
60  public:
61 
62  ExportGraphBuilder (Session const & session);
64 
65  int process (framecnt_t frames, bool last_cycle);
66  bool process_normalize (); // returns true when finished
67  bool will_normalize() { return !normalizers.empty(); }
68  unsigned get_normalize_cycle_count() const;
69 
70  void reset ();
71  void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
72  void add_config (FileSpec const & config);
73 
74  private:
75 
76  void add_split_config (FileSpec const & config);
77 
78  class Encoder {
79  public:
80  template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
81  void add_child (FileSpec const & new_config);
82  bool operator== (FileSpec const & other_config) const;
83 
84  static int get_real_format (FileSpec const & config);
85 
86  private:
90 
91  template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
92  void copy_files (std::string orig_path);
93 
94  FileSpec config;
95  std::list<ExportFilenamePtr> filenames;
97 
98  // Only one of these should be available at a time
99  FloatWriterPtr float_writer;
100  IntWriterPtr int_writer;
101  ShortWriterPtr short_writer;
102  };
103 
104  // sample format converter
105  class SFC {
106  public:
107  // This constructor so that this can be constructed like a Normalizer
108  SFC (ExportGraphBuilder &, FileSpec const & new_config, framecnt_t max_frames);
109  FloatSinkPtr sink ();
110  void add_child (FileSpec const & new_config);
111  bool operator== (FileSpec const & other_config) const;
112 
113  private:
117 
118  FileSpec config;
119  boost::ptr_list<Encoder> children;
121 
122  // Only one of these should be available at a time
123  FloatConverterPtr float_converter;
124  IntConverterPtr int_converter;
125  ShortConverterPtr short_converter;
126  };
127 
128  class Normalizer {
129  public:
130  Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
131  FloatSinkPtr sink ();
132  void add_child (FileSpec const & new_config);
133  bool operator== (FileSpec const & other_config) const;
134 
135  unsigned get_normalize_cycle_count() const;
136 
138  bool process ();
139 
140  private:
146 
147  void start_post_processing();
148 
150 
151  FileSpec config;
153 
154  BufferPtr buffer;
155  PeakReaderPtr peak_reader;
156  TmpFilePtr tmp_file;
157  NormalizerPtr normalizer;
158  ThreaderPtr threader;
159  boost::ptr_list<SFC> children;
160 
162  };
163 
164  // sample rate converter
165  class SRC {
166  public:
167  SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
168  FloatSinkPtr sink ();
169  void add_child (FileSpec const & new_config);
170  bool operator== (FileSpec const & other_config) const;
171 
172  private:
174 
175  template<typename T>
176  void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
177 
179  FileSpec config;
180  boost::ptr_list<SFC> children;
181  boost::ptr_list<Normalizer> normalized_children;
182  SRConverterPtr converter;
184  };
185 
186  // Silence trimmer + adder
188  public:
189  SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
190  FloatSinkPtr sink ();
191  void add_child (FileSpec const & new_config);
192  bool operator== (FileSpec const & other_config) const;
193 
194  private:
196 
198  FileSpec config;
199  boost::ptr_list<SRC> children;
200  SilenceTrimmerPtr silence_trimmer;
202  };
203 
204  // channel configuration
206  public:
207  ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
208  void add_child (FileSpec const & new_config);
209  bool operator== (FileSpec const & other_config) const;
210 
211  private:
214 
216  FileSpec config;
217  boost::ptr_list<SilenceHandler> children;
218  InterleaverPtr interleaver;
219  ChunkerPtr chunker;
221  };
222 
223  Session const & session;
225 
226  // Roots for export processor trees
227  typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
228  ChannelConfigList channel_configs;
229 
230  // The sources of all data, each channel is read only once
231  ChannelMap channels;
232 
234 
235  std::list<Normalizer *> normalizers;
236 
237  Glib::ThreadPool thread_pool;
238 };
239 
240 } // namespace ARDOUR
241 
242 #endif /* __ardour_export_graph_builder_h__ */
boost::shared_ptr< AudioGrapher::SndfileWriter< Sample > > FloatWriterPtr
boost::shared_ptr< AudioGrapher::TmpFile< Sample > > TmpFilePtr
boost::shared_ptr< AudioGrapher::PeakReader > PeakReaderPtr
boost::shared_ptr< AudioGrapher::SndfileWriter< int > > IntWriterPtr
boost::shared_ptr< AudioGrapher::SampleFormatConverter< int > > IntConverterPtr
std::map< ExportChannelPtr, IdentityVertexPtr > ChannelMap
ExportHandler::FileSpec FileSpec
boost::ptr_list< ChannelConfig > ChannelConfigList
boost::ptr_list< Encoder > children
boost::shared_ptr< AudioGrapher::Normalizer > NormalizerPtr
boost::shared_ptr< AudioGrapher::Chunker< Sample > > ChunkerPtr
boost::shared_ptr< ExportTimespan > timespan
std::list< ExportFilenamePtr > filenames
boost::shared_ptr< AudioGrapher::SndfileWriter< short > > ShortWriterPtr
int64_t framecnt_t
Definition: types.h:76
boost::shared_ptr< AudioGrapher::Sink< Sample > > FloatSinkPtr
Definition: amp.h:29
boost::shared_ptr< AudioGrapher::AllocatingProcessContext< Sample > > BufferPtr
boost::shared_ptr< AudioGrapher::SilenceTrimmer< Sample > > SilenceTrimmerPtr
void copy_files(const std::string &from_path, const std::string &to_dir)
Definition: file_utils.cc:319
#define LIBARDOUR_API
boost::ptr_list< Normalizer > normalized_children
boost::shared_ptr< AudioGrapher::SampleFormatConverter< short > > ShortConverterPtr
boost::ptr_list< SilenceHandler > children
bool operator==(const RouteProcessorSelection &a, const RouteProcessorSelection &b)
boost::shared_ptr< AudioGrapher::Threader< Sample > > ThreaderPtr
boost::shared_ptr< AudioGrapher::SampleRateConverter > SRConverterPtr
std::list< Normalizer * > normalizers
LIBARDOUR_API bool init(bool with_vst, bool try_optimization, const char *localedir)
Definition: globals.cc:376
boost::shared_ptr< AudioGrapher::Interleaver< Sample > > InterleaverPtr
boost::shared_ptr< AudioGrapher::IdentityVertex< Sample > > IdentityVertexPtr
boost::shared_ptr< AudioGrapher::SampleFormatConverter< Sample > > FloatConverterPtr