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