summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/export_processor.h
blob: fdb8213c68bad10c6fdbd6d993c9248f490b3797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
    Copyright (C) 2008 Paul Davis
    Author: Sakari Bergen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __ardour_export_processor_h__
#define __ardour_export_processor_h__

#include <vector>

#include <boost/smart_ptr.hpp>
#include <glibmm/ustring.h>

#include <ardour/graph.h>
#include <ardour/export_file_io.h>
#include <ardour/export_utilities.h>

using Glib::ustring;
using std::list;

namespace ARDOUR
{

class Session;
class ExportStatus;
class ExportFilename;
class ExportFormatSpecification;

/// Sets up components for export post processing
class ExportProcessor
{
  private:
	/* Typedefs for utility processors */
	
	typedef boost::shared_ptr<SampleRateConverter> SRConverterPtr;
	typedef boost::shared_ptr<PeakReader> PReaderPtr;
	typedef boost::shared_ptr<Normalizer> NormalizerPtr;
	typedef boost::shared_ptr<ExportTempFile> TempFilePtr;
	
	typedef boost::shared_ptr<SampleFormatConverter<short> > ShortConverterPtr;
	typedef boost::shared_ptr<SampleFormatConverter<int> > IntConverterPtr;
	typedef boost::shared_ptr<SampleFormatConverter<float> > FloatConverterPtr;
	
	typedef boost::shared_ptr<SndfileWriter<short> > ShortWriterPtr;
	typedef boost::shared_ptr<SndfileWriter<int> > IntWriterPtr;
	typedef boost::shared_ptr<SndfileWriter<float> > FloatWriterPtr;
	
	typedef GraphSink<float> FloatSink;
	typedef boost::shared_ptr<FloatSink> FloatSinkPtr;
	typedef std::vector<FloatSinkPtr> FloatSinkVect;
	
	typedef boost::shared_ptr<ExportFilename> FilenamePtr;
	typedef boost::shared_ptr<ExportFormatSpecification const> FormatPtr;
	
	typedef boost::shared_ptr<ExportFileWriter> FileWriterPtr;
	typedef std::list<FileWriterPtr> FileWriterList;
	
  public:

	ExportProcessor (Session & session);
	~ExportProcessor ();
	ExportProcessor * copy() { return new ExportProcessor (session); }

	/// Do preparations for exporting
	/** Should be called before process
	 * @return 0 on success
	 */
	int prepare (FormatPtr format, FilenamePtr fname, uint32_t chans, bool split = false, nframes_t start = 0);
	
	/// Process data
	/** @param frames frames to process @return frames written **/
	nframes_t process (float * data, nframes_t frames);
	
	/** should be called after all data is given to process **/
	void prepare_post_processors ();
	
	void write_files ();
	
	static sigc::signal<void, Glib::ustring> WritingFile;
	
  private:
	
	void reset ();
	FloatSinkPtr prepare_sndfile_writer (FormatPtr format, uint32_t channels, ustring const & filename);
	
	Session &        session;
	ExportStatus &   status;
	
	/* these are initalized in prepare() */
	
	FilenamePtr      filename;
	NormalizerPtr    normalizer;
	SRConverterPtr   src;
	PReaderPtr       peak_reader;
	TempFilePtr      temp_file;
	FloatSinkVect    file_sinks;
	FileWriterList   writer_list;
	
	/* general info */
	
	uint32_t         channels;
	nframes_t        blocksize;
	nframes_t        frame_rate;
	
	/* Processing */
	
	bool             tag;
	bool             broadcast_info;
	bool             split_files;
	bool             normalize;
	bool             trim_beginning;
	bool             trim_end;
	nframes_t        silence_beginning;
	nframes_t        silence_end;
	
	/* Progress info */
	
	nframes_t        temp_file_position;
	nframes_t        temp_file_length;
};

} // namespace ARDOUR

#endif /* __ardour_export_processor_h__ */