2 Copyright (C) 2009 Paul Davis
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.
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.
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.
21 #ifndef __ardour_export_graph_builder_h__
22 #define __ardour_export_graph_builder_h__
24 #include "ardour/export_handler.h"
25 #include "ardour/export_analysis.h"
27 #include "audiographer/utils/identity_vertex.h"
29 #include <boost/ptr_container/ptr_list.hpp>
30 #include <glibmm/threadpool.h>
32 namespace AudioGrapher {
33 class SampleRateConverter;
38 template <typename T> class Chunker;
39 template <typename T> class SampleFormatConverter;
40 template <typename T> class Interleaver;
41 template <typename T> class SndfileWriter;
42 template <typename T> class SilenceTrimmer;
43 template <typename T> class TmpFile;
44 template <typename T> class Threader;
45 template <typename T> class AllocatingProcessContext;
54 class LIBARDOUR_API ExportGraphBuilder
57 typedef ExportHandler::FileSpec FileSpec;
59 typedef boost::shared_ptr<AudioGrapher::Sink<Sample> > FloatSinkPtr;
60 typedef boost::shared_ptr<AudioGrapher::IdentityVertex<Sample> > IdentityVertexPtr;
61 typedef boost::shared_ptr<AudioGrapher::Analyser> AnalysisPtr;
62 typedef std::map<ExportChannelPtr, IdentityVertexPtr> ChannelMap;
63 typedef std::map<std::string, AnalysisPtr> AnalysisMap;
67 ExportGraphBuilder (Session const & session);
68 ~ExportGraphBuilder ();
70 int process (samplecnt_t samples, bool last_cycle);
71 bool post_process (); // returns true when finished
72 bool need_postprocessing () const { return !intermediates.empty(); }
73 bool realtime() const { return _realtime; }
74 unsigned get_postprocessing_cycle_count() const;
77 void cleanup (bool remove_out_files = false);
78 void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
79 void add_config (FileSpec const & config, bool rt);
80 void get_analysis_results (AnalysisResults& results);
84 void add_analyser (const std::string& fn, AnalysisPtr ap) {
85 analysis_map.insert (std::make_pair (fn, ap));
88 void add_split_config (FileSpec const & config);
92 template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
93 void add_child (FileSpec const & new_config);
94 void remove_children ();
95 void destroy_writer (bool delete_out_file);
96 bool operator== (FileSpec const & other_config) const;
98 static int get_real_format (FileSpec const & config);
101 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
102 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
103 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
105 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
106 void copy_files (std::string orig_path);
109 std::list<ExportFilenamePtr> filenames;
110 PBD::ScopedConnection copy_files_connection;
112 std::string writer_filename;
114 // Only one of these should be available at a time
115 FloatWriterPtr float_writer;
116 IntWriterPtr int_writer;
117 ShortWriterPtr short_writer;
120 // sample format converter
123 // This constructor so that this can be constructed like a Normalizer
124 SFC (ExportGraphBuilder &, FileSpec const & new_config, samplecnt_t max_samples);
125 FloatSinkPtr sink ();
126 void add_child (FileSpec const & new_config);
127 void remove_children (bool remove_out_files);
128 bool operator== (FileSpec const & other_config) const;
129 void set_peak (float);
132 typedef boost::shared_ptr<AudioGrapher::Chunker<float> > ChunkerPtr;
133 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
134 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
135 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
138 boost::ptr_list<Encoder> children;
142 AnalysisPtr analyser;
144 // Only one of these should be available at a time
145 FloatConverterPtr float_converter;
146 IntConverterPtr int_converter;
147 ShortConverterPtr short_converter;
152 Intermediate (ExportGraphBuilder & parent, FileSpec const & new_config, samplecnt_t max_samples);
153 FloatSinkPtr sink ();
154 void add_child (FileSpec const & new_config);
155 void remove_children (bool remove_out_files);
156 bool operator== (FileSpec const & other_config) const;
158 unsigned get_postprocessing_cycle_count() const;
160 /// Returns true when finished
164 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
165 typedef boost::shared_ptr<AudioGrapher::LoudnessReader> LoudnessReaderPtr;
166 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
167 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
168 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
169 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
171 void prepare_post_processing ();
172 void start_post_processing ();
174 ExportGraphBuilder & parent;
177 samplecnt_t max_samples_out;
181 PeakReaderPtr peak_reader;
183 NormalizerPtr normalizer;
184 ThreaderPtr threader;
185 LoudnessReaderPtr loudness_reader;
186 boost::ptr_list<SFC> children;
188 PBD::ScopedConnectionList post_processing_connection;
191 // sample rate converter
194 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, samplecnt_t max_samples);
195 FloatSinkPtr sink ();
196 void add_child (FileSpec const & new_config);
197 void remove_children (bool remove_out_files);
199 bool operator== (FileSpec const & other_config) const;
202 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
205 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
207 ExportGraphBuilder & parent;
209 boost::ptr_list<SFC> children;
210 boost::ptr_list<Intermediate> intermediate_children;
211 SRConverterPtr converter;
212 samplecnt_t max_samples_out;
215 // Silence trimmer + adder
216 class SilenceHandler {
218 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, samplecnt_t max_samples);
219 FloatSinkPtr sink ();
220 void add_child (FileSpec const & new_config);
221 void remove_children (bool remove_out_files);
222 bool operator== (FileSpec const & other_config) const;
225 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
227 ExportGraphBuilder & parent;
229 boost::ptr_list<SRC> children;
230 SilenceTrimmerPtr silence_trimmer;
231 samplecnt_t max_samples_in;
234 // channel configuration
235 class ChannelConfig {
237 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
238 void add_child (FileSpec const & new_config);
239 void remove_children (bool remove_out_files);
240 bool operator== (FileSpec const & other_config) const;
243 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
244 typedef boost::shared_ptr<AudioGrapher::Chunker<Sample> > ChunkerPtr;
246 ExportGraphBuilder & parent;
248 boost::ptr_list<SilenceHandler> children;
249 InterleaverPtr interleaver;
251 samplecnt_t max_samples_out;
254 Session const & session;
255 boost::shared_ptr<ExportTimespan> timespan;
257 // Roots for export processor trees
258 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
259 ChannelConfigList channel_configs;
261 // The sources of all data, each channel is read only once
264 samplecnt_t process_buffer_samples;
266 std::list<Intermediate *> intermediates;
268 AnalysisMap analysis_map;
272 Glib::ThreadPool thread_pool;
275 } // namespace ARDOUR
277 #endif /* __ardour_export_graph_builder_h__ */