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/ardour.h"
25 #include "ardour/export_handler.h"
26 #include "ardour/export_channel.h"
27 #include "ardour/export_format_base.h"
29 #include "audiographer/utils/identity_vertex.h"
31 #include <boost/ptr_container/ptr_list.hpp>
32 #include <glibmm/threadpool.h>
34 namespace AudioGrapher {
35 class SampleRateConverter;
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;
50 class ExportGraphBuilder
53 typedef ExportHandler::FileSpec FileSpec;
54 typedef ExportElementFactory::FilenamePtr FilenamePtr;
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 (nframes_t frames, bool last_cycle);
66 bool process_normalize (); // returns true when finished
69 void add_config (FileSpec const & config);
73 void add_split_config (FileSpec const & config);
77 template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
78 void add_child (FileSpec const & new_config);
79 bool operator== (FileSpec const & other_config) const;
81 static int get_real_format (FileSpec const & config);
84 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
85 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
86 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
88 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
89 void copy_files (std::string orig_path);
92 std::list<FilenamePtr> filenames;
93 PBD::ScopedConnection copy_files_connection;
95 // Only one of these should be available at a time
96 FloatWriterPtr float_writer;
97 IntWriterPtr int_writer;
98 ShortWriterPtr short_writer;
101 // sample format converter
104 // This constructor so that this can be constructed like a Normalizer
105 SFC (ExportGraphBuilder &, FileSpec const & new_config, nframes_t max_frames);
106 FloatSinkPtr sink ();
107 void add_child (FileSpec const & new_config);
108 bool operator== (FileSpec const & other_config) const;
111 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
112 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
113 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
116 boost::ptr_list<Encoder> children;
119 // Only one of these should be available at a time
120 FloatConverterPtr float_converter;
121 IntConverterPtr int_converter;
122 ShortConverterPtr short_converter;
127 Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, nframes_t max_frames);
128 FloatSinkPtr sink ();
129 void add_child (FileSpec const & new_config);
130 bool operator== (FileSpec const & other_config) const;
132 /// Returns true when finished
136 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
137 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
138 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
139 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
140 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
142 void start_post_processing();
144 ExportGraphBuilder & parent;
147 nframes_t max_frames_out;
150 PeakReaderPtr peak_reader;
152 NormalizerPtr normalizer;
153 ThreaderPtr threader;
154 boost::ptr_list<SFC> children;
156 PBD::ScopedConnection post_processing_connection;
159 // sample rate converter
162 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, nframes_t max_frames);
163 FloatSinkPtr sink ();
164 void add_child (FileSpec const & new_config);
165 bool operator== (FileSpec const & other_config) const;
168 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
171 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
173 ExportGraphBuilder & parent;
175 boost::ptr_list<SFC> children;
176 boost::ptr_list<Normalizer> normalized_children;
177 SRConverterPtr converter;
178 nframes_t max_frames_out;
181 // Silence trimmer + adder
182 class SilenceHandler {
184 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, nframes_t max_frames);
185 FloatSinkPtr sink ();
186 void add_child (FileSpec const & new_config);
187 bool operator== (FileSpec const & other_config) const;
190 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
192 ExportGraphBuilder & parent;
194 boost::ptr_list<SRC> children;
195 SilenceTrimmerPtr silence_trimmer;
196 nframes_t max_frames_in;
199 // channel configuration
200 class ChannelConfig {
202 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
203 void add_child (FileSpec const & new_config);
204 bool operator== (FileSpec const & other_config) const;
207 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
209 ExportGraphBuilder & parent;
211 boost::ptr_list<SilenceHandler> children;
212 InterleaverPtr interleaver;
213 nframes_t max_frames;
216 Session const & session;
218 // Roots for export processor trees
219 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
220 ChannelConfigList channel_configs;
222 // The sources of all data, each channel is read only once
225 Sample * process_buffer;
226 nframes_t process_buffer_frames;
228 std::list<Normalizer *> normalizers;
230 Glib::ThreadPool thread_pool;
233 } // namespace ARDOUR
235 #endif /* __ardour_export_graph_builder_h__ */