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 set_current_timespan (boost::shared_ptr<ExportTimespan> span);
72 void add_config (FileSpec const & config);
76 void add_split_config (FileSpec const & config);
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;
84 static int get_real_format (FileSpec const & config);
87 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
88 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
89 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
91 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
92 void copy_files (std::string orig_path);
95 std::list<ExportFilenamePtr> filenames;
96 PBD::ScopedConnection copy_files_connection;
98 // Only one of these should be available at a time
99 FloatWriterPtr float_writer;
100 IntWriterPtr int_writer;
101 ShortWriterPtr short_writer;
104 // sample format converter
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;
114 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
115 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
116 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
119 boost::ptr_list<Encoder> children;
122 // Only one of these should be available at a time
123 FloatConverterPtr float_converter;
124 IntConverterPtr int_converter;
125 ShortConverterPtr short_converter;
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;
135 unsigned get_normalize_cycle_count() const;
137 /// Returns true when finished
141 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
142 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
143 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
144 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
145 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
147 void start_post_processing();
149 ExportGraphBuilder & parent;
152 framecnt_t max_frames_out;
155 PeakReaderPtr peak_reader;
157 NormalizerPtr normalizer;
158 ThreaderPtr threader;
159 boost::ptr_list<SFC> children;
161 PBD::ScopedConnection post_processing_connection;
164 // sample rate converter
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;
173 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
176 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
178 ExportGraphBuilder & parent;
180 boost::ptr_list<SFC> children;
181 boost::ptr_list<Normalizer> normalized_children;
182 SRConverterPtr converter;
183 framecnt_t max_frames_out;
186 // Silence trimmer + adder
187 class SilenceHandler {
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;
195 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
197 ExportGraphBuilder & parent;
199 boost::ptr_list<SRC> children;
200 SilenceTrimmerPtr silence_trimmer;
201 framecnt_t max_frames_in;
204 // channel configuration
205 class ChannelConfig {
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;
212 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
213 typedef boost::shared_ptr<AudioGrapher::Chunker<Sample> > ChunkerPtr;
215 ExportGraphBuilder & parent;
217 boost::ptr_list<SilenceHandler> children;
218 InterleaverPtr interleaver;
220 framecnt_t max_frames_out;
223 Session const & session;
224 boost::shared_ptr<ExportTimespan> timespan;
226 // Roots for export processor trees
227 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
228 ChannelConfigList channel_configs;
230 // The sources of all data, each channel is read only once
233 framecnt_t process_buffer_frames;
235 std::list<Normalizer *> normalizers;
237 Glib::ThreadPool thread_pool;
240 } // namespace ARDOUR
242 #endif /* __ardour_export_graph_builder_h__ */