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>
29 ExportFormat::has_sample_format ()
31 return dynamic_cast<HasSampleFormat *> (this);
35 ExportFormat::sample_format_is_compatible (SampleFormat format) const
37 return (sample_formats.find (format) != sample_formats.end());
40 /*** HasSampleFormat ***/
42 HasSampleFormat::HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats) :
43 _sample_formats (sample_formats)
47 add_dither_type (ExportFormatBase::D_Shaped, _("Shaped Noise"));
48 add_dither_type (ExportFormatBase::D_Tri, _("Triangular"));
49 add_dither_type (ExportFormatBase::D_Rect, _("Rectangular"));
50 add_dither_type (ExportFormatBase::D_None, _("None"));
54 HasSampleFormat::add_sample_format (ExportFormatBase::SampleFormat format)
56 _sample_formats.insert (format);
58 SampleFormatPtr ptr (new SampleFormatState (format, get_sample_format_name (format)));
59 sample_format_states.push_back (ptr);
60 ptr->SelectChanged.connect (sigc::bind (SampleFormatSelectChanged.make_slot(), WeakSampleFormatPtr (ptr)));
61 ptr->SelectChanged.connect (sigc::mem_fun (*this, &HasSampleFormat::update_sample_format_selection));
62 ptr->CompatibleChanged.connect (sigc::bind (SampleFormatCompatibleChanged.make_slot(), WeakSampleFormatPtr (ptr)));
66 HasSampleFormat::add_dither_type (ExportFormatBase::DitherType type, Glib::ustring name)
68 DitherTypePtr ptr (new DitherTypeState (type, name));
69 dither_type_states.push_back (ptr);
70 ptr->SelectChanged.connect (sigc::bind (DitherTypeSelectChanged.make_slot(), WeakDitherTypePtr (ptr)));
71 ptr->SelectChanged.connect (sigc::mem_fun (*this, &HasSampleFormat::update_dither_type_selection));
72 ptr->CompatibleChanged.connect (sigc::bind (DitherTypeCompatibleChanged.make_slot(), WeakDitherTypePtr (ptr)));
75 HasSampleFormat::SampleFormatPtr
76 HasSampleFormat::get_selected_sample_format ()
78 for (SampleFormatList::iterator it = sample_format_states.begin(); it != sample_format_states.end(); ++it) {
79 if ((*it)->selected()) {
84 return SampleFormatPtr();
87 HasSampleFormat::DitherTypePtr
88 HasSampleFormat::get_selected_dither_type ()
90 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
91 if ((*it)->selected()) {
96 return DitherTypePtr();
100 HasSampleFormat::update_sample_format_selection (bool)
102 SampleFormatPtr format = get_selected_sample_format();
107 if (format->format == ExportFormatBase::SF_24 ||
108 format->format == ExportFormatBase::SF_32 ||
109 format->format == ExportFormatBase::SF_Float ||
110 format->format == ExportFormatBase::SF_Double) {
111 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
112 if ((*it)->type == ExportFormatBase::D_None) {
113 (*it)->set_selected (true);
115 (*it)->set_compatible (false);
120 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
121 (*it)->set_compatible (true);
127 HasSampleFormat::update_dither_type_selection (bool)
129 DitherTypePtr type = get_selected_dither_type();
134 if (!type->compatible()) {
135 SampleFormatPtr format = get_selected_sample_format();
137 format->set_selected (false);
140 for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
141 (*it)->set_compatible (true);
147 HasSampleFormat::get_sample_format_name (ExportFormatBase::SampleFormat format)
150 case ExportFormatBase::SF_8:
152 case ExportFormatBase::SF_16:
154 case ExportFormatBase::SF_24:
156 case ExportFormatBase::SF_32:
158 case ExportFormatBase::SF_Float:
160 case ExportFormatBase::SF_Double:
162 case ExportFormatBase::SF_U8:
163 return _("8bit unsigned");
164 case ExportFormatBase::SF_Vorbis:
165 return _("Vorbis sample format");
166 case ExportFormatBase::SF_None:
167 return _("No sample format");
174 ExportFormatLinear::ExportFormatLinear (Glib::ustring name, FormatId format_id) :
175 HasSampleFormat (sample_formats),
176 _default_sample_format (SF_None)
179 set_format_id (format_id);
181 add_sample_rate (SR_22_05);
182 add_sample_rate (SR_44_1);
183 add_sample_rate (SR_48);
184 add_sample_rate (SR_88_2);
185 add_sample_rate (SR_96);
186 add_sample_rate (SR_192);
188 add_endianness (E_FileDefault);
190 set_quality (Q_LosslessLinear);
194 ExportFormatLinear::set_compatibility_state (ExportFormatCompatibility const & compatibility)
198 bool compatible = true;
200 if (!compatibility.has_quality (Q_LosslessLinear)) {
204 if (!compatibility.has_format (get_format_id())) {
208 boost::shared_ptr<ExportFormatBase> intersection = get_intersection (compatibility);
210 if (intersection->endiannesses_empty()) {
214 if (intersection->sample_rates_empty()) {
218 if (intersection->sample_formats_empty()) {
222 set_compatible (compatible);
226 for (SampleFormatList::iterator it = sample_format_states.begin(); it != sample_format_states.end(); ++it) {
227 (*it)->set_compatible (compatibility.has_sample_format ((*it)->format));
235 ExportFormatOggVorbis::ExportFormatOggVorbis ()
237 /* Check system compatibility */
240 sf_info.channels = 2;
241 sf_info.samplerate = SR_44_1;
242 sf_info.format = F_Ogg | SF_Vorbis;
243 if (sf_format_check (&sf_info) != SF_TRUE) {
244 throw ExportFormatIncompatible();
247 set_name ("Ogg Vorbis");
248 set_format_id (F_Ogg);
249 sample_formats.insert (SF_Vorbis);
251 add_sample_rate (SR_22_05);
252 add_sample_rate (SR_44_1);
253 add_sample_rate (SR_48);
254 add_sample_rate (SR_88_2);
255 add_sample_rate (SR_96);
256 add_sample_rate (SR_192);
258 add_endianness (E_FileDefault);
260 set_extension ("ogg");
261 set_quality (Q_LossyCompression);
265 ExportFormatOggVorbis::set_compatibility_state (ExportFormatCompatibility const & compatibility)
267 bool compatible = compatibility.has_format (F_Ogg);
268 set_compatible (compatible);
274 ExportFormatFLAC::ExportFormatFLAC () :
275 HasSampleFormat (sample_formats)
277 /* Check system compatibility */
280 sf_info.channels = 2;
281 sf_info.samplerate = SR_44_1;
282 sf_info.format = F_FLAC | SF_16;
283 if (sf_format_check (&sf_info) != SF_TRUE) {
284 throw ExportFormatIncompatible();
288 set_format_id (F_FLAC);
290 add_sample_rate (SR_22_05);
291 add_sample_rate (SR_44_1);
292 add_sample_rate (SR_48);
293 add_sample_rate (SR_88_2);
294 add_sample_rate (SR_96);
295 add_sample_rate (SR_192);
297 add_sample_format (SF_8);
298 add_sample_format (SF_16);
299 add_sample_format (SF_24);
301 add_endianness (E_FileDefault);
303 set_extension ("flac");
304 set_quality (Q_LosslessCompression);
308 ExportFormatFLAC::set_compatibility_state (ExportFormatCompatibility const & compatibility)
310 bool compatible = compatibility.has_format (F_FLAC);
311 set_compatible (compatible);
317 ExportFormatBWF::ExportFormatBWF () :
318 HasSampleFormat (sample_formats)
321 set_format_id (F_WAV);
323 add_sample_rate (SR_22_05);
324 add_sample_rate (SR_44_1);
325 add_sample_rate (SR_48);
326 add_sample_rate (SR_88_2);
327 add_sample_rate (SR_96);
328 add_sample_rate (SR_192);
330 add_sample_format (SF_U8);
331 add_sample_format (SF_16);
332 add_sample_format (SF_24);
333 add_sample_format (SF_32);
334 add_sample_format (SF_Float);
335 add_sample_format (SF_Double);
337 add_endianness (E_FileDefault);
339 set_extension ("wav");
340 set_quality (Q_LosslessLinear);
344 ExportFormatBWF::set_compatibility_state (ExportFormatCompatibility const & compatibility)
346 bool compatible = compatibility.has_format (F_WAV);
347 set_compatible (compatible);
351 }; // namespace ARDOUR