Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
23 
24 #include <memory>
25 #include <set>
26 #include <string>
27 
28 #include <sndfile.h>
29 #include <samplerate.h>
30 
31 #include "pbd/signals.h"
33 #include "ardour/types.h"
34 
36 
37 namespace ARDOUR
38 {
39 
41  public:
42 
43  enum Type {
44  T_None = 0,
46  T_FFMPEG
47  };
48 
49  enum FormatId {
50  F_None = 0,
51  F_WAV = SF_FORMAT_WAV,
52  F_W64 = SF_FORMAT_W64,
53  F_CAF = SF_FORMAT_CAF,
54  F_AIFF = SF_FORMAT_AIFF,
55  F_AU = SF_FORMAT_AU,
56  F_IRCAM = SF_FORMAT_IRCAM,
57  F_RAW = SF_FORMAT_RAW,
58  F_FLAC = SF_FORMAT_FLAC,
59  F_Ogg = SF_FORMAT_OGG,
60  F_MPEG = 0x230000, /* hardcode SF_FORMAT_MPEG from libsndfile 1.1.0+ */
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  SF_Opus = 0x0064, /* SF_FORMAT_OPUS */
82  SF_MPEG_LAYER_III = 0x0082 /* SF_FORMAT_MPEG_LAYER_III */
83  };
84 
85  enum DitherType {
90  };
91 
92  enum Quality {
93  Q_None = 0,
97  Q_LossyCompression
98  };
99 
100  enum SampleRate {
101  SR_None = 0,
102  SR_Session = 1,
103  SR_8 = 8000,
104  SR_22_05 = 22050,
105  SR_24 = 24000,
106  SR_44_1 = 44100,
107  SR_48 = 48000,
108  SR_88_2 = 88200,
109  SR_96 = 96000,
110  SR_176_4 = 176400,
111  SR_192 = 192000
112  };
113 
114  enum SRCQuality {
115  SRC_SincBest = SRC_SINC_BEST_QUALITY,
116  SRC_SincMedium = SRC_SINC_MEDIUM_QUALITY,
117  SRC_SincFast = SRC_SINC_FASTEST,
118  SRC_ZeroOrderHold = SRC_ZERO_ORDER_HOLD,
119  SRC_Linear = SRC_LINEAR
120  };
121 
124  public:
126  : _selected (false), _compatible (true) { }
128 
131 
132  bool selected () const { return _selected; }
133  bool compatible () const { return _compatible; }
134  std::string name () const { return _name; }
135 
136  void set_selected (bool value);
137  void set_compatible (bool value);
138 
139  protected:
140  void set_name (std::string name) { _name = name; }
141 
142  private:
143  bool _selected;
145 
146  std::string _name;
147  };
148 
149  public:
150 
153 
154  virtual ~ExportFormatBase ();
155 
156  std::shared_ptr<ExportFormatBase> get_intersection (ExportFormatBase const & other) const;
157  std::shared_ptr<ExportFormatBase> get_union (ExportFormatBase const & other) const;
158 
159  bool endiannesses_empty () const { return endiannesses.empty (); }
160  bool sample_formats_empty () const { return sample_formats.empty (); }
161  bool sample_rates_empty () const { return sample_rates.empty (); }
162  bool formats_empty () const { return format_ids.empty (); }
163  bool qualities_empty () const { return qualities.empty (); }
164 
165  bool has_endianness (Endianness endianness) const { return endiannesses.find (endianness) != endiannesses.end() ; }
166  bool has_sample_format (SampleFormat format) const { return sample_formats.find (format) != sample_formats.end(); }
167  bool has_sample_rate (SampleRate rate) const { return sample_rates.find (rate) != sample_rates.end(); }
168  bool has_format (FormatId format) const { return format_ids.find (format) != format_ids.end(); }
169  bool has_quality (Quality quality) const { return qualities.find (quality) != qualities.end(); }
170 
171  void set_extension (std::string const & extension) { _extension = extension; }
172  std::string const & extension () const { return _extension; }
173 
175 
176  protected:
177 
178  friend class HasSampleFormat;
179  typedef std::set<SampleFormat> SampleFormatSet;
181 
182  protected:
183  typedef std::set<Endianness> EndianSet;
184  typedef std::set<SampleRate> SampleRateSet;
185  typedef std::set<FormatId> FormatSet;
186  typedef std::set<Quality> QualitySet;
187 
192 
193  private:
194 
195  std::string _extension;
196 
199  SetIntersection
200  };
201 
202  std::shared_ptr<ExportFormatBase> do_set_operation (ExportFormatBase const & other, SetOperation operation) const;
203 };
204 
205 } // namespace ARDOUR
206 
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.