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 <set> 26 #include <string> 27 28 #include <boost/shared_ptr.hpp> 29 30 #include <sndfile.h> 31 #include <samplerate.h> 32 33 #include "pbd/signals.h" 34 #include "ardour/libardour_visibility.h" 35 #include "ardour/types.h" 36 37 #include "audiographer/general/sample_format_converter.h" 38 39 namespace ARDOUR 40 { 41 42 class LIBARDOUR_API ExportFormatBase { 43 public: 44 45 enum Type { 46 T_None = 0, 47 T_Sndfile, 48 T_FFMPEG 49 }; 50 51 enum FormatId { 52 F_None = 0, 53 F_WAV = SF_FORMAT_WAV, 54 F_W64 = SF_FORMAT_W64, 55 F_CAF = SF_FORMAT_CAF, 56 F_AIFF = SF_FORMAT_AIFF, 57 F_AU = SF_FORMAT_AU, 58 F_IRCAM = SF_FORMAT_IRCAM, 59 F_RAW = SF_FORMAT_RAW, 60 F_FLAC = SF_FORMAT_FLAC, 61 F_Ogg = SF_FORMAT_OGG, 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 }; 83 84 enum DitherType { 85 D_None = AudioGrapher::D_None, 86 D_Rect = AudioGrapher::D_Rect, 87 D_Tri = AudioGrapher::D_Tri, 88 D_Shaped = AudioGrapher::D_Shaped 89 }; 90 91 enum Quality { 92 Q_None = 0, 93 Q_Any, 94 Q_LosslessLinear, 95 Q_LosslessCompression, 96 Q_LossyCompression 97 }; 98 99 enum SampleRate { 100 SR_None = 0, 101 SR_Session = 1, 102 SR_8 = 8000, 103 SR_22_05 = 22050, 104 SR_44_1 = 44100, 105 SR_48 = 48000, 106 SR_88_2 = 88200, 107 SR_96 = 96000, 108 SR_176_4 = 176400, 109 SR_192 = 192000 110 }; 111 112 enum SRCQuality { 113 SRC_SincBest = SRC_SINC_BEST_QUALITY, 114 SRC_SincMedium = SRC_SINC_MEDIUM_QUALITY, 115 SRC_SincFast = SRC_SINC_FASTEST, 116 SRC_ZeroOrderHold = SRC_ZERO_ORDER_HOLD, 117 SRC_Linear = SRC_LINEAR 118 }; 119 120 /// Class for managing selection and compatibility states 121 class LIBARDOUR_API SelectableCompatible { 122 public: SelectableCompatible()123 SelectableCompatible () 124 : _selected (false), _compatible (true) { } ~SelectableCompatible()125 ~SelectableCompatible () {} 126 127 PBD::Signal1<void,bool> SelectChanged; 128 PBD::Signal1<void,bool> CompatibleChanged; 129 selected()130 bool selected () const { return _selected; } compatible()131 bool compatible () const { return _compatible; } name()132 std::string name () const { return _name; } 133 134 void set_selected (bool value); 135 void set_compatible (bool value); 136 137 protected: set_name(std::string name)138 void set_name (std::string name) { _name = name; } 139 140 private: 141 bool _selected; 142 bool _compatible; 143 144 std::string _name; 145 }; 146 147 public: 148 149 ExportFormatBase (); 150 ExportFormatBase (ExportFormatBase const & other); 151 152 virtual ~ExportFormatBase (); 153 154 boost::shared_ptr<ExportFormatBase> get_intersection (ExportFormatBase const & other) const; 155 boost::shared_ptr<ExportFormatBase> get_union (ExportFormatBase const & other) const; 156 endiannesses_empty()157 bool endiannesses_empty () const { return endiannesses.empty (); } sample_formats_empty()158 bool sample_formats_empty () const { return sample_formats.empty (); } sample_rates_empty()159 bool sample_rates_empty () const { return sample_rates.empty (); } formats_empty()160 bool formats_empty () const { return format_ids.empty (); } qualities_empty()161 bool qualities_empty () const { return qualities.empty (); } 162 has_endianness(Endianness endianness)163 bool has_endianness (Endianness endianness) const { return endiannesses.find (endianness) != endiannesses.end() ; } has_sample_format(SampleFormat format)164 bool has_sample_format (SampleFormat format) const { return sample_formats.find (format) != sample_formats.end(); } has_sample_rate(SampleRate rate)165 bool has_sample_rate (SampleRate rate) const { return sample_rates.find (rate) != sample_rates.end(); } has_format(FormatId format)166 bool has_format (FormatId format) const { return format_ids.find (format) != format_ids.end(); } has_quality(Quality quality)167 bool has_quality (Quality quality) const { return qualities.find (quality) != qualities.end(); } 168 set_extension(std::string const & extension)169 void set_extension (std::string const & extension) { _extension = extension; } extension()170 std::string const & extension () const { return _extension; } 171 172 static SampleRate nearest_sample_rate (samplecnt_t sample_rate); 173 174 protected: 175 176 friend class HasSampleFormat; 177 typedef std::set<SampleFormat> SampleFormatSet; 178 SampleFormatSet sample_formats; 179 180 protected: 181 typedef std::set<Endianness> EndianSet; 182 typedef std::set<SampleRate> SampleRateSet; 183 typedef std::set<FormatId> FormatSet; 184 typedef std::set<Quality> QualitySet; 185 186 EndianSet endiannesses; 187 SampleRateSet sample_rates; 188 FormatSet format_ids; 189 QualitySet qualities; 190 191 private: 192 193 std::string _extension; 194 195 enum SetOperation { 196 SetUnion, 197 SetIntersection 198 }; 199 200 boost::shared_ptr<ExportFormatBase> do_set_operation (ExportFormatBase const & other, SetOperation operation) const; 201 }; 202 203 } // namespace ARDOUR 204 205 #endif /* __ardour_export_format_base_h__ */ 206