Remove ambiguous API implementation
[ardour.git] / libs / ardour / ardour / export_formats.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_formats_h__
22 #define __ardour_export_formats_h__
23
24 #include <list>
25 #include <boost/weak_ptr.hpp>
26
27 #include "pbd/failed_constructor.h"
28 #include "pbd/signals.h"
29
30 #include "ardour/export_format_base.h"
31 #include "ardour/export_format_compatibility.h"
32
33 namespace ARDOUR
34 {
35
36 class LIBARDOUR_API ExportFormatIncompatible : public failed_constructor {
37   public:
38         virtual const char *what() const throw() { return "Export format constructor failed: Format incompatible with system"; }
39 };
40
41 /// Base class for formats
42 class LIBARDOUR_API ExportFormat : public ExportFormatBase, public ExportFormatBase::SelectableCompatible {
43
44   public:
45         ExportFormat () {};
46         ~ExportFormat () {};
47
48         virtual bool set_compatibility_state (ExportFormatCompatibility const & compatibility) = 0;
49         virtual Type get_type () const = 0;
50
51         FormatId get_format_id () const { return *format_ids.begin(); }
52         Quality get_quality () const { return *qualities.begin(); }
53
54         bool has_sample_format ();
55         bool has_codec_quality ();
56
57         bool sample_format_is_compatible (SampleFormat format) const;
58
59         /* If the format has a specific sample format, this function should be overridden
60          * if the format has a selectable sample format, do not override this!
61          */
62
63         virtual SampleFormat get_explicit_sample_format () const { return SF_None; }
64
65         /* If the above is not overridden, this one should be */
66
67         virtual ExportFormat::SampleFormat default_sample_format () const { return SF_None; }
68
69         /* If the format has a channel count limit, override this */
70
71         virtual uint32_t get_channel_limit () const { return 256; }
72
73         /* If the format can be tagged with metadata override this */
74
75         virtual bool supports_tagging () const { return false; }
76
77         /* If the format contains broadcast info override this */
78
79         virtual bool has_broadcast_info () const { return false; }
80
81
82   protected:
83
84         void add_sample_rate (SampleRate rate) { sample_rates.insert (rate); }
85         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
86
87         void set_format_id (FormatId id) { format_ids.clear (); format_ids.insert (id); }
88         void set_quality (Quality value) { qualities.clear(); qualities.insert (value); }
89 };
90
91 class LIBARDOUR_API HasCodecQuality {
92 public:
93         struct CodecQuality {
94                 CodecQuality (std::string const& n, int q)
95                         : name (n)
96                         , quality (q)
97                 {}
98
99                 std::string name;
100                 int         quality;
101         };
102
103         typedef boost::shared_ptr<CodecQuality> CodecQualityPtr;
104         typedef std::list<CodecQualityPtr> CodecQualityList;
105
106         virtual ~HasCodecQuality () {}
107
108         void add_codec_quality (std::string const& name, int q) {
109                 CodecQualityPtr ptr (new CodecQuality (name, q));
110                 _codec_qualties.push_back (ptr);
111         }
112
113         CodecQualityList const & get_codec_qualities () const {
114                 return _codec_qualties;
115         }
116
117         virtual int default_codec_quality () const = 0;
118
119 protected:
120         CodecQualityList _codec_qualties;
121 };
122
123 /// Class to be inherited by export formats that have a selectable sample format
124 class LIBARDOUR_API HasSampleFormat : public PBD::ScopedConnectionList {
125   public:
126
127         class SampleFormatState : public ExportFormatBase::SelectableCompatible {
128           public:
129                 SampleFormatState (ExportFormatBase::SampleFormat format, std::string name)
130                         : format (format)
131                 {
132                         set_name (name);
133                 }
134
135                 ExportFormatBase::SampleFormat  format;
136         };
137
138         class DitherTypeState : public ExportFormatBase::SelectableCompatible {
139           public:
140                 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
141                   type (type) { set_name (name); }
142
143                 ExportFormatBase::DitherType  type;
144         };
145
146         typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
147         typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
148         typedef std::list<SampleFormatPtr> SampleFormatList;
149
150         typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
151         typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
152         typedef std::list<DitherTypePtr> DitherTypeList;
153
154   public:
155
156         HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
157         virtual ~HasSampleFormat () {};
158
159         void add_sample_format (ExportFormatBase::SampleFormat format);
160
161         SampleFormatList const & get_sample_formats () const { return sample_format_states; }
162         DitherTypeList const & get_dither_types () const { return dither_type_states; }
163
164         SampleFormatPtr get_selected_sample_format ();
165         DitherTypePtr get_selected_dither_type ();
166
167         /* Proxies for signals from sample formats and dither types */
168
169         PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
170         PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
171
172         PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeSelectChanged;
173         PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
174
175         static std::string get_sample_format_name (ExportFormatBase::SampleFormat format);
176
177   protected:
178         /* State lists */
179
180         DitherTypeList    dither_type_states;
181         SampleFormatList  sample_format_states;
182
183   private:
184         /* Connected to signals */
185
186         void add_dither_type (ExportFormatBase::DitherType type, std::string name);
187         void update_sample_format_selection (bool);
188         void update_dither_type_selection (bool);
189
190         /* Reference to ExportFormatBase::sample_formats */
191         ExportFormatBase::SampleFormatSet & _sample_formats;
192 };
193
194 class LIBARDOUR_API ExportFormatLinear : public ExportFormat, public HasSampleFormat {
195   public:
196
197         ExportFormatLinear (std::string name, FormatId format_id);
198         ~ExportFormatLinear () {};
199
200         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
201         Type get_type () const { return T_Sndfile; }
202
203         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
204
205         void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
206         SampleFormat default_sample_format () const { return _default_sample_format; }
207
208   protected:
209         SampleFormat _default_sample_format;
210 };
211
212 class LIBARDOUR_API ExportFormatOggVorbis : public ExportFormat, public HasCodecQuality {
213   public:
214         ExportFormatOggVorbis ();
215         ~ExportFormatOggVorbis () {};
216
217         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
218         Type get_type () const { return T_Sndfile; }
219         SampleFormat get_explicit_sample_format () const { return SF_Vorbis; }
220         virtual bool supports_tagging () const { return true; }
221
222         int default_codec_quality () const { return 40; }
223 };
224
225 class LIBARDOUR_API ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
226   public:
227         ExportFormatFLAC ();
228         ~ExportFormatFLAC () {};
229
230         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
231         Type get_type () const { return T_Sndfile; }
232
233         uint32_t get_channel_limit () const { return 8; }
234         SampleFormat default_sample_format () const { return SF_16; }
235         virtual bool supports_tagging () const { return true; }
236 };
237
238 class LIBARDOUR_API ExportFormatBWF : public ExportFormat, public HasSampleFormat {
239   public:
240         ExportFormatBWF ();
241         ~ExportFormatBWF () {};
242
243         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
244         Type get_type () const { return T_Sndfile; }
245
246         SampleFormat default_sample_format () const { return SF_16; }
247         virtual bool has_broadcast_info () const { return true; }
248 };
249
250
251 class LIBARDOUR_API ExportFormatFFMPEG : public ExportFormat, public HasCodecQuality {
252   public:
253         ExportFormatFFMPEG (std::string const& name, std::string const& ext);
254         ~ExportFormatFFMPEG () {};
255
256         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
257         Type get_type () const { return T_FFMPEG; }
258         SampleFormat get_explicit_sample_format () const { return SF_Float; }
259         int default_codec_quality () const { return -2; }
260 };
261
262 } // namespace ARDOUR
263
264 #endif /* __ardour_export_formats__ */