prepare fix for copying plugin state
[ardour.git] / libs / ardour / ardour / export_format_specification.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_format_specification_h__
22 #define __ardour_export_format_specification_h__
23
24 #include <string>
25
26 #include "pbd/uuid.h"
27
28 #include "ardour/libardour_visibility.h"
29 #include "ardour/types.h"
30 #include "ardour/export_format_base.h"
31
32 class XMLNode;
33
34 namespace ARDOUR
35 {
36
37 class ExportFormat;
38 class ExportFormatCompatibility;
39 class Session;
40
41 class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase {
42
43   private:
44
45         /* Time struct for keeping time formats as close as possible to what was requested */
46
47         struct Time : public AnyTime {
48                 Time (Session & session) : AnyTime (), session (session) {}
49                 Time & operator= (AnyTime const & other);
50
51                 framecnt_t get_frames_at (framepos_t position, framecnt_t target_rate) const;
52
53                 /* Serialization */
54
55                 XMLNode & get_state ();
56                 int set_state (const XMLNode & node);
57
58           private:
59                 Session & session;
60         };
61
62   private:
63         friend class ExportElementFactory;
64         explicit ExportFormatSpecification (Session & s);
65         ExportFormatSpecification (Session & s, XMLNode const & state);
66
67   public:
68         ExportFormatSpecification (ExportFormatSpecification const & other, bool modify_name = true);
69         ~ExportFormatSpecification ();
70
71         /* compatibility */
72
73         bool is_compatible_with (ExportFormatCompatibility const & compatibility) const;
74         bool is_complete () const;
75
76         /* Modifying functions */
77
78         void set_format (boost::shared_ptr<ExportFormat> format);
79
80         void set_name (std::string const & name) { _name = name; }
81
82         void set_type (Type type) { _type = type; }
83         void set_format_id (FormatId value) { format_ids.clear(); format_ids.insert (value); }
84         void set_endianness (Endianness value) { endiannesses.clear(); endiannesses.insert (value); }
85         void set_sample_format (SampleFormat value) { sample_formats.clear(); sample_formats.insert (value); }
86         void set_sample_rate (SampleRate value) { sample_rates.clear(); sample_rates.insert (value); }
87         void set_quality (Quality value) { qualities.clear(); qualities.insert (value); }
88
89         void set_dither_type (DitherType value) { _dither_type = value; }
90         void set_src_quality (SRCQuality value) { _src_quality = value; }
91         void set_trim_beginning (bool value) { _trim_beginning = value; }
92         void set_trim_end (bool value) { _trim_end = value; }
93         void set_normalize (bool value) { _normalize = value; }
94         void set_normalize_target (float value) { _normalize_target = value; }
95
96         void set_tag (bool tag_it) { _tag = tag_it; }
97         void set_with_cue (bool yn) { _with_cue = yn; }
98         void set_with_toc (bool yn) { _with_toc = yn; }
99         void set_with_mp4chaps (bool yn) { _with_mp4chaps = yn; }
100         void set_soundcloud_upload (bool yn) { _soundcloud_upload = yn; }
101         void set_command (std::string command) { _command = command; }
102         void set_analyse (bool yn) { _analyse = yn; }
103
104         void set_silence_beginning (AnyTime const & value) { _silence_beginning = value; }
105         void set_silence_end (AnyTime const & value) { _silence_end = value; }
106
107         /* Accessing functions */
108
109         PBD::UUID const & id () { return _id; }
110         std::string const & name () const { return _name; }
111         std::string description (bool include_name = true);
112
113         bool has_broadcast_info () const { return _has_broadcast_info; }
114         uint32_t channel_limit () const { return _channel_limit; }
115         std::string format_name () const { return _format_name; }
116
117         Type type () const { return _type; }
118
119         FormatId format_id () const {
120                 if (!format_ids.empty() )
121                         return *format_ids.begin();
122                 else
123                         return FormatId(0);
124         }
125
126         Endianness endianness () const {
127                 if (!endiannesses.empty() )
128                         return *endiannesses.begin();
129                 else
130                         return Endianness(0);
131         }
132
133         SampleFormat sample_format () const {
134                 if (!sample_formats.empty() )
135                         return *sample_formats.begin();
136                 else
137                         return SampleFormat(0);
138         }
139
140         SampleRate sample_rate () const {
141                 if (!sample_rates.empty() )
142                         return *sample_rates.begin();
143                 else
144                         return SampleRate(0);
145
146         }
147
148         Quality quality () const {
149                 if (!qualities.empty() )
150                         return *qualities.begin();
151                 else
152                         return Quality(0);
153         }
154
155         DitherType dither_type () const { return _dither_type; }
156         SRCQuality src_quality () const { return _src_quality; }
157         bool trim_beginning () const { return _trim_beginning; }
158         bool trim_end () const { return _trim_end; }
159         bool normalize () const { return _normalize; }
160         float normalize_target () const { return _normalize_target; }
161         bool with_toc() const { return _with_toc; }
162         bool with_cue() const { return _with_cue; }
163         bool with_mp4chaps() const { return _with_mp4chaps; }
164
165         bool soundcloud_upload() const { return _soundcloud_upload; }
166         std::string command() const { return _command; }
167         bool analyse() const { return _analyse; }
168
169         bool tag () const { return _tag && supports_tagging; }
170
171         framecnt_t silence_beginning_at (framepos_t position, framecnt_t samplerate) const
172                 { return _silence_beginning.get_frames_at (position, samplerate); }
173         framecnt_t silence_end_at (framepos_t position, framecnt_t samplerate) const
174                 { return _silence_end.get_frames_at (position, samplerate); }
175
176         AnyTime silence_beginning_time () const { return _silence_beginning; }
177         AnyTime silence_end_time () const { return _silence_end; }
178
179         /* Serialization */
180
181         XMLNode & get_state ();
182         int set_state (const XMLNode & root);
183
184
185   private:
186
187         Session &        session;
188
189         /* The variables below do not have setters (usually set via set_format) */
190
191         std::string  _format_name;
192         bool            has_sample_format;
193         bool            supports_tagging;
194         bool           _has_broadcast_info;
195         uint32_t       _channel_limit;
196
197         /* The variables below have getters and setters */
198
199         std::string   _name;
200         PBD::UUID       _id;
201
202         Type            _type;
203         DitherType      _dither_type;
204         SRCQuality      _src_quality;
205
206         bool            _tag;
207
208         bool            _trim_beginning;
209         Time            _silence_beginning;
210         bool            _trim_end;
211         Time            _silence_end;
212
213         bool            _normalize;
214         float           _normalize_target;
215         bool            _with_toc;
216         bool            _with_cue;
217         bool            _with_mp4chaps;
218         bool            _soundcloud_upload;
219
220         std::string     _command;
221         bool            _analyse;
222
223         /* serialization helpers */
224
225         void add_option (XMLNode * node, std::string const & name, std::string const & value);
226         std::string get_option (XMLNode const * node, std::string const & name);
227
228 };
229
230 } // namespace ARDOUR
231
232 #endif /* __ardour_export_format_specification_h__ */