9a3c8c43f88b360ee7d52eef58c358d174cb2bb3
[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 <glibmm/ustring.h>
25
26 #include "pbd/uuid.h"
27
28 #include "ardour/types.h"
29 #include "ardour/export_format_base.h"
30
31 using std::string;
32
33 class XMLNode;
34
35 namespace ARDOUR
36 {
37
38 class ExportFormat;
39 class ExportFormatCompatibility;
40 class Session;
41
42 class ExportFormatSpecification : public ExportFormatBase {
43
44   private:
45
46         /* Time struct for keeping time formats as close as possible to what was requested */
47
48         struct Time : public AnyTime {
49                 Time (Session & session) : AnyTime (), session (session) {}
50                 Time & operator= (AnyTime const & other);
51         
52                 nframes_t get_frames (nframes_t target_rate) const;
53                 
54                 /* Serialization */
55                 
56                 XMLNode & get_state ();
57                 int set_state (const XMLNode & node);
58                 
59           private:
60                 Session & session;
61         };
62
63   private:
64         friend class ExportElementFactory;
65         explicit ExportFormatSpecification (Session & s);
66         ExportFormatSpecification (Session & s, XMLNode const & state);
67         
68   public:
69         ExportFormatSpecification (ExportFormatSpecification const & other);
70         ~ExportFormatSpecification ();
71
72         /* compatibility */
73         
74         bool is_compatible_with (ExportFormatCompatibility const & compatibility) const;
75         bool is_complete () const;
76
77         /* Modifying functions */
78         
79         void set_format (boost::shared_ptr<ExportFormat> format);
80
81         void set_name (Glib::ustring const & name) { _name = name; }
82
83         void set_type (Type type) { _type = type; }
84         void set_format_id (FormatId value) { format_ids.clear(); format_ids.insert (value); }
85         void set_endianness (Endianness value) { endiannesses.clear(); endiannesses.insert (value); }
86         void set_sample_format (SampleFormat value) { sample_formats.clear(); sample_formats.insert (value); }
87         void set_sample_rate (SampleRate value) { sample_rates.clear(); sample_rates.insert (value); }
88         void set_quality (Quality value) { qualities.clear(); qualities.insert (value); }
89         
90         void set_dither_type (DitherType value) { _dither_type = value; }
91         void set_src_quality (SRCQuality value) { _src_quality = value; }
92         void set_trim_beginning (bool value) { _trim_beginning = value; }
93         void set_trim_end (bool value) { _trim_end = value; }
94         void set_normalize (bool value) { _normalize = value; }
95         void set_normalize_target (float value) { _normalize_target = value; }
96         
97         void set_tag (bool tag_it) { _tag = tag_it; }
98         
99         void set_silence_beginning (AnyTime const & value) { _silence_beginning = value; }
100         void set_silence_end (AnyTime const & value) { _silence_end = value; }
101         
102         /* Accessing functions */
103         
104         PBD::UUID const & id () { return _id; }
105         Glib::ustring const & name () const { return _name; }
106         Glib::ustring description ();
107         
108         bool has_broadcast_info () const { return _has_broadcast_info; }
109         uint32_t channel_limit () const { return _channel_limit; }
110         Glib::ustring format_name () const { return _format_name; }
111         
112         Type type () const { return _type; }
113         FormatId format_id () const { return *format_ids.begin(); }
114         Endianness endianness () const { return *endiannesses.begin(); }
115         SampleFormat sample_format () const { return *sample_formats.begin(); }
116         SampleRate sample_rate () const { return *sample_rates.begin(); }
117         Quality quality () const { return *qualities.begin(); }
118
119         DitherType dither_type () const { return _dither_type; }
120         SRCQuality src_quality () const { return _src_quality; }
121         bool trim_beginning () const { return _trim_beginning; }
122         bool trim_end () const { return _trim_end; }
123         bool normalize () const { return _normalize; }
124         float normalize_target () const { return _normalize_target; }
125         
126         bool tag () const { return _tag && supports_tagging; }
127         
128         nframes_t silence_beginning () const { return _silence_beginning.get_frames (sample_rate()); }
129         nframes_t silence_end () const { return _silence_end.get_frames (sample_rate()); }
130         
131         AnyTime silence_beginning_time () const { return _silence_beginning; }
132         AnyTime silence_end_time () const { return _silence_end; }
133         
134         /* Serialization */
135         
136         XMLNode & get_state ();
137         int set_state (const XMLNode & root);
138
139         
140   private:
141         
142         Session &        session;
143         
144         /* The variables below do not have setters (usually set via set_format) */
145         
146         Glib::ustring  _format_name;
147         bool            has_sample_format;
148         bool            supports_tagging;
149         bool           _has_broadcast_info;
150         uint32_t       _channel_limit;
151         
152         /* The variables below have getters and setters */
153         
154         Glib::ustring   _name;
155         PBD::UUID       _id;
156         
157         Type            _type;
158         DitherType      _dither_type;
159         SRCQuality      _src_quality;
160         
161         bool            _tag;
162         
163         bool            _trim_beginning;
164         Time            _silence_beginning;
165         bool            _trim_end;
166         Time            _silence_end;
167         
168         bool            _normalize;
169         float           _normalize_target;
170         
171         /* serialization helpers */
172         
173         void add_option (XMLNode * node, std::string const & name, std::string const & value);
174         std::string get_option (XMLNode const * node, std::string const & name);
175
176 };
177
178 } // namespace ARDOUR
179
180 #endif /* __ardour_export_format_specification_h__ */