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>
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.
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.
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.
24 #ifndef __ardour_export_handler_h__
25 #define __ardour_export_handler_h__
29 #include <boost/operators.hpp>
30 #include <boost/shared_ptr.hpp>
32 #include "pbd/gstdio_compat.h"
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"
40 namespace AudioGrapher {
48 class ExportChannelConfiguration;
49 class ExportFormatSpecification;
51 class ExportGraphBuilder;
54 class LIBARDOUR_API ExportElementFactory
58 ExportElementFactory (Session & session);
59 ~ExportElementFactory ();
61 ExportTimespanPtr add_timespan ();
63 ExportChannelConfigPtr add_channel_config ();
65 ExportFormatSpecPtr add_format ();
66 ExportFormatSpecPtr add_format (XMLNode const & state);
67 ExportFormatSpecPtr add_format_copy (ExportFormatSpecPtr other);
69 ExportFilenamePtr add_filename ();
70 ExportFilenamePtr add_filename_copy (ExportFilenamePtr other);
77 class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::trackable
82 FileSpec (ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format,
83 ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
84 : channel_config (channel_config)
87 , broadcast_info (broadcast_info)
90 ExportChannelConfigPtr channel_config;
91 ExportFormatSpecPtr format;
92 ExportFilenamePtr filename;
93 BroadcastInfoPtr broadcast_info;
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
101 friend boost::shared_ptr<ExportHandler> Session::get_export_handler();
102 ExportHandler (Session & session);
104 void command_output(std::string output, size_t size);
109 bool add_export_config (ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config,
110 ExportFormatSpecPtr format, ExportFilenamePtr filename,
111 BroadcastInfoPtr broadcast_info);
114 std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
116 /** signal emitted when soundcloud export reports progress updates during upload.
117 * The parameters are total and current bytes downloaded, and the current filename
119 PBD::Signal3<void, double, double, std::string> SoundcloudProgress;
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;
132 void handle_duplicate_format_extensions();
133 int process (samplecnt_t samples);
136 boost::shared_ptr<ExportGraphBuilder> graph_builder;
137 ExportStatusPtr export_status;
139 /* The timespan and corresponding file specifications that we are exporting;
140 there can be multiple FileSpecs for each ExportTimespan.
142 typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
143 ConfigMap config_map;
145 bool post_processing;
147 /* Timespan management */
149 void start_timespan ();
150 int process_timespan (samplecnt_t samples);
152 void finish_timespan ();
154 typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
155 ExportTimespanPtr current_timespan;
156 TimespanBounds timespan_bounds;
158 PBD::ScopedConnection process_connection;
159 samplepos_t process_position;
161 /* CD Marker stuff */
163 struct CDMarkerStatus {
164 CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
165 ExportFormatSpecPtr format, std::string filename)
167 , timespan (timespan)
169 , filename (filename)
174 , track_start_sample (0)
183 std::stringstream out;
186 ExportTimespanPtr timespan;
187 ExportFormatSpecPtr format;
188 std::string filename;
192 uint32_t track_number;
193 samplepos_t track_position;
194 samplepos_t track_duration;
195 samplepos_t track_start_sample;
198 uint32_t index_number;
199 samplepos_t index_position;
203 void export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSpecPtr file_format,
204 std::string filename, CDMarkerFormat format);
206 void write_cue_header (CDMarkerStatus & status);
207 void write_toc_header (CDMarkerStatus & status);
208 void write_mp4ch_header (CDMarkerStatus & status);
210 void write_track_info_cue (CDMarkerStatus & status);
211 void write_track_info_toc (CDMarkerStatus & status);
212 void write_track_info_mp4ch (CDMarkerStatus & status);
214 void write_index_info_cue (CDMarkerStatus & status);
215 void write_index_info_toc (CDMarkerStatus & status);
216 void write_index_info_mp4ch (CDMarkerStatus & status);
218 void samples_to_cd_frame_string (char* buf, samplepos_t when);
219 void samples_to_chapter_marks_string (char* buf, samplepos_t when);
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);
229 } // namespace ARDOUR
231 #endif /* __ardour_export_handler_h__ */