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"
26 #include "audiographer/utils/identity_vertex.h"
28 #include <boost/ptr_container/ptr_list.hpp>
29 #include <glibmm/threadpool.h>
31 namespace AudioGrapher {
32 class SampleRateConverter;
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;
51 class LIBARDOUR_API ExportGraphBuilder
54 typedef ExportHandler::FileSpec FileSpec;
56 typedef boost::shared_ptr<AudioGrapher::Sink<Sample> > FloatSinkPtr;
57 typedef boost::shared_ptr<AudioGrapher::IdentityVertex<Sample> > IdentityVertexPtr;
58 typedef std::map<ExportChannelPtr, IdentityVertexPtr> ChannelMap;
62 ExportGraphBuilder (Session const & session);
63 ~ExportGraphBuilder ();
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;
71 void cleanup (bool remove_out_files = false);
72 void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
73 void add_config (FileSpec const & config);
77 void add_split_config (FileSpec const & config);
81 template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
82 void add_child (FileSpec const & new_config);
83 void remove_children ();
84 void destroy_writer (bool delete_out_file);
85 bool operator== (FileSpec const & other_config) const;
87 static int get_real_format (FileSpec const & config);
90 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
91 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
92 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
94 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
95 void copy_files (std::string orig_path);
98 std::list<ExportFilenamePtr> filenames;
99 PBD::ScopedConnection copy_files_connection;
101 std::string writer_filename;
103 // Only one of these should be available at a time
104 FloatWriterPtr float_writer;
105 IntWriterPtr int_writer;
106 ShortWriterPtr short_writer;
109 // sample format converter
112 // This constructor so that this can be constructed like a Normalizer
113 SFC (ExportGraphBuilder &, FileSpec const & new_config, framecnt_t max_frames);
114 FloatSinkPtr sink ();
115 void add_child (FileSpec const & new_config);
116 void remove_children (bool remove_out_files);
117 bool operator== (FileSpec const & other_config) const;
120 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
121 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
122 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
125 boost::ptr_list<Encoder> children;
128 // Only one of these should be available at a time
129 FloatConverterPtr float_converter;
130 IntConverterPtr int_converter;
131 ShortConverterPtr short_converter;
136 Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
137 FloatSinkPtr sink ();
138 void add_child (FileSpec const & new_config);
139 void remove_children (bool remove_out_files);
140 bool operator== (FileSpec const & other_config) const;
142 unsigned get_normalize_cycle_count() const;
144 /// Returns true when finished
148 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
149 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
150 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
151 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
152 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
154 void start_post_processing();
156 ExportGraphBuilder & parent;
159 framecnt_t max_frames_out;
162 PeakReaderPtr peak_reader;
164 NormalizerPtr normalizer;
165 ThreaderPtr threader;
166 boost::ptr_list<SFC> children;
168 PBD::ScopedConnection post_processing_connection;
171 // sample rate converter
174 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
175 FloatSinkPtr sink ();
176 void add_child (FileSpec const & new_config);
177 void remove_children (bool remove_out_files);
179 bool operator== (FileSpec const & other_config) const;
182 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
185 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
187 ExportGraphBuilder & parent;
189 boost::ptr_list<SFC> children;
190 boost::ptr_list<Normalizer> normalized_children;
191 SRConverterPtr converter;
192 framecnt_t max_frames_out;
195 // Silence trimmer + adder
196 class SilenceHandler {
198 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
199 FloatSinkPtr sink ();
200 void add_child (FileSpec const & new_config);
201 void remove_children (bool remove_out_files);
202 bool operator== (FileSpec const & other_config) const;
205 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
207 ExportGraphBuilder & parent;
209 boost::ptr_list<SRC> children;
210 SilenceTrimmerPtr silence_trimmer;
211 framecnt_t max_frames_in;
214 // channel configuration
215 class ChannelConfig {
217 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
218 void add_child (FileSpec const & new_config);
219 void remove_children (bool remove_out_files);
220 bool operator== (FileSpec const & other_config) const;
223 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
224 typedef boost::shared_ptr<AudioGrapher::Chunker<Sample> > ChunkerPtr;
226 ExportGraphBuilder & parent;
228 boost::ptr_list<SilenceHandler> children;
229 InterleaverPtr interleaver;
231 framecnt_t max_frames_out;
234 Session const & session;
235 boost::shared_ptr<ExportTimespan> timespan;
237 // Roots for export processor trees
238 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
239 ChannelConfigList channel_configs;
241 // The sources of all data, each channel is read only once
244 framecnt_t process_buffer_frames;
246 std::list<Normalizer *> normalizers;
248 Glib::ThreadPool thread_pool;
251 } // namespace ARDOUR
253 #endif /* __ardour_export_graph_builder_h__ */