Re-integrate export-optimization branch.
[ardour.git] / libs / ardour / ardour / export_format_base.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_base_h__
22 #define __ardour_export_format_base_h__
23
24 #include <set>
25 #include <algorithm>
26 #include <boost/shared_ptr.hpp>
27 #include <glibmm/ustring.h>
28
29 #include <sndfile.h>
30 #include <samplerate.h>
31
32 #include "ardour/ardour.h"
33
34 #include "audiographer/sample_format_converter.h"
35
36 namespace ARDOUR
37 {
38
39 class HasSampleFormat;
40
41 class ExportFormatBase {
42   public:
43
44         enum Type {
45                 T_None = 0,
46                 T_Sndfile
47         };
48
49         enum FormatId {
50                 F_None = 0,
51                 F_WAV = SF_FORMAT_WAV,
52                 F_W64 = SF_FORMAT_W64,
53                 F_AIFF = SF_FORMAT_AIFF,
54                 F_AU = SF_FORMAT_AU,
55                 F_IRCAM = SF_FORMAT_IRCAM,
56                 F_RAW = SF_FORMAT_RAW,
57                 F_FLAC = SF_FORMAT_FLAC,
58                 F_Ogg = SF_FORMAT_OGG
59         };
60
61         enum Endianness {
62                 E_FileDefault = SF_ENDIAN_FILE, /* Default file endian-ness. */
63                 E_Little = SF_ENDIAN_LITTLE,    /* Force little endian-ness. */
64                 E_Big = SF_ENDIAN_BIG,          /* Force big endian-ness. */
65                 E_Cpu = SF_ENDIAN_CPU           /* Force CPU endian-ness. */
66         };
67
68         enum SampleFormat {
69                 SF_None = 0,
70                 SF_8 = SF_FORMAT_PCM_S8,
71                 SF_16 = SF_FORMAT_PCM_16,
72                 SF_24 = SF_FORMAT_PCM_24,
73                 SF_32 = SF_FORMAT_PCM_32,
74                 SF_U8 = SF_FORMAT_PCM_U8,
75                 SF_Float = SF_FORMAT_FLOAT,
76                 SF_Double = SF_FORMAT_DOUBLE,
77                 SF_Vorbis = SF_FORMAT_VORBIS
78         };
79
80         enum DitherType {
81                 D_None = AudioGrapher::D_None,
82                 D_Rect = AudioGrapher::D_Rect,
83                 D_Tri = AudioGrapher::D_Tri,
84                 D_Shaped = AudioGrapher::D_Shaped
85         };
86
87         enum Quality {
88                 Q_None = 0,
89                 Q_Any,
90                 Q_LosslessLinear,
91                 Q_LosslessCompression,
92                 Q_LossyCompression
93         };
94
95         enum SampleRate {
96                 SR_None = 0,
97                 SR_22_05 = 220500,
98                 SR_44_1 = 44100,
99                 SR_48 = 48000,
100                 SR_88_2 = 88200,
101                 SR_96 = 96000,
102                 SR_192 = 192000
103         };
104
105         enum SRCQuality {
106                 SRC_SincBest = SRC_SINC_BEST_QUALITY,
107                 SRC_SincMedium = SRC_SINC_MEDIUM_QUALITY,
108                 SRC_SincFast = SRC_SINC_FASTEST,
109                 SRC_ZeroOrderHold = SRC_ZERO_ORDER_HOLD,
110                 SRC_Linear = SRC_LINEAR
111         };
112
113         /// Class for managing selection and compatibility states
114         class SelectableCompatible {
115           public:
116                 SelectableCompatible ()
117                         : _selected (false), _compatible (true) { }
118                 ~SelectableCompatible () {}
119
120                 PBD::Signal1<void,bool> SelectChanged;
121                 PBD::Signal1<void,bool> CompatibleChanged;
122
123                 bool selected () const { return _selected; }
124                 bool compatible () const { return _compatible; }
125                 Glib::ustring name () const { return _name; }
126
127                 void set_selected (bool value);
128                 void set_compatible (bool value);
129
130           protected:
131                 void set_name (Glib::ustring name) { _name = name; }
132
133           private:
134                 bool _selected;
135                 bool _compatible;
136
137                 Glib::ustring _name;
138         };
139
140   public:
141
142         ExportFormatBase ();
143         ExportFormatBase (ExportFormatBase const & other);
144
145         virtual ~ExportFormatBase ();
146
147         boost::shared_ptr<ExportFormatBase> get_intersection (ExportFormatBase const & other) const;
148         boost::shared_ptr<ExportFormatBase> get_difference (ExportFormatBase const & other) const;
149         boost::shared_ptr<ExportFormatBase> get_union (ExportFormatBase const & other) const;
150
151         bool endiannesses_empty () const { return endiannesses.empty (); }
152         bool sample_formats_empty () const { return sample_formats.empty (); }
153         bool sample_rates_empty () const { return sample_rates.empty (); }
154         bool formats_empty () const { return format_ids.empty (); }
155         bool qualities_empty () const { return qualities.empty (); }
156
157         bool has_endianness (Endianness endianness) const { return endiannesses.find (endianness) != endiannesses.end() ; }
158         bool has_sample_format (SampleFormat format) const { return sample_formats.find (format) != sample_formats.end(); }
159         bool has_sample_rate (SampleRate rate) const { return sample_rates.find (rate) != sample_rates.end(); }
160         bool has_format (FormatId format) const { return format_ids.find (format) != format_ids.end(); }
161         bool has_quality (Quality quality) const { return qualities.find (quality) != qualities.end(); }
162
163         void set_extension (Glib::ustring const & extension) { _extension = extension; }
164         Glib::ustring const & extension () const { return _extension; }
165
166   protected:
167
168         friend class HasSampleFormat;
169         typedef std::set<SampleFormat> SampleFormatSet;
170         SampleFormatSet sample_formats;
171
172   protected:
173         typedef std::set<Endianness> EndianSet;
174         typedef std::set<SampleRate> SampleRateSet;
175         typedef std::set<FormatId> FormatSet;
176         typedef std::set<Quality> QualitySet;
177
178         EndianSet       endiannesses;
179         SampleRateSet   sample_rates;
180         FormatSet       format_ids;
181         QualitySet      qualities;
182
183   private:
184
185         Glib::ustring  _extension;
186
187         enum SetOperation {
188                 SetUnion,
189                 SetDifference,
190                 SetIntersection
191         };
192
193         boost::shared_ptr<ExportFormatBase> do_set_operation (ExportFormatBase const & other, SetOperation operation) const;
194 };
195
196 } // namespace ARDOUR
197
198 #endif /* __ardour_export_format_base_h__ */