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"
34 namespace AudioGrapher {
42 class ExportChannelConfiguration;
43 class ExportFormatSpecification;
45 class ExportGraphBuilder;
48 class ExportElementFactory
52 ExportElementFactory (Session & session);
53 ~ExportElementFactory ();
55 ExportTimespanPtr add_timespan ();
57 ExportChannelConfigPtr add_channel_config ();
59 ExportFormatSpecPtr add_format ();
60 ExportFormatSpecPtr add_format (XMLNode const & state);
61 ExportFormatSpecPtr add_format_copy (ExportFormatSpecPtr other);
63 ExportFilenamePtr add_filename ();
64 ExportFilenamePtr add_filename_copy (ExportFilenamePtr other);
70 class ExportHandler : public ExportElementFactory
75 FileSpec (ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format,
76 ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
77 : channel_config (channel_config)
80 , broadcast_info (broadcast_info)
83 ExportChannelConfigPtr channel_config;
84 ExportFormatSpecPtr format;
85 ExportFilenamePtr filename;
86 BroadcastInfoPtr broadcast_info;
90 /* Session::get_export_handler() should be used to obtain an export handler
91 * This ensures that it doesn't go out of scope before finalize_audio_export is called
94 friend boost::shared_ptr<ExportHandler> Session::get_export_handler();
95 ExportHandler (Session & session);
100 bool add_export_config (ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config,
101 ExportFormatSpecPtr format, ExportFilenamePtr filename,
102 BroadcastInfoPtr broadcast_info);
105 std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
109 int process (framecnt_t frames);
112 boost::shared_ptr<ExportGraphBuilder> graph_builder;
113 ExportStatusPtr export_status;
115 /* The timespan and corresponding file specifications that we are exporting;
116 there can be multiple FileSpecs for each ExportTimespan.
118 typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
119 ConfigMap config_map;
123 /* Timespan management */
125 void start_timespan ();
126 int process_timespan (framecnt_t frames);
127 int process_normalize ();
128 void finish_timespan ();
130 typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
131 ExportTimespanPtr current_timespan;
132 TimespanBounds timespan_bounds;
134 PBD::ScopedConnection process_connection;
135 framepos_t process_position;
137 /* CD Marker stuff */
139 struct CDMarkerStatus {
140 CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
141 ExportFormatSpecPtr format, std::string filename)
142 : out (out_file.c_str()), timespan (timespan), format (format), filename (filename), marker(0)
143 , track_number (1), track_position (0), track_duration (0), track_start_frame (0)
144 , index_number (1), index_position (0)
149 ExportTimespanPtr timespan;
150 ExportFormatSpecPtr format;
151 std::string filename;
155 uint32_t track_number;
156 framepos_t track_position;
157 framepos_t track_duration;
158 framepos_t track_start_frame;
161 uint32_t index_number;
162 framepos_t index_position;
166 void export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSpecPtr file_format,
167 std::string filename, CDMarkerFormat format);
169 void write_cue_header (CDMarkerStatus & status);
170 void write_toc_header (CDMarkerStatus & status);
172 void write_track_info_cue (CDMarkerStatus & status);
173 void write_track_info_toc (CDMarkerStatus & status);
175 void write_index_info_cue (CDMarkerStatus & status);
176 void write_index_info_toc (CDMarkerStatus & status);
178 void frames_to_cd_frames_string (char* buf, framepos_t when);
179 std::string toc_escape_cdtext (const std::string&);
180 std::string toc_escape_filename (const std::string&);
181 std::string cue_escape_cdtext (const std::string& txt);
187 } // namespace ARDOUR
189 #endif /* __ardour_export_handler_h__ */