Ardour  8.12
export_formats.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2010 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2018-2019 Robin Gareus <robin@gareus.org>
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_formats_h__
23 #define __ardour_export_formats_h__
24 
25 #include <list>
26 #include <memory>
27 
28 #include "pbd/failed_constructor.h"
29 #include "pbd/signals.h"
30 
33 
34 namespace ARDOUR {
35 
37 {
38 public:
39  virtual const char* what () const throw ()
40  {
41  return "Export format constructor failed: Format incompatible with system";
42  }
43 };
44 
47 {
48 public:
51 
52  virtual bool set_compatibility_state (ExportFormatCompatibility const& compatibility) = 0;
53 
54  virtual Type get_type () const = 0;
55 
57  {
58  return *format_ids.begin ();
59  }
60 
62  {
63  return *qualities.begin ();
64  }
65 
68 
70 
71  /* If the format has a specific sample format, this function should be overridden
72  * if the format has a selectable sample format, do not override this!
73  */
75  {
76  return SF_None;
77  }
78 
79  /* If the above is not overridden, this one should be */
81  {
82  return SF_None;
83  }
84 
85  /* If the format has a channel count limit, override this */
86  virtual uint32_t get_channel_limit () const
87  {
88  return 256;
89  }
90 
91  /* If the format can be tagged with metadata override this */
92  virtual bool supports_tagging () const
93  {
94  return false;
95  }
96 
97  /* If the format contains broadcast info override this */
98  virtual bool has_broadcast_info () const
99  {
100  return false;
101  }
102 
103 protected:
105  {
106  sample_rates.insert (rate);
107  }
108 
109  void add_endianness (Endianness endianness)
110  {
111  endiannesses.insert (endianness);
112  }
113 
115  {
116  format_ids.clear ();
117  format_ids.insert (id);
118  }
119 
120  void set_quality (Quality value)
121  {
122  qualities.clear ();
123  qualities.insert (value);
124  }
125 };
126 
128 {
129 public:
130  struct CodecQuality {
131  CodecQuality (std::string const& n, int q)
132  : name (n)
133  , quality (q)
134  {}
135 
136  std::string name;
137  int quality;
138  };
139 
140  typedef std::shared_ptr<CodecQuality> CodecQualityPtr;
141  typedef std::list<CodecQualityPtr> CodecQualityList;
142 
143  virtual ~HasCodecQuality () {}
144 
145  void add_codec_quality (std::string const& name, int q)
146  {
147  CodecQualityPtr ptr (new CodecQuality (name, q));
148  _codec_qualties.push_back (ptr);
149  }
150 
152  {
153  return _codec_qualties;
154  }
155 
156  virtual int default_codec_quality () const = 0;
157 
158 protected:
160 };
161 
164 {
165 public:
167  {
168  public:
170  : format (format)
171  {
172  set_name (name);
173  }
174 
176  };
177 
179  {
180  public:
182  : type (type)
183  {
184  set_name (name);
185  }
186 
188  };
189 
190  typedef std::shared_ptr<SampleFormatState> SampleFormatPtr;
191  typedef std::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
192  typedef std::list<SampleFormatPtr> SampleFormatList;
193 
194  typedef std::shared_ptr<DitherTypeState> DitherTypePtr;
195  typedef std::weak_ptr<DitherTypeState> WeakDitherTypePtr;
196  typedef std::list<DitherTypePtr> DitherTypeList;
197 
198 public:
200  virtual ~HasSampleFormat (){};
201 
203 
205  {
206  return sample_format_states;
207  }
208 
210  {
211  return dither_type_states;
212  }
213 
216 
217  /* Proxies for signals from sample formats and dither types */
218  PBD::Signal2<void, bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
219  PBD::Signal2<void, bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
220 
221  PBD::Signal2<void, bool, WeakDitherTypePtr> DitherTypeSelectChanged;
222  PBD::Signal2<void, bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
223 
225 
226 protected:
227  /* State lists */
230 
231 private:
232  /* Connected to signals */
236 
237  /* Reference to ExportFormatBase::sample_formats */
239 };
240 
242 {
243 public:
244  ExportFormatLinear (std::string name, FormatId format_id);
246 
248  Type get_type () const
249  {
250  return T_Sndfile;
251  }
252 
253  void add_endianness (Endianness endianness)
254  {
255  endiannesses.insert (endianness);
256  }
257 
259  {
260  _default_sample_format = sf;
261  }
262 
264  {
265  return _default_sample_format;
266  }
267 
268 protected:
270 };
271 
273 {
274 public:
275  ExportFormatTaggedLinear (std::string name, FormatId format_id)
276  : ExportFormatLinear (name, format_id)
277  {
278  }
279 
280  virtual bool supports_tagging () const
281  {
282  return true;
283  }
284 };
285 
287 {
288 public:
291 
293  Type get_type () const
294  {
295  return T_Sndfile;
296  }
298  {
299  return SF_Vorbis;
300  }
301  virtual bool supports_tagging () const
302  {
303  return true;
304  }
306  {
307  return 40;
308  }
309 };
310 
312 {
313 public:
316 
318  Type get_type () const
319  {
320  return T_Sndfile;
321  }
322  uint32_t get_channel_limit () const
323  {
324  return 8;
325  }
327  {
328  return SF_16;
329  }
330  virtual bool supports_tagging () const
331  {
332  return true;
333  }
334 };
335 
337 {
338 public:
341 
343 
344  Type get_type () const
345  {
346  return T_Sndfile;
347  }
349  {
350  return SF_16;
351  }
352  virtual bool has_broadcast_info () const
353  {
354  return true;
355  }
356 };
357 
359 {
360 public:
363 
365 
366  Type get_type () const
367  {
368  return T_Sndfile;
369  }
371  {
372  return SF_Opus;
373  }
375  {
376  return 49;
377  }
378  virtual bool supports_tagging () const
379  {
380  return true;
381  }
382 };
383 
385 {
386 public:
387  ExportFormatMPEG (std::string const& name, std::string const& ext);
389 
391 
392  Type get_type () const
393  {
394  return T_Sndfile;
395  }
397  {
398  return SF_MPEG_LAYER_III;
399  }
401  {
402  return 40;
403  }
404  virtual bool supports_tagging () const
405  {
406  return true;
407  }
408 };
409 
411 {
412 public:
413  ExportFormatFFMPEG (std::string const& name, std::string const& ext);
415 
417 
418  Type get_type () const
419  {
420  return T_FFMPEG;
421  }
423  {
424  return SF_Float;
425  }
427  {
428  return -2;
429  }
430  virtual bool supports_tagging () const
431  {
432  return true;
433  }
434 };
435 
436 } // namespace ARDOUR
437 
438 #endif /* __ardour_export_formats__ */
virtual bool has_broadcast_info() const
SampleFormat default_sample_format() const
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
Class for managing selection and compatibility states.
std::set< SampleFormat > SampleFormatSet
Allows adding to all sets. A format should be able to test if it is compatible with this.
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
virtual bool supports_tagging() const
ExportFormatFFMPEG(std::string const &name, std::string const &ext)
SampleFormat get_explicit_sample_format() const
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
uint32_t get_channel_limit() const
virtual bool supports_tagging() const
SampleFormat default_sample_format() const
virtual const char * what() const
ExportFormatLinear(std::string name, FormatId format_id)
void add_endianness(Endianness endianness)
void set_default_sample_format(SampleFormat sf)
SampleFormat default_sample_format() const
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
SampleFormat _default_sample_format
virtual bool supports_tagging() const
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
int default_codec_quality() const
SampleFormat default_sample_format() const
ExportFormatMPEG(std::string const &name, std::string const &ext)
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
SampleFormat get_explicit_sample_format() const
virtual bool supports_tagging() const
virtual bool supports_tagging() const
SampleFormat get_explicit_sample_format() const
bool set_compatibility_state(ExportFormatCompatibility const &compatibility)
virtual bool supports_tagging() const
ExportFormatTaggedLinear(std::string name, FormatId format_id)
Base class for formats.
virtual uint32_t get_channel_limit() const
void add_sample_rate(SampleRate rate)
void set_quality(Quality value)
FormatId get_format_id() const
Quality get_quality() const
void set_format_id(FormatId id)
void add_endianness(Endianness endianness)
bool sample_format_is_compatible(SampleFormat format) const
virtual ExportFormat::SampleFormat default_sample_format() const
virtual Type get_type() const =0
virtual SampleFormat get_explicit_sample_format() const
virtual bool has_broadcast_info() const
virtual bool supports_tagging() const
virtual bool set_compatibility_state(ExportFormatCompatibility const &compatibility)=0
std::shared_ptr< CodecQuality > CodecQualityPtr
std::list< CodecQualityPtr > CodecQualityList
CodecQualityList _codec_qualties
CodecQualityList const & get_codec_qualities() const
void add_codec_quality(std::string const &name, int q)
virtual int default_codec_quality() const =0
ExportFormatBase::DitherType type
DitherTypeState(ExportFormatBase::DitherType type, Glib::ustring name)
ExportFormatBase::SampleFormat format
SampleFormatState(ExportFormatBase::SampleFormat format, std::string name)
Class to be inherited by export formats that have a selectable sample format.
std::weak_ptr< DitherTypeState > WeakDitherTypePtr
PBD::Signal2< void, bool, WeakDitherTypePtr > DitherTypeSelectChanged
void add_dither_type(ExportFormatBase::DitherType type, std::string name)
DitherTypeList dither_type_states
SampleFormatList const & get_sample_formats() const
std::shared_ptr< DitherTypeState > DitherTypePtr
DitherTypeList const & get_dither_types() const
std::weak_ptr< SampleFormatState > WeakSampleFormatPtr
PBD::Signal2< void, bool, WeakSampleFormatPtr > SampleFormatCompatibleChanged
DitherTypePtr get_selected_dither_type()
std::list< SampleFormatPtr > SampleFormatList
ExportFormatBase::SampleFormatSet & _sample_formats
std::shared_ptr< SampleFormatState > SampleFormatPtr
SampleFormatPtr get_selected_sample_format()
PBD::Signal2< void, bool, WeakDitherTypePtr > DitherTypeCompatibleChanged
std::list< DitherTypePtr > DitherTypeList
PBD::Signal2< void, bool, WeakSampleFormatPtr > SampleFormatSelectChanged
void update_sample_format_selection(bool)
static std::string get_sample_format_name(ExportFormatBase::SampleFormat format)
void update_dither_type_selection(bool)
void add_sample_format(ExportFormatBase::SampleFormat format)
HasSampleFormat(ExportFormatBase::SampleFormatSet &sample_formats)
SampleFormatList sample_format_states
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
CodecQuality(std::string const &n, int q)