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;
55 typedef boost::shared_ptr<AudioGrapher::Sink<Sample> > FloatSinkPtr;
56 typedef boost::shared_ptr<AudioGrapher::IdentityVertex<Sample> > IdentityVertexPtr;
57 typedef std::map<ExportChannelPtr, IdentityVertexPtr> ChannelMap;
61 ExportGraphBuilder (Session const & session);
62 ~ExportGraphBuilder ();
64 int process (framecnt_t frames, bool last_cycle);
65 bool process_normalize (); // returns true when finished
66 bool will_normalize() { return !normalizers.empty(); }
69 void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
70 void add_config (FileSpec const & config);
74 void add_split_config (FileSpec const & config);
78 template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
79 void add_child (FileSpec const & new_config);
80 bool operator== (FileSpec const & other_config) const;
82 static int get_real_format (FileSpec const & config);
85 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
86 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
87 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
89 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
90 void copy_files (std::string orig_path);
93 std::list<ExportFilenamePtr> filenames;
94 PBD::ScopedConnection copy_files_connection;
96 // Only one of these should be available at a time
97 FloatWriterPtr float_writer;
98 IntWriterPtr int_writer;
99 ShortWriterPtr short_writer;
102 // sample format converter
105 // This constructor so that this can be constructed like a Normalizer
106 SFC (ExportGraphBuilder &, FileSpec const & new_config, framecnt_t max_frames);
107 FloatSinkPtr sink ();
108 void add_child (FileSpec const & new_config);
109 bool operator== (FileSpec const & other_config) const;
112 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
113 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
114 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
117 boost::ptr_list<Encoder> children;
120 // Only one of these should be available at a time
121 FloatConverterPtr float_converter;
122 IntConverterPtr int_converter;
123 ShortConverterPtr short_converter;
128 Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
129 FloatSinkPtr sink ();
130 void add_child (FileSpec const & new_config);
131 bool operator== (FileSpec const & other_config) const;
133 /// Returns true when finished
137 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
138 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
139 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
140 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
141 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
143 void start_post_processing();
145 ExportGraphBuilder & parent;
148 framecnt_t max_frames_out;
151 PeakReaderPtr peak_reader;
153 NormalizerPtr normalizer;
154 ThreaderPtr threader;
155 boost::ptr_list<SFC> children;
157 PBD::ScopedConnection post_processing_connection;
160 // sample rate converter
163 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
164 FloatSinkPtr sink ();
165 void add_child (FileSpec const & new_config);
166 bool operator== (FileSpec const & other_config) const;
169 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
172 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
174 ExportGraphBuilder & parent;
176 boost::ptr_list<SFC> children;
177 boost::ptr_list<Normalizer> normalized_children;
178 SRConverterPtr converter;
179 framecnt_t max_frames_out;
182 // Silence trimmer + adder
183 class SilenceHandler {
185 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
186 FloatSinkPtr sink ();
187 void add_child (FileSpec const & new_config);
188 bool operator== (FileSpec const & other_config) const;
191 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
193 ExportGraphBuilder & parent;
195 boost::ptr_list<SRC> children;
196 SilenceTrimmerPtr silence_trimmer;
197 framecnt_t max_frames_in;
200 // channel configuration
201 class ChannelConfig {
203 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
204 void add_child (FileSpec const & new_config);
205 bool operator== (FileSpec const & other_config) const;
208 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
210 ExportGraphBuilder & parent;
212 boost::ptr_list<SilenceHandler> children;
213 InterleaverPtr interleaver;
214 framecnt_t max_frames;
217 Session const & session;
218 boost::shared_ptr<ExportTimespan> timespan;
220 // Roots for export processor trees
221 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
222 ChannelConfigList channel_configs;
224 // The sources of all data, each channel is read only once
227 framecnt_t process_buffer_frames;
229 std::list<Normalizer *> normalizers;
231 Glib::ThreadPool thread_pool;
234 } // namespace ARDOUR
236 #endif /* __ardour_export_graph_builder_h__ */