ardour
export_profile_manager.h
Go to the documentation of this file.
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_profile_manager_h__
22 #define __ardour_export_profile_manager_h__
23 
24 #include <list>
25 #include <vector>
26 #include <map>
27 #include <stdexcept>
28 #include <string>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "pbd/uuid.h"
33 #include "pbd/file_utils.h"
34 #include "pbd/xml++.h"
35 
37 #include "ardour/location.h"
39 #include "ardour/types.h"
40 #include "ardour/export_handler.h"
41 
42 namespace ARDOUR
43 {
44 
45 class ExportHandler;
46 class Location;
47 class Session;
48 
51 {
52  public:
53 
54  enum ExportType {
59  StemExport
60  };
61 
62  ExportProfileManager (Session & s, ExportType type);
64 
65  void load_profile ();
66  void prepare_for_export ();
67 
68  typedef std::list<ExportPresetPtr> PresetList;
69 
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 ();
75 
76  private:
78 
79  typedef std::pair<PBD::UUID, std::string> FilePair;
80  typedef std::map<PBD::UUID, std::string> FileMap;
81 
83  std::string xml_node_name;
84  HandlerPtr handler;
86 
87  std::string preset_filename (std::string const & preset_name);
88  void load_presets ();
89  void load_preset_from_disk (std::string const & path);
90 
91  bool set_state (XMLNode const & root);
92  bool set_global_state (XMLNode const & root);
93  bool set_local_state (XMLNode const & root);
94 
95  void serialize_profile (XMLNode & root);
96  void serialize_global_profile (XMLNode & root);
97  void serialize_local_profile (XMLNode & root);
98 
99  PresetList preset_list;
102 
103  std::vector<std::string> find_file (std::string const & pattern);
104 
105  std::string export_config_dir;
107 
108 /* Timespans */
109  public:
110 
111  typedef std::list<ExportTimespanPtr> TimespanList;
113  typedef std::list<Location *> LocationList;
114 
115  enum TimeFormat {
120  };
121 
122  struct TimespanState {
123  TimespanListPtr timespans;
125 
128 
131  : timespans (new TimespanList ())
132  , time_format (Timecode)
133  , selection_range (selection_range)
134  , ranges (ranges)
135  {}
136  };
137 
139  typedef std::list<TimespanStatePtr> TimespanStateList;
140 
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); }
144 
145  private:
146 
147  TimespanStateList timespans;
148 
149  bool init_timespans (XMLNodeList nodes);
150 
151  TimespanStatePtr deserialize_timespan (XMLNode & root);
152  XMLNode & serialize_timespan (TimespanStatePtr state);
153 
154  /* Locations */
155 
156  void update_ranges ();
157 
160 
163 
164 /* Channel Configs */
165  public:
166 
169 
171  };
173  typedef std::list<ChannelConfigStatePtr> ChannelConfigStateList;
174 
175  ChannelConfigStateList const & get_channel_configs () { return check_list (channel_configs); }
176  void clear_channel_configs () { channel_configs.clear(); }
177  ChannelConfigStatePtr add_channel_config ();
178 
179  private:
180 
181  ChannelConfigStateList channel_configs;
182 
183  bool init_channel_configs (XMLNodeList nodes);
184 
185 /* Formats */
186  public:
187 
188  typedef std::list<ExportFormatSpecPtr> FormatList;
189 
190  struct FormatState {
193 
195  list (list), format (format) {}
196  };
198  typedef std::list<FormatStatePtr> FormatStateList;
199 
200  FormatStateList const & get_formats () { return check_list (formats); }
201  FormatStatePtr duplicate_format_state (FormatStatePtr state);
202  void remove_format_state (FormatStatePtr state);
203 
204  std::string save_format_to_disk (ExportFormatSpecPtr format);
205  void remove_format_profile (ExportFormatSpecPtr format);
206  ExportFormatSpecPtr get_new_format (ExportFormatSpecPtr original);
207 
208  PBD::Signal0<void> FormatListChanged;
209 
210  private:
211 
212  FormatStateList formats;
213 
214  bool init_formats (XMLNodeList nodes);
215  FormatStatePtr deserialize_format (XMLNode & root);
216  XMLNode & serialize_format (FormatStatePtr state);
217 
218  void load_formats ();
219 
220  ExportFormatSpecPtr load_format (XMLNode & node);
221  void load_format_from_disk (std::string const & path);
222 
225 
226 /* Filenames */
227  public:
228 
229  struct FilenameState {
231 
232  FilenameState (ExportFilenamePtr ptr) : filename (ptr) {}
233  };
235  typedef std::list<FilenameStatePtr> FilenameStateList;
236 
237  FilenameStateList const & get_filenames () { return check_list (filenames); }
238  FilenameStatePtr duplicate_filename_state (FilenameStatePtr state);
239  void remove_filename_state (FilenameStatePtr state);
240 
241  std::string get_sample_filename_for_format (ExportFilenamePtr filename, ExportFormatSpecPtr format);
242 
243  private:
244 
245  FilenameStateList filenames;
246 
247  bool init_filenames (XMLNodeList nodes);
248  ExportFilenamePtr load_filename (XMLNode & node);
249 
250 /* Warnings */
251  public:
252  struct Warnings {
253  std::list<std::string> errors;
254  std::list<std::string> warnings;
255  std::list<std::string> conflicting_filenames;
256  };
257 
258  boost::shared_ptr<Warnings> get_warnings ();
259 
260  private:
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);
266 
267  bool check_format (ExportFormatSpecPtr format, uint32_t channels);
268  bool check_sndfile_format (ExportFormatSpecPtr format, unsigned int channels);
269 
270  /* Utilities */
271 
272  void build_filenames(std::list<std::string> & result, ExportFilenamePtr filename,
273  TimespanListPtr timespans, ExportChannelConfigPtr channel_config,
274  ExportFormatSpecPtr format);
275 
276  /* Element state lists should never be empty, this is used to check them */
277  template<typename T>
278  std::list<T> const &
279  check_list (std::list<T> const & list)
280  {
281  if (list.empty()) {
282  throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
283  }
284  return list;
285  }
286 
287 };
288 
289 
290 } // namespace ARDOUR
291 
292 #endif /* __ardour_export_profile_manager_h__ */
boost::shared_ptr< ExportHandler > HandlerPtr
boost::shared_ptr< TimespanState > TimespanStatePtr
std::list< FilenameStatePtr > FilenameStateList
boost::shared_ptr< FormatList > format_list
std::list< TimespanStatePtr > TimespanStateList
std::list< T > const & check_list(std::list< T > const &list)
FormatStateList const & get_formats()
boost::shared_ptr< ChannelConfigState > ChannelConfigStatePtr
std::map< PBD::UUID, std::string > FileMap
std::list< ExportPresetPtr > PresetList
boost::shared_ptr< FilenameState > FilenameStatePtr
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
ChannelConfigStateList channel_configs
ChannelConfigStateList const & get_channel_configs()
bool find_file(const Searchpath &search_path, const string &filename, std::string &result)
Definition: file_utils.cc:187
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
FilenameStateList const & get_filenames()
TimespanStateList const & get_timespans()
TimespanState(boost::shared_ptr< Location > selection_range, boost::shared_ptr< LocationList > ranges)
Definition: amp.h:29
Manages (de)serialization of export profiles and related classes.
boost::shared_ptr< TimespanList > TimespanListPtr
int64_t framepos_t
Definition: types.h:66
boost::shared_ptr< FormatState > FormatStatePtr
#define LIBARDOUR_API
FormatState(boost::shared_ptr< FormatList const > list, ExportFormatSpecPtr format)
const char * name
std::pair< PBD::UUID, std::string > FilePair
Definition: xml++.h:95
std::list< ExportFormatSpecPtr > FormatList
std::list< ExportTimespanPtr > TimespanList
boost::shared_ptr< FormatList const > list
boost::shared_ptr< Location > single_range
std::list< Location * > LocationList
PBD::Signal0< void > FormatListChanged
boost::shared_ptr< Location > selection_range
std::list< ChannelConfigStatePtr > ChannelConfigStateList
boost::shared_ptr< LocationList > ranges
std::list< FormatStatePtr > FormatStateList