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_same_thread (*this, boost::bind (&HasSampleFormat::update_sample_format_selection
, this, _1
));
63 // BOOST SIGNALS Could this be made any uglier?
64 ptr
->SelectChanged
.connect_same_thread (*this,
65 boost::bind (boost::type
<void> (), boost::ref (SampleFormatSelectChanged
), _1
, WeakSampleFormatPtr (ptr
)));
66 ptr
->CompatibleChanged
.connect_same_thread (*this,
67 boost::bind (boost::type
<void> (), boost::ref (SampleFormatCompatibleChanged
), _1
, WeakSampleFormatPtr (ptr
)));
71 HasSampleFormat::add_dither_type (ExportFormatBase::DitherType type
, Glib::ustring name
)
73 DitherTypePtr
ptr (new DitherTypeState (type
, name
));
74 dither_type_states
.push_back (ptr
);
75 ptr
->SelectChanged
.connect_same_thread (*this, boost::bind (&HasSampleFormat::update_dither_type_selection
, this, _1
));
76 // BOOST SIGNALS Could this be made any uglier?
77 ptr
->SelectChanged
.connect_same_thread (*this,
78 boost::bind (boost::type
<void> (), boost::ref (DitherTypeSelectChanged
), _1
, WeakDitherTypePtr (ptr
)));
79 ptr
->CompatibleChanged
.connect_same_thread (*this,
80 boost::bind (boost::type
<void> (),boost::ref ( DitherTypeCompatibleChanged
), _1
, WeakDitherTypePtr (ptr
)));
83 HasSampleFormat::SampleFormatPtr
84 HasSampleFormat::get_selected_sample_format ()
86 for (SampleFormatList::iterator it
= sample_format_states
.begin(); it
!= sample_format_states
.end(); ++it
) {
87 if ((*it
)->selected()) {
92 return SampleFormatPtr();
95 HasSampleFormat::DitherTypePtr
96 HasSampleFormat::get_selected_dither_type ()
98 for (DitherTypeList::iterator it
= dither_type_states
.begin(); it
!= dither_type_states
.end(); ++it
) {
99 if ((*it
)->selected()) {
104 return DitherTypePtr();
108 HasSampleFormat::update_sample_format_selection (bool)
110 SampleFormatPtr format
= get_selected_sample_format();
115 if (format
->format
== ExportFormatBase::SF_24
||
116 format
->format
== ExportFormatBase::SF_32
||
117 format
->format
== ExportFormatBase::SF_Float
||
118 format
->format
== ExportFormatBase::SF_Double
) {
119 for (DitherTypeList::iterator it
= dither_type_states
.begin(); it
!= dither_type_states
.end(); ++it
) {
120 if ((*it
)->type
== ExportFormatBase::D_None
) {
121 (*it
)->set_selected (true);
123 (*it
)->set_compatible (false);
128 for (DitherTypeList::iterator it
= dither_type_states
.begin(); it
!= dither_type_states
.end(); ++it
) {
129 (*it
)->set_compatible (true);
135 HasSampleFormat::update_dither_type_selection (bool)
137 DitherTypePtr type
= get_selected_dither_type();
142 if (!type
->compatible()) {
143 SampleFormatPtr format
= get_selected_sample_format();
145 format
->set_selected (false);
148 for (DitherTypeList::iterator it
= dither_type_states
.begin(); it
!= dither_type_states
.end(); ++it
) {
149 (*it
)->set_compatible (true);
155 HasSampleFormat::get_sample_format_name (ExportFormatBase::SampleFormat format
)
158 case ExportFormatBase::SF_8
:
160 case ExportFormatBase::SF_16
:
162 case ExportFormatBase::SF_24
:
164 case ExportFormatBase::SF_32
:
166 case ExportFormatBase::SF_Float
:
168 case ExportFormatBase::SF_Double
:
170 case ExportFormatBase::SF_U8
:
171 return _("8bit unsigned");
172 case ExportFormatBase::SF_Vorbis
:
173 return _("Vorbis sample format");
174 case ExportFormatBase::SF_None
:
175 return _("No sample format");
182 ExportFormatLinear::ExportFormatLinear (Glib::ustring name
, FormatId format_id
) :
183 HasSampleFormat (sample_formats
),
184 _default_sample_format (SF_None
)
187 set_format_id (format_id
);
189 add_sample_rate (SR_22_05
);
190 add_sample_rate (SR_44_1
);
191 add_sample_rate (SR_48
);
192 add_sample_rate (SR_88_2
);
193 add_sample_rate (SR_96
);
194 add_sample_rate (SR_192
);
196 add_endianness (E_FileDefault
);
198 set_quality (Q_LosslessLinear
);
202 ExportFormatLinear::set_compatibility_state (ExportFormatCompatibility
const & compatibility
)
206 bool compatible
= true;
208 if (!compatibility
.has_quality (Q_LosslessLinear
)) {
212 if (!compatibility
.has_format (get_format_id())) {
216 boost::shared_ptr
<ExportFormatBase
> intersection
= get_intersection (compatibility
);
218 if (intersection
->endiannesses_empty()) {
222 if (intersection
->sample_rates_empty()) {
226 if (intersection
->sample_formats_empty()) {
230 set_compatible (compatible
);
234 for (SampleFormatList::iterator it
= sample_format_states
.begin(); it
!= sample_format_states
.end(); ++it
) {
235 (*it
)->set_compatible (compatibility
.has_sample_format ((*it
)->format
));
243 ExportFormatOggVorbis::ExportFormatOggVorbis ()
245 /* Check system compatibility */
248 sf_info
.channels
= 2;
249 sf_info
.samplerate
= SR_44_1
;
250 sf_info
.format
= F_Ogg
| SF_Vorbis
;
251 if (sf_format_check (&sf_info
) != SF_TRUE
) {
252 throw ExportFormatIncompatible();
255 set_name ("Ogg Vorbis");
256 set_format_id (F_Ogg
);
257 sample_formats
.insert (SF_Vorbis
);
259 add_sample_rate (SR_22_05
);
260 add_sample_rate (SR_44_1
);
261 add_sample_rate (SR_48
);
262 add_sample_rate (SR_88_2
);
263 add_sample_rate (SR_96
);
264 add_sample_rate (SR_192
);
266 add_endianness (E_FileDefault
);
268 set_extension ("ogg");
269 set_quality (Q_LossyCompression
);
273 ExportFormatOggVorbis::set_compatibility_state (ExportFormatCompatibility
const & compatibility
)
275 bool compatible
= compatibility
.has_format (F_Ogg
);
276 set_compatible (compatible
);
282 ExportFormatFLAC::ExportFormatFLAC () :
283 HasSampleFormat (sample_formats
)
285 /* Check system compatibility */
288 sf_info
.channels
= 2;
289 sf_info
.samplerate
= SR_44_1
;
290 sf_info
.format
= F_FLAC
| SF_16
;
291 if (sf_format_check (&sf_info
) != SF_TRUE
) {
292 throw ExportFormatIncompatible();
296 set_format_id (F_FLAC
);
298 add_sample_rate (SR_22_05
);
299 add_sample_rate (SR_44_1
);
300 add_sample_rate (SR_48
);
301 add_sample_rate (SR_88_2
);
302 add_sample_rate (SR_96
);
303 add_sample_rate (SR_192
);
305 add_sample_format (SF_8
);
306 add_sample_format (SF_16
);
307 add_sample_format (SF_24
);
309 add_endianness (E_FileDefault
);
311 set_extension ("flac");
312 set_quality (Q_LosslessCompression
);
316 ExportFormatFLAC::set_compatibility_state (ExportFormatCompatibility
const & compatibility
)
318 bool compatible
= compatibility
.has_format (F_FLAC
);
319 set_compatible (compatible
);
325 ExportFormatBWF::ExportFormatBWF () :
326 HasSampleFormat (sample_formats
)
329 set_format_id (F_WAV
);
331 add_sample_rate (SR_22_05
);
332 add_sample_rate (SR_44_1
);
333 add_sample_rate (SR_48
);
334 add_sample_rate (SR_88_2
);
335 add_sample_rate (SR_96
);
336 add_sample_rate (SR_192
);
338 add_sample_format (SF_U8
);
339 add_sample_format (SF_16
);
340 add_sample_format (SF_24
);
341 add_sample_format (SF_32
);
342 add_sample_format (SF_Float
);
343 add_sample_format (SF_Double
);
345 add_endianness (E_FileDefault
);
347 set_extension ("wav");
348 set_quality (Q_LosslessLinear
);
352 ExportFormatBWF::set_compatibility_state (ExportFormatCompatibility
const & compatibility
)
354 bool compatible
= compatibility
.has_format (F_WAV
);
355 set_compatible (compatible
);
359 }; // namespace ARDOUR