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 TmpFileRt;
45 template <typename T> class Threader;
46 template <typename T> class AllocatingProcessContext;
55 class LIBARDOUR_API ExportGraphBuilder
58 typedef ExportHandler::FileSpec FileSpec;
60 typedef boost::shared_ptr<AudioGrapher::Sink<Sample> > FloatSinkPtr;
61 typedef boost::shared_ptr<AudioGrapher::IdentityVertex<Sample> > IdentityVertexPtr;
62 typedef boost::shared_ptr<AudioGrapher::Analyser> AnalysisPtr;
63 typedef std::map<ExportChannelPtr, IdentityVertexPtr> ChannelMap;
64 typedef std::map<std::string, AnalysisPtr> AnalysisMap;
68 ExportGraphBuilder (Session const & session);
69 ~ExportGraphBuilder ();
71 int process (framecnt_t frames, bool last_cycle);
72 bool process_normalize (); // returns true when finished
73 bool will_normalize() { return !normalizers.empty(); }
74 unsigned get_normalize_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);
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, framecnt_t max_frames);
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 Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
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_normalize_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::TmpFileRt<Sample> > TmpFileRtPtr;
169 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
170 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
172 void start_post_processing();
174 ExportGraphBuilder & parent;
177 framecnt_t max_frames_out;
180 PeakReaderPtr peak_reader;
182 NormalizerPtr normalizer;
183 ThreaderPtr threader;
184 LoudnessReaderPtr loudness_reader;
185 boost::ptr_list<SFC> children;
187 PBD::ScopedConnection post_processing_connection;
190 // sample rate converter
193 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
194 FloatSinkPtr sink ();
195 void add_child (FileSpec const & new_config);
196 void remove_children (bool remove_out_files);
198 bool operator== (FileSpec const & other_config) const;
201 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
204 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
206 ExportGraphBuilder & parent;
208 boost::ptr_list<SFC> children;
209 boost::ptr_list<Normalizer> normalized_children;
210 SRConverterPtr converter;
211 framecnt_t max_frames_out;
214 // Silence trimmer + adder
215 class SilenceHandler {
217 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
218 FloatSinkPtr sink ();
219 void add_child (FileSpec const & new_config);
220 void remove_children (bool remove_out_files);
221 bool operator== (FileSpec const & other_config) const;
224 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
226 ExportGraphBuilder & parent;
228 boost::ptr_list<SRC> children;
229 SilenceTrimmerPtr silence_trimmer;
230 framecnt_t max_frames_in;
233 // channel configuration
234 class ChannelConfig {
236 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
237 void add_child (FileSpec const & new_config);
238 void remove_children (bool remove_out_files);
239 bool operator== (FileSpec const & other_config) const;
242 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
243 typedef boost::shared_ptr<AudioGrapher::Chunker<Sample> > ChunkerPtr;
245 ExportGraphBuilder & parent;
247 boost::ptr_list<SilenceHandler> children;
248 InterleaverPtr interleaver;
250 framecnt_t max_frames_out;
253 Session const & session;
254 boost::shared_ptr<ExportTimespan> timespan;
256 // Roots for export processor trees
257 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
258 ChannelConfigList channel_configs;
260 // The sources of all data, each channel is read only once
263 framecnt_t process_buffer_frames;
265 std::list<Normalizer *> normalizers;
267 AnalysisMap analysis_map;
269 Glib::ThreadPool thread_pool;
272 } // namespace ARDOUR
274 #endif /* __ardour_export_graph_builder_h__ */