Remove over 500 unnecessary includes (including 54 of session.h).
[ardour.git] / libs / ardour / export_format_manager.cc
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #include "ardour/export_format_manager.h"
22
23 #include "ardour/export_format_specification.h"
24 #include "ardour/export_format_compatibility.h"
25
26 #include "i18n.h"
27
28 using std::string;
29
30 namespace ARDOUR
31 {
32
33 ExportFormatManager::ExportFormatManager (ExportFormatSpecPtr specification) :
34   pending_selection_change (false),
35   universal_set (new ExportFormatBase ())
36 {
37         current_selection = specification;
38
39         init_compatibilities ();
40         init_qualities ();
41         init_formats ();
42         init_sample_rates ();
43 }
44
45 ExportFormatManager::~ExportFormatManager ()
46 {
47
48 }
49
50 void
51 ExportFormatManager::init_compatibilities ()
52 {
53         ExportFormatCompatibilityPtr c_ptr;
54
55         c_ptr.reset (new ExportFormatCompatibility (_("CD")));
56         c_ptr->add_sample_rate (ExportFormatBase::SR_44_1);
57         c_ptr->add_format_id (ExportFormatBase::F_WAV);
58         c_ptr->add_format_id (ExportFormatBase::F_AIFF);
59         c_ptr->add_quality (ExportFormatBase::Q_LosslessLinear);
60         c_ptr->add_sample_format (ExportFormatBase::SF_16);
61         c_ptr->add_endianness (ExportFormatBase::E_FileDefault);
62         add_compatibility (c_ptr);
63
64         c_ptr.reset (new ExportFormatCompatibility (_("DVD-A")));
65         c_ptr->add_sample_rate (ExportFormatBase::SR_44_1);
66         c_ptr->add_sample_rate (ExportFormatBase::SR_48);
67         c_ptr->add_sample_rate (ExportFormatBase::SR_88_2);
68         c_ptr->add_sample_rate (ExportFormatBase::SR_96);
69         c_ptr->add_sample_rate (ExportFormatBase::SR_192);
70         c_ptr->add_format_id (ExportFormatBase::F_WAV);
71         c_ptr->add_format_id (ExportFormatBase::F_AIFF);
72         c_ptr->add_quality (ExportFormatBase::Q_LosslessLinear);
73         c_ptr->add_sample_format (ExportFormatBase::SF_16);
74         c_ptr->add_sample_format (ExportFormatBase::SF_24);
75         c_ptr->add_endianness (ExportFormatBase::E_FileDefault);
76         add_compatibility (c_ptr);
77
78         c_ptr.reset (new ExportFormatCompatibility (_("iPod")));
79         c_ptr->add_sample_rate (ExportFormatBase::SR_44_1);
80         c_ptr->add_sample_rate (ExportFormatBase::SR_48);
81         c_ptr->add_format_id (ExportFormatBase::F_WAV);
82         c_ptr->add_format_id (ExportFormatBase::F_AIFF);
83         c_ptr->add_quality (ExportFormatBase::Q_LosslessLinear);
84         c_ptr->add_sample_format (ExportFormatBase::SF_16);
85         c_ptr->add_sample_format (ExportFormatBase::SF_24);
86         c_ptr->add_endianness (ExportFormatBase::E_FileDefault);
87         add_compatibility (c_ptr);
88
89         c_ptr.reset (new ExportFormatCompatibility (_("Something else")));
90         c_ptr->add_sample_rate (ExportFormatBase::SR_44_1);
91         c_ptr->add_sample_rate (ExportFormatBase::SR_48);
92         c_ptr->add_format_id (ExportFormatBase::F_WAV);
93         c_ptr->add_format_id (ExportFormatBase::F_AIFF);
94         c_ptr->add_format_id (ExportFormatBase::F_AU);
95         c_ptr->add_format_id (ExportFormatBase::F_FLAC);
96         c_ptr->add_quality (ExportFormatBase::Q_LosslessLinear);
97         c_ptr->add_quality (ExportFormatBase::Q_LosslessCompression);
98         c_ptr->add_sample_format (ExportFormatBase::SF_16);
99         c_ptr->add_sample_format (ExportFormatBase::SF_24);
100         c_ptr->add_sample_format (ExportFormatBase::SF_32);
101         c_ptr->add_endianness (ExportFormatBase::E_FileDefault);
102         add_compatibility (c_ptr);
103 }
104
105 void
106 ExportFormatManager::init_qualities ()
107 {
108         add_quality (QualityPtr (new QualityState (ExportFormatBase::Q_Any, _("Any"))));
109         add_quality (QualityPtr (new QualityState (ExportFormatBase::Q_LosslessLinear, _("Lossless (linear PCM)"))));
110         add_quality (QualityPtr (new QualityState (ExportFormatBase::Q_LossyCompression, _("Lossy compression"))));
111         add_quality (QualityPtr (new QualityState (ExportFormatBase::Q_LosslessCompression, _("Lossless compression"))));
112 }
113
114 void
115 ExportFormatManager::init_formats ()
116 {
117         ExportFormatPtr f_ptr;
118         ExportFormatLinear * fl_ptr;
119
120         f_ptr.reset (fl_ptr = new ExportFormatLinear ("AIFF", ExportFormatBase::F_AIFF));
121         fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
122         fl_ptr->add_sample_format (ExportFormatBase::SF_8);
123         fl_ptr->add_sample_format (ExportFormatBase::SF_16);
124         fl_ptr->add_sample_format (ExportFormatBase::SF_24);
125         fl_ptr->add_sample_format (ExportFormatBase::SF_32);
126         fl_ptr->add_sample_format (ExportFormatBase::SF_Float);
127         fl_ptr->add_sample_format (ExportFormatBase::SF_Double);
128         fl_ptr->add_endianness (ExportFormatBase::E_Big);
129         fl_ptr->set_default_sample_format (ExportFormatBase::SF_16);
130         fl_ptr->set_extension ("aiff");
131         add_format (f_ptr);
132
133         f_ptr.reset (fl_ptr = new ExportFormatLinear ("AU", ExportFormatBase::F_AU));
134         fl_ptr->add_sample_format (ExportFormatBase::SF_8);
135         fl_ptr->add_sample_format (ExportFormatBase::SF_16);
136         fl_ptr->add_sample_format (ExportFormatBase::SF_24);
137         fl_ptr->add_sample_format (ExportFormatBase::SF_32);
138         fl_ptr->add_sample_format (ExportFormatBase::SF_Float);
139         fl_ptr->add_sample_format (ExportFormatBase::SF_Double);
140         fl_ptr->set_default_sample_format (ExportFormatBase::SF_16);
141         fl_ptr->set_extension ("au");
142         add_format (f_ptr);
143
144         f_ptr.reset (new ExportFormatBWF ());
145         add_format (f_ptr);
146
147         f_ptr.reset (fl_ptr = new ExportFormatLinear ("IRCAM", ExportFormatBase::F_IRCAM));
148         fl_ptr->add_sample_format (ExportFormatBase::SF_16);
149         fl_ptr->add_sample_format (ExportFormatBase::SF_24);
150         fl_ptr->add_sample_format (ExportFormatBase::SF_32);
151         fl_ptr->add_sample_format (ExportFormatBase::SF_Float);
152         fl_ptr->set_default_sample_format (ExportFormatBase::SF_24);
153         fl_ptr->set_extension ("sf");
154         add_format (f_ptr);
155
156         f_ptr.reset (fl_ptr = new ExportFormatLinear ("WAV", ExportFormatBase::F_WAV));
157         fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
158         fl_ptr->add_sample_format (ExportFormatBase::SF_16);
159         fl_ptr->add_sample_format (ExportFormatBase::SF_24);
160         fl_ptr->add_sample_format (ExportFormatBase::SF_32);
161         fl_ptr->add_sample_format (ExportFormatBase::SF_Float);
162         fl_ptr->add_sample_format (ExportFormatBase::SF_Double);
163         fl_ptr->add_endianness (ExportFormatBase::E_Little);
164         fl_ptr->set_default_sample_format (ExportFormatBase::SF_16);
165         fl_ptr->set_extension ("wav");
166         add_format (f_ptr);
167
168         f_ptr.reset (fl_ptr = new ExportFormatLinear ("W64", ExportFormatBase::F_W64));
169         fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
170         fl_ptr->add_sample_format (ExportFormatBase::SF_16);
171         fl_ptr->add_sample_format (ExportFormatBase::SF_24);
172         fl_ptr->add_sample_format (ExportFormatBase::SF_32);
173         fl_ptr->add_sample_format (ExportFormatBase::SF_Float);
174         fl_ptr->add_sample_format (ExportFormatBase::SF_Double);
175         fl_ptr->set_default_sample_format (ExportFormatBase::SF_Double);
176         fl_ptr->set_extension ("w64");
177         add_format (f_ptr);
178
179         f_ptr.reset (fl_ptr = new ExportFormatLinear ("RAW", ExportFormatBase::F_RAW));
180         fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
181         fl_ptr->add_sample_format (ExportFormatBase::SF_8);
182         fl_ptr->add_sample_format (ExportFormatBase::SF_16);
183         fl_ptr->add_sample_format (ExportFormatBase::SF_24);
184         fl_ptr->add_sample_format (ExportFormatBase::SF_32);
185         fl_ptr->add_sample_format (ExportFormatBase::SF_Float);
186         fl_ptr->add_sample_format (ExportFormatBase::SF_Double);
187         fl_ptr->set_default_sample_format (ExportFormatBase::SF_Float);
188         fl_ptr->set_extension ("raw");
189         add_format (f_ptr);
190
191         try {
192                 f_ptr.reset (new ExportFormatOggVorbis ());
193                 add_format (f_ptr);
194         } catch (ExportFormatIncompatible & e) {}
195
196         try {
197                 f_ptr.reset (new ExportFormatFLAC ());
198                 add_format (f_ptr);
199         } catch (ExportFormatIncompatible & e) {}
200 }
201
202 void
203 ExportFormatManager::init_sample_rates ()
204 {
205         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_Session, _("Session rate"))));
206         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_22_05, "22,05 kHz")));
207         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_44_1, "44,1 kHz")));
208         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_48, "48 kHz")));
209         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_88_2, "88,2 kHz")));
210         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_96, "96 kHz")));
211         add_sample_rate (SampleRatePtr (new SampleRateState (ExportFormatBase::SR_192, "192 kHz")));
212 }
213
214 void
215 ExportFormatManager::add_compatibility (ExportFormatCompatibilityPtr ptr)
216 {
217         compatibilities.push_back (ptr);
218         ptr->SelectChanged.connect_same_thread (*this,
219                                                 boost::bind (&ExportFormatManager::change_compatibility_selection,
220                                                              this, _1, WeakExportFormatCompatibilityPtr (ptr)));
221 }
222
223 void
224 ExportFormatManager::add_quality (QualityPtr ptr)
225 {
226         ptr->SelectChanged.connect_same_thread (*this, boost::bind (&ExportFormatManager::change_quality_selection, this, _1, WeakQualityPtr (ptr)));
227         qualities.push_back (ptr);
228 }
229
230 void
231 ExportFormatManager::add_format (ExportFormatPtr ptr)
232 {
233         formats.push_back (ptr);
234         ptr->SelectChanged.connect_same_thread (*this, boost::bind (&ExportFormatManager::change_format_selection, this, _1, WeakExportFormatPtr (ptr)));
235         universal_set = universal_set->get_union (*ptr);
236
237         /* Encoding options */
238
239         boost::shared_ptr<HasSampleFormat> hsf;
240
241         if ((hsf = boost::dynamic_pointer_cast<HasSampleFormat> (ptr))) {
242                 hsf->SampleFormatSelectChanged.connect_same_thread (*this, boost::bind (&ExportFormatManager::change_sample_format_selection, this, _1, _2));
243                 hsf->DitherTypeSelectChanged.connect_same_thread (*this, boost::bind (&ExportFormatManager::change_dither_type_selection, this, _1, _2));
244         }
245 }
246
247 void
248 ExportFormatManager::add_sample_rate (SampleRatePtr ptr)
249 {
250         ptr->SelectChanged.connect_same_thread (*this, boost::bind (&ExportFormatManager::change_sample_rate_selection, this, _1, WeakSampleRatePtr (ptr)));
251         sample_rates.push_back (ptr);
252 }
253
254 void
255 ExportFormatManager::set_name (string name)
256 {
257         current_selection->set_name (name);
258 }
259
260 void
261 ExportFormatManager::select_src_quality (ExportFormatBase::SRCQuality value)
262 {
263         current_selection->set_src_quality (value);
264 }
265
266 void
267 ExportFormatManager::select_with_cue (bool value)
268 {
269         current_selection->set_with_cue (value);
270 }
271
272 void
273 ExportFormatManager::select_with_toc (bool value)
274 {
275         current_selection->set_with_toc (value);
276 }
277
278 void
279 ExportFormatManager::select_trim_beginning (bool value)
280 {
281         current_selection->set_trim_beginning (value);
282 }
283
284 void
285 ExportFormatManager::select_silence_beginning (AnyTime const & time)
286 {
287         current_selection->set_silence_beginning (time);
288 }
289
290 void
291 ExportFormatManager::select_trim_end (bool value)
292 {
293         current_selection->set_trim_end (value);
294 }
295
296 void
297 ExportFormatManager::select_silence_end (AnyTime const & time)
298 {
299         current_selection->set_silence_end (time);
300 }
301
302 void
303 ExportFormatManager::select_normalize (bool value)
304 {
305         current_selection->set_normalize (value);
306 }
307
308 void
309 ExportFormatManager::select_normalize_target (float value)
310 {
311         current_selection->set_normalize_target (value);
312 }
313
314 void
315 ExportFormatManager::select_tagging (bool tag)
316 {
317         current_selection->set_tag (tag);
318 }
319
320 void
321 ExportFormatManager::change_compatibility_selection (bool select, WeakExportFormatCompatibilityPtr const & compat)
322 {
323         bool do_selection_changed = !pending_selection_change;
324         if (!pending_selection_change) {
325                 pending_selection_change = true;
326         }
327
328         ExportFormatCompatibilityPtr ptr = compat.lock();
329
330         if (ptr && select) {
331                 select_compatibility (ptr);
332         }
333
334         if (do_selection_changed) {
335                 selection_changed ();
336         }
337 }
338
339 void
340 ExportFormatManager::change_quality_selection (bool select, WeakQualityPtr const & quality)
341 {
342         QualityPtr ptr = quality.lock ();
343
344         if (!ptr) {
345                 return;
346         }
347
348         if (select) {
349                 select_quality (ptr);
350         } else if (ptr->quality == current_selection->quality()) {
351                 ptr.reset();
352                 select_quality (ptr);
353         }
354 }
355
356 void
357 ExportFormatManager::change_format_selection (bool select, WeakExportFormatPtr const & format)
358 {
359         ExportFormatPtr ptr = format.lock();
360
361         if (!ptr) {
362                 return;
363         }
364
365         if (select) {
366                 select_format (ptr);
367         } else if (ptr->get_format_id() == current_selection->format_id()) {
368                 ptr.reset();
369                 select_format (ptr);
370         }
371 }
372
373 void
374 ExportFormatManager::change_sample_rate_selection (bool select, WeakSampleRatePtr const & rate)
375 {
376         SampleRatePtr ptr = rate.lock();
377
378         if (!ptr) {
379                 return;
380         }
381
382         if (select) {
383                 select_sample_rate (ptr);
384         } else if (ptr->rate == current_selection->sample_rate()) {
385                 ptr.reset();
386                 select_sample_rate (ptr);
387         }
388 }
389
390 void
391 ExportFormatManager::change_sample_format_selection (bool select, WeakSampleFormatPtr const & format)
392 {
393         SampleFormatPtr ptr = format.lock();
394
395         if (!ptr) {
396                 return;
397         }
398
399         if (select) {
400                 select_sample_format (ptr);
401         } else if (ptr->format == current_selection->sample_format()) {
402                 ptr.reset();
403                 select_sample_format (ptr);
404         }
405 }
406
407 void
408 ExportFormatManager::change_dither_type_selection (bool select, WeakDitherTypePtr const & type)
409 {
410         DitherTypePtr ptr = type.lock();
411
412         if (!ptr) {
413                 return;
414         }
415
416         if (select) {
417                 select_dither_type (ptr);
418         } else if (ptr->type == current_selection->dither_type()) {
419                 ptr.reset();
420                 select_dither_type (ptr);
421         }
422 }
423
424 void
425 ExportFormatManager::select_compatibility (WeakExportFormatCompatibilityPtr const & /*compat*/)
426 {
427         /* Calculate compatibility intersection for the selection */
428
429         ExportFormatBasePtr compat_intersect = get_compatibility_intersection ();
430
431         /* Unselect incompatible items */
432
433         boost::shared_ptr<ExportFormatBase> select_intersect;
434
435         select_intersect = compat_intersect->get_intersection (*current_selection);
436         if (select_intersect->qualities_empty()) {
437                 select_quality (QualityPtr());
438         }
439
440         select_intersect = compat_intersect->get_intersection (*current_selection);
441         if (select_intersect->formats_empty()) {
442                 select_format (ExportFormatPtr());
443         }
444
445         select_intersect = compat_intersect->get_intersection (*current_selection);
446         if (select_intersect->sample_rates_empty()) {
447                 select_sample_rate (SampleRatePtr());
448         }
449
450         select_intersect = compat_intersect->get_intersection (*current_selection);
451         if (select_intersect->sample_formats_empty()) {
452                 select_sample_format (SampleFormatPtr());
453         }
454 }
455
456 void
457 ExportFormatManager::select_quality (QualityPtr const & quality)
458 {
459         bool do_selection_changed = !pending_selection_change;
460         if (!pending_selection_change) {
461                 pending_selection_change = true;
462         }
463
464         if (quality) {
465                 current_selection->set_quality (quality->quality);
466
467                 /* Deselect format if it is incompatible */
468
469                 ExportFormatPtr format = get_selected_format();
470                 if (format && !format->has_quality (quality->quality)) {
471                         format->set_selected (false);
472                 }
473
474         } else {
475                 current_selection->set_quality (ExportFormatBase::Q_None);
476
477                 QualityPtr current_quality = get_selected_quality();
478                 if (current_quality) {
479                         current_quality->set_selected (false);
480                 }
481
482                 /* Note:
483                  * A quality is never explicitly deselected without also deselecting the format
484                  * so we don't need to deselect the format here.
485                  * doing so causes extra complications
486                  */
487         }
488
489         if (do_selection_changed) {
490                 selection_changed ();
491         }
492 }
493
494 void
495 ExportFormatManager::select_format (ExportFormatPtr const & format)
496 {
497         bool do_selection_changed = !pending_selection_change;
498         if (!pending_selection_change) {
499                 pending_selection_change = true;
500         }
501
502         current_selection->set_format (format);
503
504         if (format) {
505
506                 /* Slect right quality for format */
507
508                 ExportFormatBase::Quality quality = format->get_quality();
509                 for (QualityList::iterator it = qualities.begin (); it != qualities.end (); ++it) {
510                         if ((*it)->quality == quality) {
511                                 (*it)->set_selected (true);
512                         } else {
513                                 (*it)->set_selected (false);
514                         }
515                 }
516
517                 /* Handle sample formats */
518
519                 ExportFormatBase::SampleFormat format_to_select;
520                 if (format->sample_format_is_compatible (current_selection->sample_format())) {
521                         format_to_select = current_selection->sample_format();
522                 } else {
523                         format_to_select = format->default_sample_format();
524                 }
525
526                 boost::shared_ptr<HasSampleFormat> hsf;
527                 if ((hsf = boost::dynamic_pointer_cast<HasSampleFormat> (format))) {
528                         SampleFormatList sample_formats = hsf->get_sample_formats();
529                         for (SampleFormatList::iterator it = sample_formats.begin (); it != sample_formats.end (); ++it) {
530                                 if ((*it)->format == format_to_select) {
531                                         (*it)->set_selected (true);
532                                 } else {
533                                         (*it)->set_selected (false);
534                                 }
535                         }
536                 }
537
538                 current_selection->set_sample_format (format_to_select);
539
540         } else {
541                 ExportFormatPtr current_format = get_selected_format ();
542                 if (current_format) {
543                         current_format->set_selected (false);
544                 }
545         }
546
547         if (do_selection_changed) {
548                 selection_changed ();
549         }
550 }
551
552 void
553 ExportFormatManager::select_sample_rate (SampleRatePtr const & rate)
554 {
555
556         bool do_selection_changed = !pending_selection_change;
557         if (!pending_selection_change) {
558                 pending_selection_change = true;
559         }
560
561         if (rate) {
562                 current_selection->set_sample_rate (rate->rate);
563         } else {
564                 current_selection->set_sample_rate (ExportFormatBase::SR_None);
565
566                 SampleRatePtr current_rate = get_selected_sample_rate();
567                 if (current_rate) {
568                         current_rate->set_selected (false);
569                 }
570         }
571
572         if (do_selection_changed) {
573                 selection_changed ();
574         }
575 }
576
577 void
578 ExportFormatManager::select_sample_format (SampleFormatPtr const & format)
579 {
580
581         bool do_selection_changed = !pending_selection_change;
582         if (!pending_selection_change) {
583                 pending_selection_change = true;
584         }
585
586         if (format) {
587                 current_selection->set_sample_format (format->format);
588         } else {
589                 current_selection->set_sample_format (ExportFormatBase::SF_None);
590
591                 SampleFormatPtr current_format = get_selected_sample_format();
592                 if (current_format) {
593                         current_format->set_selected (false);
594                 }
595         }
596
597         if (do_selection_changed) {
598                 selection_changed ();
599         }
600 }
601
602 void
603 ExportFormatManager::select_dither_type (DitherTypePtr const & type)
604 {
605
606         bool do_selection_changed = !pending_selection_change;
607         if (!pending_selection_change) {
608                 pending_selection_change = true;
609         }
610
611         if (type) {
612                 current_selection->set_dither_type (type->type);
613         } else {
614                 current_selection->set_dither_type (ExportFormatBase::D_None);
615         }
616
617         if (do_selection_changed) {
618                 selection_changed ();
619         }
620 }
621
622 void
623 ExportFormatManager::selection_changed ()
624 {
625         /* Get a list of incompatible compatibility selections */
626
627         CompatList incompatibles;
628         for (CompatList::iterator it = compatibilities.begin(); it != compatibilities.end(); ++it) {
629                 if (!current_selection->is_compatible_with (**it)) {
630                         incompatibles.push_back (*it);
631                 }
632         }
633
634         /* Deselect them */
635
636         for (CompatList::iterator it = incompatibles.begin(); it != incompatibles.end(); ++it) {
637                 (*it)->set_selected (false);
638         }
639
640         /* Mark compatibility for everything necessary */
641
642         std::set<ExportFormatBase::Quality> compatible_qualities;
643         ExportFormatBasePtr compat_intersect = get_compatibility_intersection ();
644         ExportFormatCompatibility global_compat (*compat_intersect);
645
646         for (FormatList::iterator it = formats.begin(); it != formats.end(); ++it) {
647                 if ((*it)->set_compatibility_state (global_compat)) {
648                         compatible_qualities.insert ((*it)->get_quality());
649                 }
650         }
651
652         bool any_quality_compatible = true;
653         for (QualityList::iterator it = qualities.begin(); it != qualities.end(); ++it) {
654                 if (compatible_qualities.find((*it)->quality) != compatible_qualities.end()) {
655                         (*it)->set_compatible (true);
656
657                 } else {
658                         (*it)->set_compatible (false);
659
660                         if ((*it)->quality != ExportFormatBase::Q_Any) {
661                                 any_quality_compatible = false;
662                         }
663                 }
664         }
665
666         if (any_quality_compatible) {
667                 for (QualityList::iterator it = qualities.begin(); it != qualities.end(); ++it) {
668                         if ((*it)->quality == ExportFormatBase::Q_Any) {
669                                 (*it)->set_compatible (true);
670                                 break;
671                         }
672                 }
673         }
674
675         for (SampleRateList::iterator it = sample_rates.begin(); it != sample_rates.end(); ++it) {
676                 if (compat_intersect->has_sample_rate ((*it)->rate)) {
677                         (*it)->set_compatible (true);
678                 } else {
679                         (*it)->set_compatible (false);
680                 }
681         }
682
683         boost::shared_ptr<HasSampleFormat> hsf;
684         if ((hsf = boost::dynamic_pointer_cast<HasSampleFormat> (get_selected_format()))) {
685
686                 SampleFormatList sf_list = hsf->get_sample_formats();
687                 for (SampleFormatList::iterator it = sf_list.begin(); it != sf_list.end(); ++it) {
688                         if (compat_intersect->has_sample_format ((*it)->format)) {
689                                 (*it)->set_compatible (true);
690                         } else {
691                                 (*it)->set_compatible (false);
692                         }
693                 }
694
695         }
696
697         /* Signal completeness */
698
699         CompleteChanged (current_selection->is_complete());
700
701         /* Reset pending state */
702
703         pending_selection_change = false;
704 }
705
706 ExportFormatManager::QualityPtr
707 ExportFormatManager::get_selected_quality ()
708 {
709         for (QualityList::iterator it = qualities.begin(); it != qualities.end(); ++it) {
710                 if ((*it)->selected()) {
711                         return *it;
712                 }
713         }
714
715         return QualityPtr();
716 }
717
718 ExportFormatPtr
719 ExportFormatManager::get_selected_format ()
720 {
721         ExportFormatPtr format;
722
723         for (FormatList::iterator it = formats.begin(); it != formats.end(); ++it) {
724                 if ((*it)->selected()) {
725                         return *it;
726                 }
727         }
728
729         return format;
730 }
731
732 ExportFormatManager::SampleRatePtr
733 ExportFormatManager::get_selected_sample_rate ()
734 {
735         for (SampleRateList::iterator it = sample_rates.begin(); it != sample_rates.end(); ++it) {
736                 if ((*it)->selected()) {
737                         return *it;
738                 }
739         }
740
741         return SampleRatePtr();
742 }
743
744 ExportFormatManager::SampleFormatPtr
745 ExportFormatManager::get_selected_sample_format ()
746 {
747         boost::shared_ptr<HasSampleFormat> hsf;
748
749         if ((hsf = boost::dynamic_pointer_cast<HasSampleFormat> (get_selected_format()))) {
750                 return hsf->get_selected_sample_format ();
751         } else {
752                 return SampleFormatPtr ();
753         }
754 }
755
756
757 ExportFormatBasePtr
758 ExportFormatManager::get_compatibility_intersection ()
759 {
760         ExportFormatBasePtr compat_intersect = universal_set;
761
762         for (CompatList::iterator it = compatibilities.begin(); it != compatibilities.end(); ++it) {
763                 if ((*it)->selected ()) {
764                         compat_intersect = compat_intersect->get_intersection (**it);
765                 }
766         }
767
768         return compat_intersect;
769 }
770
771 }; // namespace ARDOUR