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