2 Copyright (C) 2008 Paul Davis
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.
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.
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.
21 #include "ardour/export_formats.h"
31 ExportFormat::has_sample_format ()
33 return dynamic_cast<HasSampleFormat *> (this);
37 ExportFormat::sample_format_is_compatible (SampleFormat format) const
39 return (sample_formats.find (format) != sample_formats.end());
42 /*** HasSampleFormat ***/
44 HasSampleFormat::HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats) :
45 _sample_formats (sample_formats)
49 add_dither_type (ExportFormatBase::D_Shaped, _("Shaped Noise"));
50 add_dither_type (ExportFormatBase::D_Tri, _("Triangular"));
51 add_dither_type (ExportFormatBase::D_Rect, _("Rectangular"));
52 add_dither_type (ExportFormatBase::D_None, _("None"));
56 HasSampleFormat::add_sample_format (ExportFormatBase::SampleFormat format)
58 _sample_formats.insert (format);
60 SampleFormatPtr ptr (new SampleFormatState (format, get_sample_format_name (format)));
61 sample_format_states.push_back (ptr);
62 ptr->SelectChanged.connect (sigc::bind (SampleFormatSelectChanged.make_slot(), WeakSampleFormatPtr (ptr)));
63 ptr->SelectChanged.connect (sigc::mem_fun (*this, &HasSampleFormat::update_sample_format_selection));
64 ptr->CompatibleChanged.connect (sigc::bind (SampleFormatCompatibleChanged.make_slot(), WeakSampleFormatPtr (ptr)));
68 HasSampleFormat::add_dither_type (ExportFormatBase::DitherType type, Glib::ustring name)
70 DitherTypePtr ptr (new DitherTypeState (type, name));
71 dither_type_states.push_back (ptr);
72 ptr->SelectChanged.connect (sigc::bind (DitherTypeSelectChanged.make_slot(), WeakDitherTypePtr (ptr)));
73 ptr->SelectChanged.connect (sigc::mem_fun (*this, &HasSampleFormat::update_dither_type_selection));
74 ptr->CompatibleChanged.connect (sigc::bind (DitherTypeCompatibleChanged.make_slot(), WeakDitherTypePtr (ptr)));
77 HasSampleFormat::SampleFormatPtr
78 HasSampleFormat::get_selected_sample_format ()
80 for (SampleFormatList::iterator it = sample_format_states.begin(); it != sample_format_states.end(); ++it) {
81 if ((*it)->selected()) {
86 return SampleFormatPtr();
89 HasSampleFormat::DitherTypePtr
90 HasSampleFormat::get_selected_dither_type ()
92 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
93 if ((*it)->selected()) {
98 return DitherTypePtr();
102 HasSampleFormat::update_sample_format_selection (bool)
104 SampleFormatPtr format = get_selected_sample_format();
109 if (format->format == ExportFormatBase::SF_24 ||
110 format->format == ExportFormatBase::SF_32 ||
111 format->format == ExportFormatBase::SF_Float ||
112 format->format == ExportFormatBase::SF_Double) {
113 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
114 if ((*it)->type == ExportFormatBase::D_None) {
115 (*it)->set_selected (true);
117 (*it)->set_compatible (false);
122 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
123 (*it)->set_compatible (true);
129 HasSampleFormat::update_dither_type_selection (bool)
131 DitherTypePtr type = get_selected_dither_type();
136 if (!type->compatible()) {
137 SampleFormatPtr format = get_selected_sample_format();
139 format->set_selected (false);
142 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
143 (*it)->set_compatible (true);
149 HasSampleFormat::get_sample_format_name (ExportFormatBase::SampleFormat format)
152 case ExportFormatBase::SF_8:
154 case ExportFormatBase::SF_16:
156 case ExportFormatBase::SF_24:
158 case ExportFormatBase::SF_32:
160 case ExportFormatBase::SF_Float:
162 case ExportFormatBase::SF_Double:
164 case ExportFormatBase::SF_U8:
165 return _("8bit unsigned");
166 case ExportFormatBase::SF_Vorbis:
167 return _("Vorbis sample format");
168 case ExportFormatBase::SF_None:
169 return _("No sample format");
176 ExportFormatLinear::ExportFormatLinear (Glib::ustring name, FormatId format_id) :
177 HasSampleFormat (sample_formats),
178 _default_sample_format (SF_None)
181 set_format_id (format_id);
183 add_sample_rate (SR_22_05);
184 add_sample_rate (SR_44_1);
185 add_sample_rate (SR_48);
186 add_sample_rate (SR_88_2);
187 add_sample_rate (SR_96);
188 add_sample_rate (SR_192);
190 add_endianness (E_FileDefault);
192 set_quality (Q_LosslessLinear);
196 ExportFormatLinear::set_compatibility_state (ExportFormatCompatibility const & compatibility)
200 bool compatible = true;
202 if (!compatibility.has_quality (Q_LosslessLinear)) {
206 if (!compatibility.has_format (get_format_id())) {
210 boost::shared_ptr<ExportFormatBase> intersection = get_intersection (compatibility);
212 if (intersection->endiannesses_empty()) {
216 if (intersection->sample_rates_empty()) {
220 if (intersection->sample_formats_empty()) {
224 set_compatible (compatible);
228 for (SampleFormatList::iterator it = sample_format_states.begin(); it != sample_format_states.end(); ++it) {
229 (*it)->set_compatible (compatibility.has_sample_format ((*it)->format));
237 ExportFormatOggVorbis::ExportFormatOggVorbis ()
239 /* Check system compatibility */
242 sf_info.channels = 2;
243 sf_info.samplerate = SR_44_1;
244 sf_info.format = F_Ogg | SF_Vorbis;
245 if (sf_format_check (&sf_info) != SF_TRUE) {
246 throw ExportFormatIncompatible();
249 set_name ("Ogg Vorbis");
250 set_format_id (F_Ogg);
251 sample_formats.insert (SF_Vorbis);
253 add_sample_rate (SR_22_05);
254 add_sample_rate (SR_44_1);
255 add_sample_rate (SR_48);
256 add_sample_rate (SR_88_2);
257 add_sample_rate (SR_96);
258 add_sample_rate (SR_192);
260 add_endianness (E_FileDefault);
262 set_extension ("ogg");
263 set_quality (Q_LossyCompression);
267 ExportFormatOggVorbis::set_compatibility_state (ExportFormatCompatibility const & compatibility)
269 bool compatible = compatibility.has_format (F_Ogg);
270 set_compatible (compatible);
276 ExportFormatFLAC::ExportFormatFLAC () :
277 HasSampleFormat (sample_formats)
279 /* Check system compatibility */
282 sf_info.channels = 2;
283 sf_info.samplerate = SR_44_1;
284 sf_info.format = F_FLAC | SF_16;
285 if (sf_format_check (&sf_info) != SF_TRUE) {
286 throw ExportFormatIncompatible();
290 set_format_id (F_FLAC);
292 add_sample_rate (SR_22_05);
293 add_sample_rate (SR_44_1);
294 add_sample_rate (SR_48);
295 add_sample_rate (SR_88_2);
296 add_sample_rate (SR_96);
297 add_sample_rate (SR_192);
299 add_sample_format (SF_8);
300 add_sample_format (SF_16);
301 add_sample_format (SF_24);
303 add_endianness (E_FileDefault);
305 set_extension ("flac");
306 set_quality (Q_LosslessCompression);
310 ExportFormatFLAC::set_compatibility_state (ExportFormatCompatibility const & compatibility)
312 bool compatible = compatibility.has_format (F_FLAC);
313 set_compatible (compatible);
319 ExportFormatBWF::ExportFormatBWF () :
320 HasSampleFormat (sample_formats)
323 set_format_id (F_WAV);
325 add_sample_rate (SR_22_05);
326 add_sample_rate (SR_44_1);
327 add_sample_rate (SR_48);
328 add_sample_rate (SR_88_2);
329 add_sample_rate (SR_96);
330 add_sample_rate (SR_192);
332 add_sample_format (SF_U8);
333 add_sample_format (SF_16);
334 add_sample_format (SF_24);
335 add_sample_format (SF_32);
336 add_sample_format (SF_Float);
337 add_sample_format (SF_Double);
339 add_endianness (E_FileDefault);
341 set_extension ("wav");
342 set_quality (Q_LosslessLinear);
346 ExportFormatBWF::set_compatibility_state (ExportFormatCompatibility const & compatibility)
348 bool compatible = compatibility.has_format (F_WAV);
349 set_compatible (compatible);
353 }; // namespace ARDOUR