Remove "i18n.h" include from header - fix builds
[ardour.git] / libs / ardour / ardour / export_handler.h
1 /*
2  * Copyright (C) 2008-2013 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
6  * Copyright (C) 2013-2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
7  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __ardour_export_handler_h__
25 #define __ardour_export_handler_h__
26
27 #include <map>
28
29 #include <boost/operators.hpp>
30 #include <boost/shared_ptr.hpp>
31
32 #include "pbd/gstdio_compat.h"
33
34 #include "ardour/export_pointers.h"
35 #include "ardour/session.h"
36 #include "ardour/libardour_visibility.h"
37 #include "ardour/types.h"
38 #include "pbd/signals.h"
39
40 namespace AudioGrapher {
41         class BroadcastInfo;
42 }
43
44 namespace ARDOUR
45 {
46
47 class ExportTimespan;
48 class ExportChannelConfiguration;
49 class ExportFormatSpecification;
50 class ExportFilename;
51 class ExportGraphBuilder;
52 class Location;
53
54 class LIBARDOUR_API ExportElementFactory
55 {
56   public:
57
58         ExportElementFactory (Session & session);
59         ~ExportElementFactory ();
60
61         ExportTimespanPtr add_timespan ();
62
63         ExportChannelConfigPtr add_channel_config ();
64
65         ExportFormatSpecPtr    add_format ();
66         ExportFormatSpecPtr    add_format (XMLNode const & state);
67         ExportFormatSpecPtr    add_format_copy (ExportFormatSpecPtr other);
68
69         ExportFilenamePtr      add_filename ();
70         ExportFilenamePtr      add_filename_copy (ExportFilenamePtr other);
71
72   private:
73         Session & session;
74 };
75
76 /** Export Handler */
77 class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::trackable
78 {
79   public:
80         struct FileSpec {
81                 FileSpec() {}
82                 FileSpec (ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format,
83                           ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
84                   : channel_config (channel_config)
85                   , format (format)
86                   , filename (filename)
87                   , broadcast_info (broadcast_info)
88                         {}
89
90                 ExportChannelConfigPtr channel_config;
91                 ExportFormatSpecPtr    format;
92                 ExportFilenamePtr      filename;
93                 BroadcastInfoPtr       broadcast_info;
94         };
95
96   private:
97         /* Session::get_export_handler() should be used to obtain an export handler
98          * This ensures that it doesn't go out of scope before finalize_audio_export is called
99          */
100
101         friend boost::shared_ptr<ExportHandler> Session::get_export_handler();
102         ExportHandler (Session & session);
103
104         void command_output(std::string output, size_t size);
105
106   public:
107         ~ExportHandler ();
108
109         bool add_export_config (ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config,
110                                 ExportFormatSpecPtr format, ExportFilenamePtr filename,
111                                 BroadcastInfoPtr broadcast_info);
112         void do_export ();
113
114         std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
115
116         /** signal emitted when soundcloud export reports progress updates during upload.
117          * The parameters are total and current bytes downloaded, and the current filename
118          */
119         PBD::Signal3<void, double, double, std::string> SoundcloudProgress;
120
121         /* upload credentials & preferences */
122         std::string soundcloud_username;
123         std::string soundcloud_password;
124         bool soundcloud_make_public;
125         bool soundcloud_open_page;
126         bool soundcloud_downloadable;
127
128         void reset ();
129
130   private:
131
132         void handle_duplicate_format_extensions();
133         int process (samplecnt_t samples);
134
135         Session &          session;
136         boost::shared_ptr<ExportGraphBuilder> graph_builder;
137         ExportStatusPtr    export_status;
138
139         /* The timespan and corresponding file specifications that we are exporting;
140            there can be multiple FileSpecs for each ExportTimespan.
141         */
142         typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
143         ConfigMap          config_map;
144
145         bool               post_processing;
146
147         /* Timespan management */
148
149         void start_timespan ();
150         int  process_timespan (samplecnt_t samples);
151         int  post_process ();
152         void finish_timespan ();
153
154         typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
155         ExportTimespanPtr     current_timespan;
156         TimespanBounds        timespan_bounds;
157
158         PBD::ScopedConnection process_connection;
159         samplepos_t           process_position;
160
161         /* CD Marker stuff */
162
163         struct CDMarkerStatus {
164                 CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
165                                 ExportFormatSpecPtr format, std::string filename)
166                   : path (out_file)
167                   , timespan (timespan)
168                   , format (format)
169                   , filename (filename)
170                   , marker(0)
171                   , track_number (1)
172                   , track_position (0)
173                   , track_duration (0)
174                   , track_start_sample (0)
175                   , index_number (1)
176                   , index_position (0)
177                   {}
178
179                 ~CDMarkerStatus ();
180
181                 /* I/O */
182                 std::string         path;
183                 std::stringstream   out;
184
185                 /* General info */
186                 ExportTimespanPtr   timespan;
187                 ExportFormatSpecPtr format;
188                 std::string         filename;
189                 Location *          marker;
190
191                 /* Track info */
192                 uint32_t        track_number;
193                 samplepos_t     track_position;
194                 samplepos_t     track_duration;
195                 samplepos_t     track_start_sample;
196
197                 /* Index info */
198                 uint32_t        index_number;
199                 samplepos_t     index_position;
200         };
201
202
203         void export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSpecPtr file_format,
204                                     std::string filename, CDMarkerFormat format);
205
206         void write_cue_header (CDMarkerStatus & status);
207         void write_toc_header (CDMarkerStatus & status);
208         void write_mp4ch_header (CDMarkerStatus & status);
209
210         void write_track_info_cue (CDMarkerStatus & status);
211         void write_track_info_toc (CDMarkerStatus & status);
212         void write_track_info_mp4ch (CDMarkerStatus & status);
213
214         void write_index_info_cue (CDMarkerStatus & status);
215         void write_index_info_toc (CDMarkerStatus & status);
216         void write_index_info_mp4ch (CDMarkerStatus & status);
217
218         void samples_to_cd_frame_string (char* buf, samplepos_t when);
219         void samples_to_chapter_marks_string (char* buf, samplepos_t when);
220
221         std::string toc_escape_cdtext (const std::string&);
222         std::string toc_escape_filename (const std::string&);
223         std::string cue_escape_cdtext (const std::string& txt);
224
225         int cue_tracknum;
226         int cue_indexnum;
227 };
228
229 } // namespace ARDOUR
230
231 #endif /* __ardour_export_handler_h__ */