Ardour  8.12
export_format_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2009-2010 Sakari Bergen <sakari.bergen@beatwaves.net>
4  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __ardour_export_format_base_h__
23 #define __ardour_export_format_base_h__
24 
25 #include <memory>
26 #include <set>
27 #include <string>
28 
29 #include <sndfile.h>
30 #include <samplerate.h>
31 
32 #include "pbd/signals.h"
34 #include "ardour/types.h"
35 
37 
38 namespace ARDOUR
39 {
40 
42  public:
43 
44  enum Type {
45  T_None = 0,
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_MPEG = 0x230000, /* hardcode SF_FORMAT_MPEG from libsndfile 1.1.0+ */
62  F_FFMPEG = 0xF10000
63  };
64 
65  enum Endianness {
66  E_FileDefault = SF_ENDIAN_FILE, /* Default file endian-ness. */
67  E_Little = SF_ENDIAN_LITTLE, /* Force little endian-ness. */
68  E_Big = SF_ENDIAN_BIG, /* Force big endian-ness. */
69  E_Cpu = SF_ENDIAN_CPU /* Force CPU endian-ness. */
70  };
71 
72  enum SampleFormat {
73  SF_None = 0,
74  SF_8 = SF_FORMAT_PCM_S8,
75  SF_16 = SF_FORMAT_PCM_16,
76  SF_24 = SF_FORMAT_PCM_24,
77  SF_32 = SF_FORMAT_PCM_32,
78  SF_U8 = SF_FORMAT_PCM_U8,
79  SF_Float = SF_FORMAT_FLOAT,
80  SF_Double = SF_FORMAT_DOUBLE,
81  SF_Vorbis = SF_FORMAT_VORBIS,
82  SF_Opus = 0x0064, /* SF_FORMAT_OPUS */
83  SF_MPEG_LAYER_III = 0x0082 /* SF_FORMAT_MPEG_LAYER_III */
84  };
85 
86  enum DitherType {
91  };
92 
93  enum Quality {
94  Q_None = 0,
98  Q_LossyCompression
99  };
100 
101  enum SampleRate {
102  SR_None = 0,
103  SR_Session = 1,
104  SR_8 = 8000,
105  SR_22_05 = 22050,
106  SR_24 = 24000,
107  SR_44_1 = 44100,
108  SR_48 = 48000,
109  SR_88_2 = 88200,
110  SR_96 = 96000,
111  SR_176_4 = 176400,
112  SR_192 = 192000
113  };
114 
115  enum SRCQuality {
116  SRC_SincBest = SRC_SINC_BEST_QUALITY,
117  SRC_SincMedium = SRC_SINC_MEDIUM_QUALITY,
118  SRC_SincFast = SRC_SINC_FASTEST,
119  SRC_ZeroOrderHold = SRC_ZERO_ORDER_HOLD,
120  SRC_Linear = SRC_LINEAR
121  };
122 
125  public:
127  : _selected (false), _compatible (true) { }
129 
130  PBD::Signal1<void,bool> SelectChanged;
131  PBD::Signal1<void,bool> CompatibleChanged;
132 
133  bool selected () const { return _selected; }
134  bool compatible () const { return _compatible; }
135  std::string name () const { return _name; }
136 
137  void set_selected (bool value);
138  void set_compatible (bool value);
139 
140  protected:
141  void set_name (std::string name) { _name = name; }
142 
143  private:
144  bool _selected;
146 
147  std::string _name;
148  };
149 
150  public:
151 
154 
155  virtual ~ExportFormatBase ();
156 
157  std::shared_ptr<ExportFormatBase> get_intersection (ExportFormatBase const & other) const;
158  std::shared_ptr<ExportFormatBase> get_union (ExportFormatBase const & other) const;
159 
160  bool endiannesses_empty () const { return endiannesses.empty (); }
161  bool sample_formats_empty () const { return sample_formats.empty (); }
162  bool sample_rates_empty () const { return sample_rates.empty (); }
163  bool formats_empty () const { return format_ids.empty (); }
164  bool qualities_empty () const { return qualities.empty (); }
165 
166  bool has_endianness (Endianness endianness) const { return endiannesses.find (endianness) != endiannesses.end() ; }
167  bool has_sample_format (SampleFormat format) const { return sample_formats.find (format) != sample_formats.end(); }
168  bool has_sample_rate (SampleRate rate) const { return sample_rates.find (rate) != sample_rates.end(); }
169  bool has_format (FormatId format) const { return format_ids.find (format) != format_ids.end(); }
170  bool has_quality (Quality quality) const { return qualities.find (quality) != qualities.end(); }
171 
172  void set_extension (std::string const & extension) { _extension = extension; }
173  std::string const & extension () const { return _extension; }
174 
176 
177  protected:
178 
179  friend class HasSampleFormat;
180  typedef std::set<SampleFormat> SampleFormatSet;
182 
183  protected:
184  typedef std::set<Endianness> EndianSet;
185  typedef std::set<SampleRate> SampleRateSet;
186  typedef std::set<FormatId> FormatSet;
187  typedef std::set<Quality> QualitySet;
188 
193 
194  private:
195 
196  std::string _extension;
197 
200  SetIntersection
201  };
202 
203  std::shared_ptr<ExportFormatBase> do_set_operation (ExportFormatBase const & other, SetOperation operation) const;
204 };
205 
206 } // namespace ARDOUR
207 
208 #endif /* __ardour_export_format_base_h__ */
Class for managing selection and compatibility states.
bool has_quality(Quality quality) const
bool has_sample_format(SampleFormat format) const
std::set< Quality > QualitySet
bool has_endianness(Endianness endianness) const
std::shared_ptr< ExportFormatBase > get_intersection(ExportFormatBase const &other) const
std::set< SampleFormat > SampleFormatSet
std::shared_ptr< ExportFormatBase > do_set_operation(ExportFormatBase const &other, SetOperation operation) const
void set_extension(std::string const &extension)
std::set< FormatId > FormatSet
std::shared_ptr< ExportFormatBase > get_union(ExportFormatBase const &other) const
bool has_format(FormatId format) const
ExportFormatBase(ExportFormatBase const &other)
static SampleRate nearest_sample_rate(samplecnt_t sample_rate)
std::set< SampleRate > SampleRateSet
bool has_sample_rate(SampleRate rate) const
std::set< Endianness > EndianSet
std::string const & extension() const
Class to be inherited by export formats that have a selectable sample format.
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
Temporal::samplecnt_t samplecnt_t
@ D_Tri
Triangular dithering.
@ D_None
No didtering.
@ D_Shaped
Actually noise shaping, only works for 46kHzish signals.
@ D_Rect
Rectangular dithering, i.e. white noise.