Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
25 
26 #include <list>
27 #include <map>
28 #include <memory>
29 #include <stdexcept>
30 #include <string>
31 #include <vector>
32 
33 #include "pbd/file_utils.h"
34 #include "pbd/uuid.h"
35 #include "pbd/xml++.h"
36 
37 #include "ardour/export_handler.h"
40 #include "ardour/location.h"
41 #include "ardour/types.h"
42 
43 namespace ARDOUR
44 {
45 class ExportHandler;
46 class Location;
47 class Session;
48 
51 {
52 public:
53  enum ExportType {
58  StemExport
59  };
60 
63 
64  void load_profile ();
66 
67  ExportType type () const { return _type; }
68 
69  typedef std::list<ExportPresetPtr> PresetList;
70 
71  PresetList const& get_presets () { return preset_list; }
72  ExportPresetPtr preset () const { return current_preset; }
73 
75  ExportPresetPtr new_preset (std::string const& name);
76  ExportPresetPtr save_preset (std::string const& name);
77  void remove_preset ();
78 
79 private:
80  typedef std::shared_ptr<ExportHandler> HandlerPtr;
81 
82  typedef std::pair<PBD::UUID, std::string> FilePair;
83  typedef std::map<PBD::UUID, std::string> FileMap;
84 
86  std::string xml_node_name;
89 
90  std::string preset_filename (std::string const& preset_name);
91  void load_presets ();
92  void load_preset_from_disk (std::string const& path);
93 
94  bool set_state (XMLNode const& root);
95  bool set_global_state (XMLNode const& root);
96  bool set_local_state (XMLNode const& root);
97 
98  void serialize_profile (XMLNode& root);
101 
105 
106  std::vector<std::string> find_file (std::string const& pattern);
107 
108  std::string export_config_dir;
110 
111  /* Timespans */
112 public:
113  typedef std::list<ExportTimespanPtr> TimespanList;
114  typedef std::shared_ptr<TimespanList> TimespanListPtr;
115  typedef std::list<Location*> LocationList;
116 
117  enum TimeFormat {
122  };
123 
124  struct TimespanState {
127 
128  std::shared_ptr<Location> selection_range;
129  std::shared_ptr<LocationList> ranges;
130 
131  TimespanState (std::shared_ptr<Location> selection_range,
132  std::shared_ptr<LocationList> ranges)
133  : timespans (new TimespanList ())
134  , time_format (Timecode)
135  , selection_range (selection_range)
136  , ranges (ranges)
137  {
138  }
139  };
140 
141  typedef std::shared_ptr<TimespanState> TimespanStatePtr;
142  typedef std::list<TimespanStatePtr> TimespanStateList;
143 
145  std::string set_single_range (samplepos_t start, samplepos_t end, std::string name);
146 
147  TimespanStateList const& get_timespans () { return check_list (timespans); }
148 
149 private:
151 
153 
156 
157  /* Locations */
158  void update_ranges ();
159 
160  std::shared_ptr<Location> selection_range;
161  std::shared_ptr<LocationList> ranges;
162  std::shared_ptr<Location> single_range;
163 
165 
166  /* Channel Configs */
167 public:
170 
172  : config (ptr)
173  {
174  }
175  };
176 
177  typedef std::shared_ptr<ChannelConfigState> ChannelConfigStatePtr;
178  typedef std::list<ChannelConfigStatePtr> ChannelConfigStateList;
179 
180  ChannelConfigStateList const& get_channel_configs () { return check_list (channel_configs); }
181 
182  void clear_channel_configs () { channel_configs.clear (); }
183 
185 
186 private:
188 
190 
191  /* Formats */
192 public:
193  typedef std::list<ExportFormatSpecPtr> FormatList;
194 
195  struct FormatState {
196  std::shared_ptr<FormatList const> list;
198 
199  FormatState (std::shared_ptr<FormatList const> list, ExportFormatSpecPtr format)
200  : list (list)
201  , format (format)
202  {
203  }
204  };
205 
206  typedef std::shared_ptr<FormatState> FormatStatePtr;
207  typedef std::list<FormatStatePtr> FormatStateList;
208 
209  FormatStateList const& get_formats () { return check_list (formats); }
210 
213 
217 
219 
221 
222 private:
224 
225  bool init_formats (XMLNodeList nodes);
228 
229  void load_formats ();
230 
232  void load_format_from_disk (std::string const& path);
233 
234  std::shared_ptr<FormatList> format_list;
236 
237  /* Filenames */
238 public:
239  struct FilenameState {
241 
243  : filename (ptr)
244  {
245  }
246  };
247 
248  typedef std::shared_ptr<FilenameState> FilenameStatePtr;
249  typedef std::list<FilenameStatePtr> FilenameStateList;
250 
251  FilenameStateList const& get_filenames () { return check_list (filenames); }
252 
255 
257 
258 private:
260 
263 
264  /* Warnings */
265 public:
266  struct Warnings {
267  std::list<std::string> errors;
268  std::list<std::string> warnings;
269  std::list<std::string> conflicting_filenames;
270  };
271 
272  std::shared_ptr<Warnings> get_warnings ();
273 
274 private:
275  void check_config (std::shared_ptr<Warnings> warnings,
276  TimespanStatePtr timespan_state,
277  ExportChannelConfigPtr channel_config,
278  FormatStatePtr format_state,
279  FilenameStatePtr filename_state);
280 
281  bool check_format (ExportFormatSpecPtr format, uint32_t channels);
282  bool check_sndfile_format (ExportFormatSpecPtr format, unsigned int channels);
283 
284  /* Utilities */
285 
286  void build_filenames (std::list<std::string>& result, ExportFilenamePtr filename,
287  TimespanListPtr timespans, ExportChannelConfigPtr channel_config,
288  ExportFormatSpecPtr format);
289 
290  /* Element state lists should never be empty, this is used to check them */
291  template <typename T>
292  std::list<T> const&
293  check_list (std::list<T> const& list)
294  {
295  if (list.empty ()) {
296  throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
297  }
298  return list;
299  }
300 };
301 
302 } // namespace ARDOUR
303 
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
PBD::Signal< void()> FormatListChanged
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)
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:28
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