Ardour  8.12
export_profile_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2013 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
6  * Copyright (C) 2012-2013 Tim Mayberry <mojofunk@gmail.com>
7  * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef __ardour_export_profile_manager_h__
25 #define __ardour_export_profile_manager_h__
26 
27 #include <list>
28 #include <map>
29 #include <memory>
30 #include <stdexcept>
31 #include <string>
32 #include <vector>
33 
34 #include "pbd/file_utils.h"
35 #include "pbd/uuid.h"
36 #include "pbd/xml++.h"
37 
38 #include "ardour/export_handler.h"
41 #include "ardour/location.h"
42 #include "ardour/types.h"
43 
44 namespace ARDOUR
45 {
46 class ExportHandler;
47 class Location;
48 class Session;
49 
52 {
53 public:
54  enum ExportType {
59  StemExport
60  };
61 
64 
65  void load_profile ();
67 
68  ExportType type () const { return _type; }
69 
70  typedef std::list<ExportPresetPtr> PresetList;
71 
72  PresetList const& get_presets () { return preset_list; }
73  ExportPresetPtr preset () const { return current_preset; }
74 
76  ExportPresetPtr new_preset (std::string const& name);
77  ExportPresetPtr save_preset (std::string const& name);
78  void remove_preset ();
79 
80 private:
81  typedef std::shared_ptr<ExportHandler> HandlerPtr;
82 
83  typedef std::pair<PBD::UUID, std::string> FilePair;
84  typedef std::map<PBD::UUID, std::string> FileMap;
85 
87  std::string xml_node_name;
90 
91  std::string preset_filename (std::string const& preset_name);
92  void load_presets ();
93  void load_preset_from_disk (std::string const& path);
94 
95  bool set_state (XMLNode const& root);
96  bool set_global_state (XMLNode const& root);
97  bool set_local_state (XMLNode const& root);
98 
99  void serialize_profile (XMLNode& root);
102 
106 
107  std::vector<std::string> find_file (std::string const& pattern);
108 
109  std::string export_config_dir;
111 
112  /* Timespans */
113 public:
114  typedef std::list<ExportTimespanPtr> TimespanList;
115  typedef std::shared_ptr<TimespanList> TimespanListPtr;
116  typedef std::list<Location*> LocationList;
117 
118  enum TimeFormat {
123  };
124 
125  struct TimespanState {
128 
129  std::shared_ptr<Location> selection_range;
130  std::shared_ptr<LocationList> ranges;
131 
132  TimespanState (std::shared_ptr<Location> selection_range,
133  std::shared_ptr<LocationList> ranges)
134  : timespans (new TimespanList ())
135  , time_format (Timecode)
136  , selection_range (selection_range)
137  , ranges (ranges)
138  {
139  }
140  };
141 
142  typedef std::shared_ptr<TimespanState> TimespanStatePtr;
143  typedef std::list<TimespanStatePtr> TimespanStateList;
144 
146  std::string set_single_range (samplepos_t start, samplepos_t end, std::string name);
147 
148  TimespanStateList const& get_timespans () { return check_list (timespans); }
149 
150 private:
152 
154 
157 
158  /* Locations */
159  void update_ranges ();
160 
161  std::shared_ptr<Location> selection_range;
162  std::shared_ptr<LocationList> ranges;
163  std::shared_ptr<Location> single_range;
164 
166 
167  /* Channel Configs */
168 public:
171 
173  : config (ptr)
174  {
175  }
176  };
177 
178  typedef std::shared_ptr<ChannelConfigState> ChannelConfigStatePtr;
179  typedef std::list<ChannelConfigStatePtr> ChannelConfigStateList;
180 
181  ChannelConfigStateList const& get_channel_configs () { return check_list (channel_configs); }
182 
183  void clear_channel_configs () { channel_configs.clear (); }
184 
186 
187 private:
189 
191 
192  /* Formats */
193 public:
194  typedef std::list<ExportFormatSpecPtr> FormatList;
195 
196  struct FormatState {
197  std::shared_ptr<FormatList const> list;
199 
200  FormatState (std::shared_ptr<FormatList const> list, ExportFormatSpecPtr format)
201  : list (list)
202  , format (format)
203  {
204  }
205  };
206 
207  typedef std::shared_ptr<FormatState> FormatStatePtr;
208  typedef std::list<FormatStatePtr> FormatStateList;
209 
210  FormatStateList const& get_formats () { return check_list (formats); }
211 
214 
218 
220 
221  PBD::Signal0<void> FormatListChanged;
222 
223 private:
225 
226  bool init_formats (XMLNodeList nodes);
229 
230  void load_formats ();
231 
233  void load_format_from_disk (std::string const& path);
234 
235  std::shared_ptr<FormatList> format_list;
237 
238  /* Filenames */
239 public:
240  struct FilenameState {
242 
244  : filename (ptr)
245  {
246  }
247  };
248 
249  typedef std::shared_ptr<FilenameState> FilenameStatePtr;
250  typedef std::list<FilenameStatePtr> FilenameStateList;
251 
252  FilenameStateList const& get_filenames () { return check_list (filenames); }
253 
256 
258 
259 private:
261 
264 
265  /* Warnings */
266 public:
267  struct Warnings {
268  std::list<std::string> errors;
269  std::list<std::string> warnings;
270  std::list<std::string> conflicting_filenames;
271  };
272 
273  std::shared_ptr<Warnings> get_warnings ();
274 
275 private:
276  void check_config (std::shared_ptr<Warnings> warnings,
277  TimespanStatePtr timespan_state,
278  ExportChannelConfigPtr channel_config,
279  FormatStatePtr format_state,
280  FilenameStatePtr filename_state);
281 
282  bool check_format (ExportFormatSpecPtr format, uint32_t channels);
283  bool check_sndfile_format (ExportFormatSpecPtr format, unsigned int channels);
284 
285  /* Utilities */
286 
287  void build_filenames (std::list<std::string>& result, ExportFilenamePtr filename,
288  TimespanListPtr timespans, ExportChannelConfigPtr channel_config,
289  ExportFormatSpecPtr format);
290 
291  /* Element state lists should never be empty, this is used to check them */
292  template <typename T>
293  std::list<T> const&
294  check_list (std::list<T> const& list)
295  {
296  if (list.empty ()) {
297  throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
298  }
299  return list;
300  }
301 };
302 
303 } // namespace ARDOUR
304 
305 #endif /* __ardour_export_profile_manager_h__ */
Manages (de)serialization of export profiles and related classes.
void remove_format_profile(ExportFormatSpecPtr format)
bool init_channel_configs(XMLNodeList nodes)
FormatStatePtr deserialize_format(XMLNode &root)
std::shared_ptr< Location > single_range
std::list< ExportPresetPtr > PresetList
ChannelConfigStatePtr add_channel_config()
XMLNode & serialize_timespan(TimespanStatePtr state)
std::list< Location * > LocationList
bool set_state(XMLNode const &root)
void serialize_global_profile(XMLNode &root)
void serialize_profile(XMLNode &root)
bool init_timespans(XMLNodeList nodes)
ChannelConfigStateList channel_configs
std::shared_ptr< Warnings > get_warnings()
std::shared_ptr< ChannelConfigState > ChannelConfigStatePtr
ExportProfileManager(Session &s, ExportType type)
bool check_sndfile_format(ExportFormatSpecPtr format, unsigned int channels)
std::list< FormatStatePtr > FormatStateList
std::shared_ptr< FormatList > format_list
std::list< ExportFormatSpecPtr > FormatList
bool init_formats(XMLNodeList nodes)
bool set_global_state(XMLNode const &root)
std::map< PBD::UUID, std::string > FileMap
std::list< FilenameStatePtr > FilenameStateList
void serialize_local_profile(XMLNode &root)
bool check_format(ExportFormatSpecPtr format, uint32_t channels)
ExportPresetPtr preset() const
FormatStatePtr duplicate_format_state(FormatStatePtr state)
std::list< T > const & check_list(std::list< T > const &list)
std::string save_format_to_disk(ExportFormatSpecPtr format)
std::string preset_filename(std::string const &preset_name)
std::shared_ptr< LocationList > ranges
std::pair< PBD::UUID, std::string > FilePair
FilenameStatePtr duplicate_filename_state(FilenameStatePtr state)
ExportFilenamePtr load_filename(XMLNode &node)
std::string get_sample_filename_for_format(ExportFilenamePtr filename, ExportFormatSpecPtr format)
std::shared_ptr< TimespanState > TimespanStatePtr
std::list< ChannelConfigStatePtr > ChannelConfigStateList
std::string set_single_range(samplepos_t start, samplepos_t end, std::string name)
void check_config(std::shared_ptr< Warnings > warnings, TimespanStatePtr timespan_state, ExportChannelConfigPtr channel_config, FormatStatePtr format_state, FilenameStatePtr filename_state)
std::list< ExportTimespanPtr > TimespanList
FilenameStateList const & get_filenames()
void remove_format_state(FormatStatePtr state)
bool set_local_state(XMLNode const &root)
ChannelConfigStateList const & get_channel_configs()
ExportPresetPtr new_preset(std::string const &name)
void remove_filename_state(FilenameStatePtr state)
std::shared_ptr< ExportHandler > HandlerPtr
std::vector< std::string > find_file(std::string const &pattern)
ExportFormatSpecPtr load_format(XMLNode &node)
std::shared_ptr< TimespanList > TimespanListPtr
std::list< TimespanStatePtr > TimespanStateList
void revert_format_profile(ExportFormatSpecPtr format)
void set_selection_range(samplepos_t start=0, samplepos_t end=0)
TimespanStatePtr deserialize_timespan(XMLNode &root)
bool load_preset(ExportPresetPtr preset)
TimespanStateList const & get_timespans()
std::shared_ptr< Location > selection_range
ExportPresetPtr save_preset(std::string const &name)
std::shared_ptr< FormatState > FormatStatePtr
bool init_filenames(XMLNodeList nodes)
std::shared_ptr< FilenameState > FilenameStatePtr
FormatStateList const & get_formats()
XMLNode & serialize_format(FormatStatePtr state)
ExportFormatSpecPtr get_new_format(ExportFormatSpecPtr original)
void load_format_from_disk(std::string const &path)
void build_filenames(std::list< std::string > &result, ExportFilenamePtr filename, TimespanListPtr timespans, ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format)
void load_preset_from_disk(std::string const &path)
PBD::Signal0< void > FormatListChanged
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
PBD::PropertyDescriptor< timepos_t > start
std::shared_ptr< ExportPreset > ExportPresetPtr
std::shared_ptr< ExportFilename > ExportFilenamePtr
std::shared_ptr< ExportChannelConfiguration > ExportChannelConfigPtr
std::shared_ptr< ExportFormatSpecification > ExportFormatSpecPtr
Temporal::samplepos_t samplepos_t
Definition: time.h:29
FormatState(std::shared_ptr< FormatList const > list, ExportFormatSpecPtr format)
std::shared_ptr< FormatList const > list
TimespanState(std::shared_ptr< Location > selection_range, std::shared_ptr< LocationList > ranges)
std::vector< XMLNode * > XMLNodeList
Definition: xml++.h:66