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