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