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 SampleFormatConverter;
36 template <typename T> class Interleaver;
37 template <typename T> class SndfileWriter;
38 template <typename T> class SilenceTrimmer;
39 template <typename T> class TmpFile;
40 template <typename T> class Threader;
41 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(); }
67 unsigned get_normalize_cycle_count() const;
70 void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
71 void add_config (FileSpec const & config);
75 void add_split_config (FileSpec const & config);
79 template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
80 void add_child (FileSpec const & new_config);
81 bool operator== (FileSpec const & other_config) const;
83 static int get_real_format (FileSpec const & config);
86 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<Sample> > FloatWriterPtr;
87 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<int> > IntWriterPtr;
88 typedef boost::shared_ptr<AudioGrapher::SndfileWriter<short> > ShortWriterPtr;
90 template<typename T> void init_writer (boost::shared_ptr<AudioGrapher::SndfileWriter<T> > & writer);
91 void copy_files (std::string orig_path);
94 std::list<ExportFilenamePtr> filenames;
95 PBD::ScopedConnection copy_files_connection;
97 // Only one of these should be available at a time
98 FloatWriterPtr float_writer;
99 IntWriterPtr int_writer;
100 ShortWriterPtr short_writer;
103 // sample format converter
106 // This constructor so that this can be constructed like a Normalizer
107 SFC (ExportGraphBuilder &, FileSpec const & new_config, framecnt_t max_frames);
108 FloatSinkPtr sink ();
109 void add_child (FileSpec const & new_config);
110 bool operator== (FileSpec const & other_config) const;
113 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
114 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
115 typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
118 boost::ptr_list<Encoder> children;
121 // Only one of these should be available at a time
122 FloatConverterPtr float_converter;
123 IntConverterPtr int_converter;
124 ShortConverterPtr short_converter;
129 Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
130 FloatSinkPtr sink ();
131 void add_child (FileSpec const & new_config);
132 bool operator== (FileSpec const & other_config) const;
134 unsigned get_normalize_cycle_count() const;
136 /// Returns true when finished
140 typedef boost::shared_ptr<AudioGrapher::PeakReader> PeakReaderPtr;
141 typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
142 typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
143 typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
144 typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
146 void start_post_processing();
148 ExportGraphBuilder & parent;
151 framecnt_t max_frames_out;
154 PeakReaderPtr peak_reader;
156 NormalizerPtr normalizer;
157 ThreaderPtr threader;
158 boost::ptr_list<SFC> children;
160 PBD::ScopedConnection post_processing_connection;
163 // sample rate converter
166 SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
167 FloatSinkPtr sink ();
168 void add_child (FileSpec const & new_config);
169 bool operator== (FileSpec const & other_config) const;
172 typedef boost::shared_ptr<AudioGrapher::SampleRateConverter> SRConverterPtr;
175 void add_child_to_list (FileSpec const & new_config, boost::ptr_list<T> & list);
177 ExportGraphBuilder & parent;
179 boost::ptr_list<SFC> children;
180 boost::ptr_list<Normalizer> normalized_children;
181 SRConverterPtr converter;
182 framecnt_t max_frames_out;
185 // Silence trimmer + adder
186 class SilenceHandler {
188 SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
189 FloatSinkPtr sink ();
190 void add_child (FileSpec const & new_config);
191 bool operator== (FileSpec const & other_config) const;
194 typedef boost::shared_ptr<AudioGrapher::SilenceTrimmer<Sample> > SilenceTrimmerPtr;
196 ExportGraphBuilder & parent;
198 boost::ptr_list<SRC> children;
199 SilenceTrimmerPtr silence_trimmer;
200 framecnt_t max_frames_in;
203 // channel configuration
204 class ChannelConfig {
206 ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
207 void add_child (FileSpec const & new_config);
208 bool operator== (FileSpec const & other_config) const;
211 typedef boost::shared_ptr<AudioGrapher::Interleaver<Sample> > InterleaverPtr;
213 ExportGraphBuilder & parent;
215 boost::ptr_list<SilenceHandler> children;
216 InterleaverPtr interleaver;
217 framecnt_t max_frames;
220 Session const & session;
221 boost::shared_ptr<ExportTimespan> timespan;
223 // Roots for export processor trees
224 typedef boost::ptr_list<ChannelConfig> ChannelConfigList;
225 ChannelConfigList channel_configs;
227 // The sources of all data, each channel is read only once
230 framecnt_t process_buffer_frames;
232 std::list<Normalizer *> normalizers;
234 Glib::ThreadPool thread_pool;
237 } // namespace ARDOUR
239 #endif /* __ardour_export_graph_builder_h__ */