Remove over 500 unnecessary includes (including 54 of session.h).
[ardour.git] / libs / ardour / ardour / export_handler.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __ardour_export_handler_h__
22 #define __ardour_export_handler_h__
23
24 #include <map>
25 #include <fstream>
26
27 #include <boost/operators.hpp>
28 #include <boost/shared_ptr.hpp>
29
30 #include "ardour/export_pointers.h"
31 #include "ardour/session.h"
32 #include "ardour/types.h"
33
34 namespace AudioGrapher {
35         class BroadcastInfo;
36 }
37
38 namespace ARDOUR
39 {
40
41 class ExportTimespan;
42 class ExportChannelConfiguration;
43 class ExportFormatSpecification;
44 class ExportFilename;
45 class ExportGraphBuilder;
46 class Location;
47
48 class ExportElementFactory
49 {
50   public:
51
52         ExportElementFactory (Session & session);
53         ~ExportElementFactory ();
54
55         ExportTimespanPtr add_timespan ();
56
57         ExportChannelConfigPtr add_channel_config ();
58
59         ExportFormatSpecPtr    add_format ();
60         ExportFormatSpecPtr    add_format (XMLNode const & state);
61         ExportFormatSpecPtr    add_format_copy (ExportFormatSpecPtr other);
62
63         ExportFilenamePtr      add_filename ();
64         ExportFilenamePtr      add_filename_copy (ExportFilenamePtr other);
65
66   private:
67         Session & session;
68 };
69
70 class ExportHandler : public ExportElementFactory
71 {
72   public:
73         struct FileSpec {
74                 FileSpec() {}
75                 FileSpec (ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format,
76                           ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
77                   : channel_config (channel_config)
78                   , format (format)
79                   , filename (filename)
80                   , broadcast_info (broadcast_info)
81                         {}
82
83                 ExportChannelConfigPtr channel_config;
84                 ExportFormatSpecPtr        format;
85                 ExportFilenamePtr      filename;
86                 BroadcastInfoPtr       broadcast_info;
87         };
88
89   private:
90
91         /* Stuff for export configs
92          * The multimap maps timespans to file specifications
93          */
94
95         typedef std::pair<ExportTimespanPtr, FileSpec> ConfigPair;
96         typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
97
98         typedef boost::shared_ptr<ExportGraphBuilder> GraphBuilderPtr;
99
100   private:
101         /* Session::get_export_handler() should be used to obtain an export handler
102          * This ensures that it doesn't go out of scope before finalize_audio_export is called
103          */
104
105         friend boost::shared_ptr<ExportHandler> Session::get_export_handler();
106         ExportHandler (Session & session);
107
108   public:
109         ~ExportHandler ();
110
111         bool add_export_config (ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config,
112                                 ExportFormatSpecPtr format, ExportFilenamePtr filename,
113                                 BroadcastInfoPtr broadcast_info);
114         void do_export (bool rt = false);
115
116         std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
117
118   private:
119
120         int process (framecnt_t frames);
121
122         Session &          session;
123         GraphBuilderPtr    graph_builder;
124         ExportStatusPtr    export_status;
125         ConfigMap          config_map;
126
127         bool               realtime;
128         bool               normalizing;
129
130         /* Timespan management */
131
132         void start_timespan ();
133         int  process_timespan (framecnt_t frames);
134         int  process_normalize ();
135         void finish_timespan ();
136
137         typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
138         ExportTimespanPtr     current_timespan;
139         TimespanBounds        timespan_bounds;
140
141         PBD::ScopedConnection process_connection;
142         framepos_t             process_position;
143
144         /* CD Marker stuff */
145
146         struct CDMarkerStatus {
147                 CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
148                                 ExportFormatSpecPtr format, std::string filename)
149                   : out (out_file.c_str()), timespan (timespan), format (format), filename (filename), marker(0)
150                   , track_number (1), track_position (0), track_duration (0), track_start_frame (0)
151                   , index_number (1), index_position (0)
152                   {}
153
154                 /* General info */
155                 std::ofstream  out;
156                 ExportTimespanPtr   timespan;
157                 ExportFormatSpecPtr format;
158                 std::string         filename;
159                 Location *          marker;
160
161                 /* Track info */
162                 uint32_t        track_number;
163                 framepos_t      track_position;
164                 framepos_t      track_duration;
165                 framepos_t      track_start_frame;
166
167                 /* Index info */
168                 uint32_t       index_number;
169                 framepos_t      index_position;
170         };
171
172
173         void export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSpecPtr file_format,
174                                     std::string filename, CDMarkerFormat format);
175
176         void write_cue_header (CDMarkerStatus & status);
177         void write_toc_header (CDMarkerStatus & status);
178
179         void write_track_info_cue (CDMarkerStatus & status);
180         void write_track_info_toc (CDMarkerStatus & status);
181
182         void write_index_info_cue (CDMarkerStatus & status);
183         void write_index_info_toc (CDMarkerStatus & status);
184
185         void frames_to_cd_frames_string (char* buf, framepos_t when);
186         std::string toc_escape_cdtext (const std::string&);
187         std::string toc_escape_filename (const std::string&);
188         std::string cue_escape_cdtext (const std::string& txt);
189
190         int cue_tracknum;
191         int cue_indexnum;
192 };
193
194 } // namespace ARDOUR
195
196 #endif /* __ardour_export_handler_h__ */