2 Copyright (C) 2008 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_handler_h__
22 #define __ardour_export_handler_h__
27 #include <boost/operators.hpp>
28 #include <boost/shared_ptr.hpp>
30 #include "ardour/export_pointers.h"
31 #include "ardour/session.h"
32 #include "ardour/types.h"
33 #include "pbd/signals.h"
35 namespace AudioGrapher {
43 class ExportChannelConfiguration;
44 class ExportFormatSpecification;
46 class ExportGraphBuilder;
49 class ExportElementFactory
53 ExportElementFactory (Session & session);
54 ~ExportElementFactory ();
56 ExportTimespanPtr add_timespan ();
58 ExportChannelConfigPtr add_channel_config ();
60 ExportFormatSpecPtr add_format ();
61 ExportFormatSpecPtr add_format (XMLNode const & state);
62 ExportFormatSpecPtr add_format_copy (ExportFormatSpecPtr other);
64 ExportFilenamePtr add_filename ();
65 ExportFilenamePtr add_filename_copy (ExportFilenamePtr other);
71 class ExportHandler : public ExportElementFactory, public sigc::trackable
76 FileSpec (ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format,
77 ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
78 : channel_config (channel_config)
81 , broadcast_info (broadcast_info)
84 ExportChannelConfigPtr channel_config;
85 ExportFormatSpecPtr format;
86 ExportFilenamePtr filename;
87 BroadcastInfoPtr broadcast_info;
91 /* Session::get_export_handler() should be used to obtain an export handler
92 * This ensures that it doesn't go out of scope before finalize_audio_export is called
95 friend boost::shared_ptr<ExportHandler> Session::get_export_handler();
96 ExportHandler (Session & session);
101 bool add_export_config (ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config,
102 ExportFormatSpecPtr format, ExportFilenamePtr filename,
103 BroadcastInfoPtr broadcast_info);
106 std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
108 /** signal emitted when soundcloud export reports progress updates during upload.
109 * The parameters are total and current bytes downloaded, and the current filename
111 PBD::Signal3<void, double, double, std::string> SoundcloudProgress;
113 /* upload credentials & preferences */
114 std::string upload_username;
115 std::string upload_password;
121 void handle_duplicate_format_extensions();
122 int process (framecnt_t frames);
125 boost::shared_ptr<ExportGraphBuilder> graph_builder;
126 ExportStatusPtr export_status;
128 /* The timespan and corresponding file specifications that we are exporting;
129 there can be multiple FileSpecs for each ExportTimespan.
131 typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
132 ConfigMap config_map;
136 /* Timespan management */
138 void start_timespan ();
139 int process_timespan (framecnt_t frames);
140 int process_normalize ();
141 void finish_timespan ();
143 typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
144 ExportTimespanPtr current_timespan;
145 TimespanBounds timespan_bounds;
147 PBD::ScopedConnection process_connection;
148 framepos_t process_position;
150 /* CD Marker stuff */
152 struct CDMarkerStatus {
153 CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
154 ExportFormatSpecPtr format, std::string filename)
155 : out (out_file.c_str()), timespan (timespan), format (format), filename (filename), marker(0)
156 , track_number (1), track_position (0), track_duration (0), track_start_frame (0)
157 , index_number (1), index_position (0)
162 ExportTimespanPtr timespan;
163 ExportFormatSpecPtr format;
164 std::string filename;
168 uint32_t track_number;
169 framepos_t track_position;
170 framepos_t track_duration;
171 framepos_t track_start_frame;
174 uint32_t index_number;
175 framepos_t index_position;
179 void export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSpecPtr file_format,
180 std::string filename, CDMarkerFormat format);
182 void write_cue_header (CDMarkerStatus & status);
183 void write_toc_header (CDMarkerStatus & status);
185 void write_track_info_cue (CDMarkerStatus & status);
186 void write_track_info_toc (CDMarkerStatus & status);
188 void write_index_info_cue (CDMarkerStatus & status);
189 void write_index_info_toc (CDMarkerStatus & status);
191 void frames_to_cd_frames_string (char* buf, framepos_t when);
192 std::string toc_escape_cdtext (const std::string&);
193 std::string toc_escape_filename (const std::string&);
194 std::string cue_escape_cdtext (const std::string& txt);
200 } // namespace ARDOUR
202 #endif /* __ardour_export_handler_h__ */