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_profile_manager_h__
22 #define __ardour_export_profile_manager_h__
30 #include <boost/shared_ptr.hpp>
33 #include "pbd/file_utils.h"
34 #include "pbd/xml++.h"
36 #include "ardour/filesystem_paths.h"
37 #include "ardour/location.h"
38 #include "ardour/libardour_visibility.h"
39 #include "ardour/types.h"
40 #include "ardour/export_handler.h"
49 /// Manages (de)serialization of export profiles and related classes
50 class LIBARDOUR_API ExportProfileManager
62 ExportProfileManager (Session & s, ExportType type);
63 ~ExportProfileManager ();
66 void prepare_for_export ();
68 typedef std::list<ExportPresetPtr> PresetList;
70 PresetList const & get_presets () { return preset_list; }
71 bool load_preset (ExportPresetPtr preset);
72 ExportPresetPtr new_preset (std::string const & name);
73 ExportPresetPtr save_preset (std::string const & name);
74 void remove_preset ();
77 typedef boost::shared_ptr<ExportHandler> HandlerPtr;
79 typedef std::pair<PBD::UUID, std::string> FilePair;
80 typedef std::map<PBD::UUID, std::string> FileMap;
83 std::string xml_node_name;
87 std::string preset_filename (std::string const & preset_name);
89 void load_preset_from_disk (std::string const & path);
91 bool set_state (XMLNode const & root);
92 bool set_global_state (XMLNode const & root);
93 bool set_local_state (XMLNode const & root);
95 void serialize_profile (XMLNode & root);
96 void serialize_global_profile (XMLNode & root);
97 void serialize_local_profile (XMLNode & root);
99 PresetList preset_list;
100 ExportPresetPtr current_preset;
101 FileMap preset_file_map;
103 std::vector<std::string> find_file (std::string const & pattern);
105 std::string export_config_dir;
106 PBD::Searchpath search_path;
111 typedef std::list<ExportTimespanPtr> TimespanList;
112 typedef boost::shared_ptr<TimespanList> TimespanListPtr;
113 typedef std::list<Location *> LocationList;
122 struct TimespanState {
123 TimespanListPtr timespans;
124 TimeFormat time_format;
126 boost::shared_ptr<Location> selection_range;
127 boost::shared_ptr<LocationList> ranges;
129 TimespanState (boost::shared_ptr<Location> selection_range,
130 boost::shared_ptr<LocationList> ranges)
131 : timespans (new TimespanList ())
132 , time_format (Timecode)
133 , selection_range (selection_range)
138 typedef boost::shared_ptr<TimespanState> TimespanStatePtr;
139 typedef std::list<TimespanStatePtr> TimespanStateList;
141 void set_selection_range (framepos_t start = 0, framepos_t end = 0);
142 std::string set_single_range (framepos_t start, framepos_t end, std::string name);
143 TimespanStateList const & get_timespans () { return check_list (timespans); }
147 TimespanStateList timespans;
149 bool init_timespans (XMLNodeList nodes);
151 TimespanStatePtr deserialize_timespan (XMLNode & root);
152 XMLNode & serialize_timespan (TimespanStatePtr state);
156 void update_ranges ();
158 boost::shared_ptr<Location> selection_range;
159 boost::shared_ptr<LocationList> ranges;
161 bool single_range_mode;
162 boost::shared_ptr<Location> single_range;
164 /* Channel Configs */
167 struct ChannelConfigState {
168 ExportChannelConfigPtr config;
170 ChannelConfigState (ExportChannelConfigPtr ptr) : config (ptr) {}
172 typedef boost::shared_ptr<ChannelConfigState> ChannelConfigStatePtr;
173 typedef std::list<ChannelConfigStatePtr> ChannelConfigStateList;
175 ChannelConfigStateList const & get_channel_configs () { return check_list (channel_configs); }
176 void clear_channel_configs () { channel_configs.clear(); }
177 ChannelConfigStatePtr add_channel_config ();
181 ChannelConfigStateList channel_configs;
183 bool init_channel_configs (XMLNodeList nodes);
188 typedef std::list<ExportFormatSpecPtr> FormatList;
191 boost::shared_ptr<FormatList const> list;
192 ExportFormatSpecPtr format;
194 FormatState (boost::shared_ptr<FormatList const> list, ExportFormatSpecPtr format) :
195 list (list), format (format) {}
197 typedef boost::shared_ptr<FormatState> FormatStatePtr;
198 typedef std::list<FormatStatePtr> FormatStateList;
200 FormatStateList const & get_formats () { return check_list (formats); }
201 FormatStatePtr duplicate_format_state (FormatStatePtr state);
202 void remove_format_state (FormatStatePtr state);
204 std::string save_format_to_disk (ExportFormatSpecPtr format);
205 void remove_format_profile (ExportFormatSpecPtr format);
206 ExportFormatSpecPtr get_new_format (ExportFormatSpecPtr original);
208 PBD::Signal0<void> FormatListChanged;
212 FormatStateList formats;
214 bool init_formats (XMLNodeList nodes);
215 FormatStatePtr deserialize_format (XMLNode & root);
216 XMLNode & serialize_format (FormatStatePtr state);
218 void load_formats ();
220 ExportFormatSpecPtr load_format (XMLNode & node);
221 void load_format_from_disk (std::string const & path);
223 boost::shared_ptr<FormatList> format_list;
224 FileMap format_file_map;
229 struct FilenameState {
230 ExportFilenamePtr filename;
232 FilenameState (ExportFilenamePtr ptr) : filename (ptr) {}
234 typedef boost::shared_ptr<FilenameState> FilenameStatePtr;
235 typedef std::list<FilenameStatePtr> FilenameStateList;
237 FilenameStateList const & get_filenames () { return check_list (filenames); }
238 FilenameStatePtr duplicate_filename_state (FilenameStatePtr state);
239 void remove_filename_state (FilenameStatePtr state);
241 std::string get_sample_filename_for_format (ExportFilenamePtr filename, ExportFormatSpecPtr format);
245 FilenameStateList filenames;
247 bool init_filenames (XMLNodeList nodes);
248 ExportFilenamePtr load_filename (XMLNode & node);
253 std::list<std::string> errors;
254 std::list<std::string> warnings;
255 std::list<std::string> conflicting_filenames;
258 boost::shared_ptr<Warnings> get_warnings ();
261 void check_config (boost::shared_ptr<Warnings> warnings,
262 TimespanStatePtr timespan_state,
263 ChannelConfigStatePtr channel_config_state,
264 FormatStatePtr format_state,
265 FilenameStatePtr filename_state);
267 bool check_format (ExportFormatSpecPtr format, uint32_t channels);
268 bool check_sndfile_format (ExportFormatSpecPtr format, unsigned int channels);
272 void build_filenames(std::list<std::string> & result, ExportFilenamePtr filename,
273 TimespanListPtr timespans, ExportChannelConfigPtr channel_config,
274 ExportFormatSpecPtr format);
276 /* Element state lists should never be empty, this is used to check them */
279 check_list (std::list<T> const & list)
282 throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
290 } // namespace ARDOUR
292 #endif /* __ardour_export_profile_manager_h__ */