Remove most using declarations from header files.
[ardour.git] / libs / ardour / ardour / export_profile_manager.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_profile_manager_h__
22 #define __ardour_export_profile_manager_h__
23
24 #include <list>
25 #include <vector>
26 #include <map>
27 #include <stdexcept>
28
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
31 #include <sigc++/signal.h>
32 #include <glibmm/ustring.h>
33
34 #include "pbd/uuid.h"
35 #include "pbd/file_utils.h"
36 #include "pbd/xml++.h"
37
38 #include "ardour/filesystem_paths.h"
39 #include "ardour/location.h"
40 #include "ardour/types.h"
41
42 namespace ARDOUR
43 {
44
45 class ExportHandler;
46 class ExportTimespan;
47 class ExportChannelConfiguration;
48 class ExportFormatSpecification;
49 class ExportFilename;
50 class ExportPreset;
51 class Location;
52 class Session;
53
54 /// Manages (de)serialization of export profiles and related classes
55 class ExportProfileManager
56 {
57   public:
58
59         ExportProfileManager (Session & s);
60         ~ExportProfileManager ();
61
62         void load_profile ();
63         void prepare_for_export ();
64         
65         typedef boost::shared_ptr<ExportPreset> PresetPtr;
66         typedef std::list<PresetPtr> PresetList;
67         
68         PresetList const & get_presets () { return preset_list; }
69         bool load_preset (PresetPtr preset);
70         PresetPtr save_preset (std::string const & name);
71         void remove_preset ();
72
73   private:
74         typedef boost::shared_ptr<ExportHandler> HandlerPtr;
75
76         typedef std::pair<PBD::UUID, PBD::sys::path> FilePair;
77         typedef std::map<PBD::UUID, PBD::sys::path> FileMap;
78         
79         HandlerPtr  handler;
80         Session &   session;
81         
82         void load_presets ();
83         void load_preset_from_disk (PBD::sys::path const & path);
84         
85         bool set_state (XMLNode const & root);
86         bool set_global_state (XMLNode const & root);
87         bool set_local_state (XMLNode const & root);
88         
89         void serialize_profile (XMLNode & root);
90         void serialize_global_profile (XMLNode & root);
91         void serialize_local_profile (XMLNode & root);
92         
93         PresetList preset_list;
94         PresetPtr  current_preset;
95         FileMap    preset_file_map;
96         
97         std::vector<PBD::sys::path> find_file (std::string const & pattern);
98         
99         PBD::sys::path  export_config_dir;
100         PBD::SearchPath search_path;
101
102 /* Timespans */
103   public:
104
105         typedef boost::shared_ptr<ExportTimespan> TimespanPtr;
106         typedef std::list<TimespanPtr> TimespanList;
107         typedef boost::shared_ptr<TimespanList> TimespanListPtr;
108         typedef std::list<Location *> LocationList;
109
110         enum TimeFormat {
111                 SMPTE,
112                 BBT,
113                 MinSec,
114                 Frames,
115                 Off
116         };
117
118         struct TimespanState {
119                 TimespanListPtr timespans;
120                 TimeFormat      time_format;
121                 
122                 boost::shared_ptr<Location> session_range;
123                 boost::shared_ptr<Location> selection_range;
124                 boost::shared_ptr<LocationList> ranges;
125                 
126                 TimespanState (boost::shared_ptr<Location> session_range,
127                                boost::shared_ptr<Location> selection_range,
128                                boost::shared_ptr<LocationList> ranges) :
129                   timespans (new TimespanList ()),
130                   time_format (SMPTE),
131                 
132                   session_range (session_range),
133                   selection_range (selection_range),
134                   ranges (ranges)
135                 {}
136         };
137         
138         typedef boost::shared_ptr<TimespanState> TimespanStatePtr;
139         typedef std::list<TimespanStatePtr> TimespanStateList;
140         
141         void set_selection_range (nframes_t start = 0, nframes_t end = 0);
142         std::string set_single_range (nframes_t start, nframes_t end, Glib::ustring 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         
158         boost::shared_ptr<Location>     session_range;
159         boost::shared_ptr<Location>     selection_range;
160         boost::shared_ptr<LocationList> ranges;
161         
162         bool                            single_range_mode;
163         boost::shared_ptr<Location>     single_range;
164
165 /* Channel Configs */
166   public:
167
168         typedef boost::shared_ptr<ExportChannelConfiguration> ChannelConfigPtr;
169
170         struct ChannelConfigState {
171                 ChannelConfigPtr config;
172                 
173                 ChannelConfigState (ChannelConfigPtr ptr) : config (ptr) {}
174         };
175         typedef boost::shared_ptr<ChannelConfigState> ChannelConfigStatePtr;
176         typedef std::list<ChannelConfigStatePtr> ChannelConfigStateList;
177         
178         ChannelConfigStateList const & get_channel_configs () { return check_list (channel_configs); }
179
180   private:
181
182         ChannelConfigStateList channel_configs;
183
184         bool init_channel_configs (XMLNodeList nodes);
185
186 /* Formats */
187   public:
188
189         typedef boost::shared_ptr<ExportFormatSpecification> FormatPtr;
190         typedef std::list<FormatPtr> FormatList;
191
192         struct FormatState {
193                 boost::shared_ptr<FormatList const> list;
194                 FormatPtr                           format;
195                 
196                 FormatState (boost::shared_ptr<FormatList const> list, FormatPtr format) :
197                   list (list), format (format) {}
198         };
199         typedef boost::shared_ptr<FormatState> FormatStatePtr;
200         typedef std::list<FormatStatePtr> FormatStateList;
201         
202         FormatStateList const & get_formats () { return check_list (formats); }
203         FormatStatePtr duplicate_format_state (FormatStatePtr state);
204         void remove_format_state (FormatStatePtr state);
205         
206         PBD::sys::path save_format_to_disk (FormatPtr format);
207         void remove_format_profile (FormatPtr format);
208         FormatPtr get_new_format (FormatPtr original);
209         
210         sigc::signal<void> FormatListChanged;
211
212   private:
213
214         FormatStateList formats;
215
216         bool init_formats (XMLNodeList nodes);
217         FormatStatePtr deserialize_format (XMLNode & root);
218         XMLNode & serialize_format (FormatStatePtr state);
219
220         void load_formats ();
221         
222         FormatPtr load_format (XMLNode & node);
223         void load_format_from_disk (PBD::sys::path const & path);
224
225         boost::shared_ptr<FormatList> format_list;
226         FileMap                       format_file_map;
227         
228 /* Filenames */
229   public:
230         
231         typedef boost::shared_ptr<ExportFilename> FilenamePtr;
232         
233         struct FilenameState {
234                 FilenamePtr  filename;
235                 
236                 FilenameState (FilenamePtr ptr) : filename (ptr) {}
237         };
238         typedef boost::shared_ptr<FilenameState> FilenameStatePtr;
239         typedef std::list<FilenameStatePtr> FilenameStateList;
240         
241         FilenameStateList const & get_filenames () { return check_list (filenames); }
242         FilenameStatePtr duplicate_filename_state (FilenameStatePtr state);
243         void remove_filename_state (FilenameStatePtr state);
244
245   private:
246
247         FilenameStateList filenames;
248         
249         bool init_filenames (XMLNodeList nodes);
250         FilenamePtr load_filename (XMLNode & node);
251
252 /* Warnings */
253   public:
254         struct Warnings {
255                 std::list<Glib::ustring> errors;
256                 std::list<Glib::ustring> warnings;
257                 std::list<Glib::ustring> conflicting_filenames;
258         };
259         
260         boost::shared_ptr<Warnings> get_warnings ();
261         
262   private:
263         void check_config (boost::shared_ptr<Warnings> warnings,
264                            TimespanStatePtr timespan_state,
265                            ChannelConfigStatePtr channel_config_state,
266                            FormatStatePtr format_state,
267                            FilenameStatePtr filename_state);
268
269  /* Utilities */
270
271         /* Element state lists should never be empty, this is used to check them */
272         template<typename T>
273         std::list<T> const &
274         check_list (std::list<T> const & list)
275         {
276                 if (list.empty()) {
277                         throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
278                 }
279                 return list;
280         }
281
282 };
283
284
285 } // namespace ARDOUR
286
287 #endif /* __ardour_export_profile_manager_h__ */