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;
37 template <typename T> class Chunker;
38 template <typename T> class SampleFormatConverter;
39 template <typename T> class Interleaver;
40 template <typename T> class SndfileWriter;
41 template <typename T> class SilenceTrimmer;
42 template <typename T> class TmpFile;
43 template <typename T> class Threader;
44 template <typename T> class AllocatingProcessContext;
53 class LIBARDOUR_API ExportGraphBuilder
56 typedef ExportHandler::FileSpec FileSpec;
58 typedef boost::shared_ptr<AudioGrapher::Sink<Sample> > FloatSinkPtr;
59 typedef boost::shared_ptr<AudioGrapher::IdentityVertex<Sample> > IdentityVertexPtr;
60 typedef boost::shared_ptr<AudioGrapher::Analyser> AnalysisPtr;
61 typedef std::map<ExportChannelPtr, IdentityVertexPtr> ChannelMap;
62 typedef std::map<std::string, AnalysisPtr> AnalysisMap;
66 ExportGraphBuilder (Session const & session);
67 ~ExportGraphBuilder ();
69 int process (framecnt_t frames, bool last_cycle);
70 bool process_normalize (); // returns true when finished
71 bool will_normalize() { return !normalizers.empty(); }
72 unsigned get_normalize_cycle_count() const;
75 void cleanup (bool remove_out_files = false);
76 void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
77 void add_config (FileSpec const & config);
78 void get_analysis_results (AnalysisResults& results);
82 void add_analyser (const std::string& fn, AnalysisPtr ap) {
83 analysis_map.insert (std::make_pair (fn, ap));
86 void add_split_config (FileSpec const & config);
90 template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
91 void add_child (FileSpec const & new_config);
92 void remove_children ();
93 void destroy_writer (bool delete_out_file);
94 bool operator== (FileSpec const & other_config) const;
96 static int get_real_format (FileSpec const & config);
99 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
100 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
101 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
103 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
104 void copy_files (std::string orig_path);
107 std::list<ExportFilenamePtr> filenames;
108 PBD::ScopedConnection copy_files_connection;
110 std::string writer_filename;
112 // Only one of these should be available at a time
113 FloatWriterPtr float_writer;
114 IntWriterPtr int_writer;
115 ShortWriterPtr short_writer;
118 // sample format converter
121 // This constructor so that this can be constructed like a Normalizer
122 SFC (ExportGraphBuilder &, FileSpec const & new_config, framecnt_t max_frames);
123 FloatSinkPtr sink ();
124 void add_child (FileSpec const & new_config);
125 void remove_children (bool remove_out_files);
126 bool operator== (FileSpec const & other_config) const;
129 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
130 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
131 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
134 boost::ptr_list<Encoder> children;
137 AnalysisPtr analyser;
139 // Only one of these should be available at a time
140 FloatConverterPtr float_converter;
141 IntConverterPtr int_converter;
142 ShortConverterPtr short_converter;
147 Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
148 FloatSinkPtr sink ();
149 void add_child (FileSpec const & new_config);
150 void remove_children (bool remove_out_files);
151 bool operator== (FileSpec const & other_config) const;
153 unsigned get_normalize_cycle_count() const;
155 /// Returns true when finished
159 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
160 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
161 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
162 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
163 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
165 void start_post_processing();
167 ExportGraphBuilder & parent;
170 framecnt_t max_frames_out;
173 PeakReaderPtr peak_reader;
175 NormalizerPtr normalizer;
176 ThreaderPtr threader;
177 boost::ptr_list<SFC> children;
179 PBD::ScopedConnection post_processing_connection;
182 // sample rate converter
185 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
186 FloatSinkPtr sink ();
187 void add_child (FileSpec const & new_config);
188 void remove_children (bool remove_out_files);
190 bool operator== (FileSpec const & other_config) const;
193 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
196 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
198 ExportGraphBuilder & parent;
200 boost::ptr_list<SFC> children;
201 boost::ptr_list<Normalizer> normalized_children;
202 SRConverterPtr converter;
203 framecnt_t max_frames_out;
206 // Silence trimmer + adder
207 class SilenceHandler {
209 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
210 FloatSinkPtr sink ();
211 void add_child (FileSpec const & new_config);
212 void remove_children (bool remove_out_files);
213 bool operator== (FileSpec const & other_config) const;
216 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
218 ExportGraphBuilder & parent;
220 boost::ptr_list<SRC> children;
221 SilenceTrimmerPtr silence_trimmer;
222 framecnt_t max_frames_in;
225 // channel configuration
226 class ChannelConfig {
228 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
229 void add_child (FileSpec const & new_config);
230 void remove_children (bool remove_out_files);
231 bool operator== (FileSpec const & other_config) const;
234 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
235 typedef boost::shared_ptr<AudioGrapher::Chunker<Sample> > ChunkerPtr;
237 ExportGraphBuilder & parent;
239 boost::ptr_list<SilenceHandler> children;
240 InterleaverPtr interleaver;
242 framecnt_t max_frames_out;
245 Session const & session;
246 boost::shared_ptr<ExportTimespan> timespan;
248 // Roots for export processor trees
249 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
250 ChannelConfigList channel_configs;
252 // The sources of all data, each channel is read only once
255 framecnt_t process_buffer_frames;
257 std::list<Normalizer *> normalizers;
259 AnalysisMap analysis_map;
261 Glib::ThreadPool thread_pool;
264 } // namespace ARDOUR
266 #endif /* __ardour_export_graph_builder_h__ */