remove Glib::ustring from libardour; allow any characters except '/' and '\' in paths...
[ardour.git] / libs / ardour / export_profile_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 <cassert>
22 #include <stdexcept>
23
24 #include <glibmm/fileutils.h>
25
26 #include "pbd/enumwriter.h"
27 #include "pbd/xml++.h"
28 #include "pbd/convert.h"
29
30 #include "ardour/export_profile_manager.h"
31 #include "ardour/export_format_specification.h"
32 #include "ardour/export_timespan.h"
33 #include "ardour/export_channel_configuration.h"
34 #include "ardour/export_filename.h"
35 #include "ardour/export_preset.h"
36 #include "ardour/export_handler.h"
37 #include "ardour/export_failed.h"
38 #include "ardour/filename_extensions.h"
39 #include "ardour/route.h"
40 #include "ardour/session.h"
41 #include "ardour/broadcast_info.h"
42
43 #include "i18n.h"
44
45 using namespace std;
46 using namespace Glib;
47 using namespace PBD;
48
49 namespace ARDOUR
50 {
51
52 ExportProfileManager::ExportProfileManager (Session & s) :
53   handler (s.get_export_handler()),
54   session (s),
55
56   session_range (new Location (s)),
57   ranges (new LocationList ()),
58   single_range_mode (false),
59
60   format_list (new FormatList ())
61 {
62
63         /* Initialize path variables */
64
65         export_config_dir = user_config_directory();
66         export_config_dir /= "export";
67         search_path += export_config_dir;
68
69         search_path += ardour_search_path().add_subdirectory_to_paths("export");
70         search_path += system_config_search_path().add_subdirectory_to_paths("export");;
71
72         /* create export config directory if necessary */
73
74         if (!sys::exists (export_config_dir)) {
75                 sys::create_directory (export_config_dir);
76         }
77
78         load_presets ();
79         load_formats ();
80
81         /* Initialize all lists with an empty config */
82
83         XMLNodeList dummy;
84         init_timespans (dummy);
85         init_channel_configs (dummy);
86         init_formats (dummy);
87         init_filenames (dummy);
88 }
89
90 ExportProfileManager::~ExportProfileManager ()
91 {
92         if (single_range_mode) { return; }
93
94         XMLNode * instant_xml (new XMLNode ("ExportProfile"));
95         serialize_profile (*instant_xml);
96         session.add_instant_xml (*instant_xml, false);
97 }
98
99 void
100 ExportProfileManager::load_profile ()
101 {
102         XMLNode * instant_node = session.instant_xml ("ExportProfile");
103         if (instant_node) {
104                 set_state (*instant_node);
105         } else {
106                 XMLNode empty_node ("ExportProfile");
107                 set_state (empty_node);
108         }
109 }
110
111 void
112 ExportProfileManager::prepare_for_export ()
113 {
114         ChannelConfigPtr channel_config = channel_configs.front()->config;
115         TimespanListPtr ts_list = timespans.front()->timespans;
116
117         FormatStateList::const_iterator format_it;
118         FilenameStateList::const_iterator filename_it;
119
120         for (TimespanList::iterator ts_it = ts_list->begin(); ts_it != ts_list->end(); ++ts_it) {
121                 for (format_it = formats.begin(), filename_it = filenames.begin();
122                      format_it != formats.end() && filename_it != filenames.end();
123                      ++format_it, ++filename_it) {
124
125 //                      filename->include_timespan = (ts_list->size() > 1); Disabled for now...
126
127                         boost::shared_ptr<BroadcastInfo> b;
128                         if ((*format_it)->format->has_broadcast_info()) {
129                                 b.reset (new BroadcastInfo);
130                                 b->set_from_session (session, (*ts_it)->get_start());
131                         }
132                         
133                         handler->add_export_config (*ts_it, channel_config, (*format_it)->format, (*filename_it)->filename, b);
134                 }
135         }
136 }
137
138 bool
139 ExportProfileManager::load_preset (PresetPtr preset)
140 {
141         bool ok = true;
142
143         current_preset = preset;
144         if (!preset) { return false; }
145
146         XMLNode const * state;
147         if ((state = preset->get_local_state())) {
148                 set_local_state (*state);
149         } else { ok = false; }
150
151         if ((state = preset->get_global_state())) {
152                 if (!set_global_state (*state)) {
153                         ok = false;
154                 }
155         } else { ok = false; }
156
157         return ok;
158 }
159
160 void
161 ExportProfileManager::load_presets ()
162 {
163         vector<sys::path> found = find_file (string_compose (X_("*%1"),export_preset_suffix));
164
165         for (vector<sys::path>::iterator it = found.begin(); it != found.end(); ++it) {
166                 load_preset_from_disk (*it);
167         }
168 }
169
170 ExportProfileManager::PresetPtr
171 ExportProfileManager::save_preset (string const & name)
172 {
173         string filename = export_config_dir.to_string() + "/" + name + export_preset_suffix;
174
175         if (!current_preset) {
176                 current_preset.reset (new ExportPreset (filename, session));
177                 preset_list.push_back (current_preset);
178         }
179
180         XMLNode * global_preset = new XMLNode ("ExportPreset");
181         XMLNode * local_preset = new XMLNode ("ExportPreset");
182
183         serialize_global_profile (*global_preset);
184         serialize_local_profile (*local_preset);
185
186         current_preset->set_name (name);
187         current_preset->set_global_state (*global_preset);
188         current_preset->set_local_state (*local_preset);
189
190         current_preset->save (filename);
191
192         return current_preset;
193 }
194
195 void
196 ExportProfileManager::remove_preset ()
197 {
198         if (!current_preset) { return; }
199
200         for (PresetList::iterator it = preset_list.begin(); it != preset_list.end(); ++it) {
201                 if (*it == current_preset) {
202                         preset_list.erase (it);
203                         break;
204                 }
205         }
206
207         FileMap::iterator it = preset_file_map.find (current_preset->id());
208         if (it != preset_file_map.end()) {
209                 sys::remove (it->second);
210                 preset_file_map.erase (it);
211         }
212
213         current_preset->remove_local();
214         current_preset.reset();
215 }
216
217 void
218 ExportProfileManager::load_preset_from_disk (PBD::sys::path const & path)
219 {
220         PresetPtr preset (new ExportPreset (path.to_string(), session));
221
222         /* Handle id to filename mapping and don't add duplicates to list */
223
224         FilePair pair (preset->id(), path);
225         if (preset_file_map.insert (pair).second) {
226                 preset_list.push_back (preset);
227         }
228 }
229
230 bool
231 ExportProfileManager::set_state (XMLNode const & root)
232 {
233         return set_global_state (root) & set_local_state (root);
234 }
235
236 bool
237 ExportProfileManager::set_global_state (XMLNode const & root)
238 {
239         return init_filenames (root.children ("ExportFilename")) &
240                init_formats (root.children ("ExportFormat"));
241 }
242
243 bool
244 ExportProfileManager::set_local_state (XMLNode const & root)
245 {
246         return init_timespans (root.children ("ExportTimespan")) &
247                init_channel_configs (root.children ("ExportChannelConfiguration"));
248 }
249
250 void
251 ExportProfileManager::serialize_profile (XMLNode & root)
252 {
253         serialize_local_profile (root);
254         serialize_global_profile (root);
255 }
256
257 void
258 ExportProfileManager::serialize_global_profile (XMLNode & root)
259 {
260         for (FormatStateList::iterator it = formats.begin(); it != formats.end(); ++it) {
261                 root.add_child_nocopy (serialize_format (*it));
262         }
263
264         for (FilenameStateList::iterator it = filenames.begin(); it != filenames.end(); ++it) {
265                 root.add_child_nocopy ((*it)->filename->get_state());
266         }
267 }
268
269 void
270 ExportProfileManager::serialize_local_profile (XMLNode & root)
271 {
272         for (TimespanStateList::iterator it = timespans.begin(); it != timespans.end(); ++it) {
273                 root.add_child_nocopy (serialize_timespan (*it));
274         }
275
276         for (ChannelConfigStateList::iterator it = channel_configs.begin(); it != channel_configs.end(); ++it) {
277                 root.add_child_nocopy ((*it)->config->get_state());
278         }
279 }
280
281 std::vector<sys::path>
282 ExportProfileManager::find_file (std::string const & pattern)
283 {
284         vector<sys::path> found;
285
286         Glib::PatternSpec pattern_spec (pattern);
287         find_matching_files_in_search_path (search_path, pattern_spec, found);
288
289         return found;
290 }
291
292 void
293 ExportProfileManager::set_selection_range (nframes_t start, nframes_t end)
294 {
295
296         if (start || end) {
297                 selection_range.reset (new Location (session));
298                 selection_range->set_name (_("Selection"));
299                 selection_range->set (start, end);
300         } else {
301                 selection_range.reset();
302         }
303
304         for (TimespanStateList::iterator it = timespans.begin(); it != timespans.end(); ++it) {
305                 (*it)->selection_range = selection_range;
306         }
307 }
308
309 std::string
310 ExportProfileManager::set_single_range (nframes_t start, nframes_t end, string name)
311 {
312         single_range_mode = true;
313
314         single_range.reset (new Location (session));
315         single_range->set_name (name);
316         single_range->set (start, end);
317
318         update_ranges ();
319
320         return single_range->id().to_s();
321 }
322
323 bool
324 ExportProfileManager::init_timespans (XMLNodeList nodes)
325 {
326         timespans.clear ();
327         update_ranges ();
328
329         bool ok = true;
330         for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
331                 TimespanStatePtr span = deserialize_timespan (**it);
332                 if (span) {
333                         timespans.push_back (span);
334                 } else { ok = false; }
335         }
336
337         if (timespans.empty()) {
338                 TimespanStatePtr state (new TimespanState (session_range, selection_range, ranges));
339                 timespans.push_back (state);
340                 
341                 // Add session as default selection
342                 TimespanPtr timespan = handler->add_timespan();
343                 timespan->set_name (session_range->name());
344                 timespan->set_range_id ("session");
345                 timespan->set_range (session_range->start(), session_range->end());
346                 state->timespans->push_back (timespan);
347                 return false;
348         }
349
350         return ok;
351 }
352
353 ExportProfileManager::TimespanStatePtr
354 ExportProfileManager::deserialize_timespan (XMLNode & root)
355 {
356         TimespanStatePtr state (new TimespanState (session_range, selection_range, ranges));
357         XMLProperty const * prop;
358
359         XMLNodeList spans = root.children ("Range");
360         for (XMLNodeList::iterator node_it = spans.begin(); node_it != spans.end(); ++node_it) {
361
362                 prop = (*node_it)->property ("id");
363                 if (!prop) { continue; }
364                 string id = prop->value();
365
366                 for (LocationList::iterator it = ranges->begin(); it != ranges->end(); ++it) {
367                         if ((!id.compare ("session") && *it == session_range.get()) ||
368                             (!id.compare ("selection") && *it == selection_range.get()) ||
369                             (!id.compare ((*it)->id().to_s()))) {
370                                 TimespanPtr timespan = handler->add_timespan();
371                                 timespan->set_name ((*it)->name());
372                                 timespan->set_range_id (id);
373                                 timespan->set_range ((*it)->start(), (*it)->end());
374                                 state->timespans->push_back (timespan);
375                         }
376                 }
377         }
378
379         if ((prop = root.property ("format"))) {
380                 state->time_format = (TimeFormat) string_2_enum (prop->value(), TimeFormat);
381         }
382
383         return state;
384 }
385
386 XMLNode &
387 ExportProfileManager::serialize_timespan (TimespanStatePtr state)
388 {
389         XMLNode & root = *(new XMLNode ("ExportTimespan"));
390         XMLNode * span;
391
392         update_ranges ();
393
394         for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
395                 if ((span = root.add_child ("Range"))) {
396                         span->add_property ("id", (*it)->range_id());
397                 }
398         }
399
400         root.add_property ("format", enum_2_string (state->time_format));
401
402         return root;
403 }
404
405 void
406 ExportProfileManager::update_ranges () {
407         ranges->clear();
408
409         if (single_range_mode) {
410                 ranges->push_back (single_range.get());
411                 return;
412         }
413
414         /* Session */
415
416         session_range->set_name (_("Session"));
417         session_range->set (session.current_start_frame(), session.current_end_frame());
418         ranges->push_back (session_range.get());
419
420         /* Selection */
421
422         if (selection_range) {
423                 ranges->push_back (selection_range.get());
424         }
425
426         /* ranges */
427
428         LocationList const & list (session.locations()->list());
429         for (LocationList::const_iterator it = list.begin(); it != list.end(); ++it) {
430                 if ((*it)->is_range_marker()) {
431                         ranges->push_back (*it);
432                 }
433         }
434 }
435
436 bool
437 ExportProfileManager::init_channel_configs (XMLNodeList nodes)
438 {
439         channel_configs.clear();
440
441         if (nodes.empty()) {
442                 ChannelConfigStatePtr config (new ChannelConfigState (handler->add_channel_config()));
443                 channel_configs.push_back (config);
444                 
445                 // Add master outs as default
446                 IO* master_out = session.master_out()->output().get();
447                 if (!master_out) { return false; }
448                 
449                 for (uint32_t n = 0; n < master_out->n_ports().n_audio(); ++n) {
450                         PortExportChannel * channel = new PortExportChannel ();
451                         channel->add_port (master_out->audio (n));
452                         
453                         ExportChannelPtr chan_ptr (channel);
454                         config->config->register_channel (chan_ptr);
455                 }
456                 return false;
457         }
458
459         for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
460                 ChannelConfigStatePtr config (new ChannelConfigState (handler->add_channel_config()));
461                 config->config->set_state (**it);
462                 channel_configs.push_back (config);
463         }
464
465         return true;
466 }
467
468 ExportProfileManager::FormatStatePtr
469 ExportProfileManager::duplicate_format_state (FormatStatePtr state)
470 {
471         /* Note: The pointer in the new FormatState should point to the same format spec
472                  as the original state's pointer. The spec itself should not be copied!   */
473
474         FormatStatePtr format (new FormatState (format_list, state->format));
475         formats.push_back (format);
476         return format;
477 }
478
479 void
480 ExportProfileManager::remove_format_state (FormatStatePtr state)
481 {
482         for (FormatStateList::iterator it = formats.begin(); it != formats.end(); ++it) {
483                 if (*it == state) {
484                         formats.erase (it);
485                         return;
486                 }
487         }
488 }
489
490 sys::path
491 ExportProfileManager::save_format_to_disk (FormatPtr format)
492 {
493         // TODO filename character stripping
494
495         /* Get filename for file */
496
497         string new_name = format->name();
498         new_name += export_format_suffix;
499
500         sys::path new_path (export_config_dir);
501         new_path /= new_name;
502
503         /* Check if format is on disk already */
504         FileMap::iterator it;
505         if ((it = format_file_map.find (format->id())) != format_file_map.end()) {
506
507                 /* Check if config is not in user config dir */
508                 if (it->second.branch_path().to_string().compare (export_config_dir.to_string())) {
509
510                         /* Write new file */
511
512                         XMLTree tree (new_path.to_string());
513                         tree.set_root (&format->get_state());
514                         tree.write();
515
516                 } else {
517
518                         /* Update file and rename if necessary */
519
520                         XMLTree tree (it->second.to_string());
521                         tree.set_root (&format->get_state());
522                         tree.write();
523
524                         if (new_name.compare (it->second.leaf())) {
525                                 sys::rename (it->second, new_path);
526                         }
527                 }
528
529                 it->second = new_path;
530
531         } else {
532                 /* Write new file */
533
534                 XMLTree tree (new_path.to_string());
535                 tree.set_root (&format->get_state());
536                 tree.write();
537         }
538
539         FormatListChanged ();
540         return new_path;
541 }
542
543 void
544 ExportProfileManager::remove_format_profile (FormatPtr format)
545 {
546         for (FormatList::iterator it = format_list->begin(); it != format_list->end(); ++it) {
547                 if (*it == format) {
548                         format_list->erase (it);
549                         break;
550                 }
551         }
552
553         FileMap::iterator it = format_file_map.find (format->id());
554         if (it != format_file_map.end()) {
555                 sys::remove (it->second);
556                 format_file_map.erase (it);
557         }
558
559         FormatListChanged ();
560 }
561
562 ExportProfileManager::FormatPtr
563 ExportProfileManager::get_new_format (FormatPtr original)
564 {
565         FormatPtr format;
566         if (original) {
567                 format.reset (new ExportFormatSpecification (*original));
568         } else {
569                 format = handler->add_format();
570                 format->set_name ("empty format");
571         }
572
573         sys::path path = save_format_to_disk (format);
574         FilePair pair (format->id(), path);
575         format_file_map.insert (pair);
576
577         format_list->push_back (format);
578         FormatListChanged ();
579
580         return format;
581 }
582
583 bool
584 ExportProfileManager::init_formats (XMLNodeList nodes)
585 {
586         formats.clear();
587
588         bool ok = true;
589         for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
590                 FormatStatePtr format = deserialize_format (**it);
591                 if (format) {
592                         formats.push_back (format);
593                 } else { ok = false; }
594         }
595
596         if (formats.empty ()) {
597                 FormatStatePtr format (new FormatState (format_list, FormatPtr ()));
598                 formats.push_back (format);
599                 return false;
600         }
601
602         return ok;
603 }
604
605 ExportProfileManager::FormatStatePtr
606 ExportProfileManager::deserialize_format (XMLNode & root)
607 {
608         XMLProperty * prop;
609         UUID id;
610
611         if ((prop = root.property ("id"))) {
612                 id = prop->value();
613         }
614
615         for (FormatList::iterator it = format_list->begin(); it != format_list->end(); ++it) {
616                 if ((*it)->id() == id) {
617                         return FormatStatePtr (new FormatState (format_list, *it));
618                 }
619         }
620
621         return FormatStatePtr ();
622 }
623
624 XMLNode &
625 ExportProfileManager::serialize_format (FormatStatePtr state)
626 {
627         XMLNode * root = new XMLNode ("ExportFormat");
628
629         string id = state->format ? state->format->id().to_s() : "";
630         root->add_property ("id", id);
631
632         return *root;
633 }
634
635 void
636 ExportProfileManager::load_formats ()
637 {
638         vector<sys::path> found = find_file (string_compose ("*%1", export_format_suffix));
639
640         for (vector<sys::path>::iterator it = found.begin(); it != found.end(); ++it) {
641                 load_format_from_disk (*it);
642         }
643 }
644
645 void
646 ExportProfileManager::load_format_from_disk (PBD::sys::path const & path)
647 {
648         XMLTree const tree (path.to_string());
649         FormatPtr format = handler->add_format (*tree.root());
650
651         /* Handle id to filename mapping and don't add duplicates to list */
652
653         FilePair pair (format->id(), path);
654         if (format_file_map.insert (pair).second) {
655                 format_list->push_back (format);
656         }
657
658         FormatListChanged ();
659 }
660
661 ExportProfileManager::FilenameStatePtr
662 ExportProfileManager::duplicate_filename_state (FilenameStatePtr state)
663 {
664         FilenameStatePtr filename (new FilenameState (handler->add_filename_copy (state->filename)));
665         filenames.push_back (filename);
666         return filename;
667 }
668
669 void
670 ExportProfileManager::remove_filename_state (FilenameStatePtr state)
671 {
672         for (FilenameStateList::iterator it = filenames.begin(); it != filenames.end(); ++it) {
673                 if (*it == state) {
674                         filenames.erase (it);
675                         return;
676                 }
677         }
678 }
679
680 bool
681 ExportProfileManager::init_filenames (XMLNodeList nodes)
682 {
683         filenames.clear ();
684
685         for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
686                 FilenamePtr filename = handler->add_filename();
687                 filename->set_state (**it);
688                 filenames.push_back (FilenameStatePtr (new FilenameState (filename)));
689         }
690
691         if (filenames.empty()) {
692                 FilenameStatePtr filename (new FilenameState (handler->add_filename()));
693                 filenames.push_back (filename);
694                 return false;
695         }
696
697         return true;
698 }
699
700 boost::shared_ptr<ExportProfileManager::Warnings>
701 ExportProfileManager::get_warnings ()
702 {
703         boost::shared_ptr<Warnings> warnings (new Warnings ());
704
705         ChannelConfigStatePtr channel_config_state = channel_configs.front();
706         TimespanStatePtr timespan_state = timespans.front();
707
708         /*** Check "global" config ***/
709
710         TimespanListPtr timespans = timespan_state->timespans;
711         ChannelConfigPtr channel_config = channel_config_state->config;
712
713         /* Check Timespans are not empty */
714
715         if (timespans->empty()) {
716                 warnings->errors.push_back (_("No timespan has been selected!"));
717         }
718
719         /* Check channel config ports */
720
721         if (!channel_config->all_channels_have_ports ()) {
722                 warnings->warnings.push_back (_("Some channels are empty"));
723         }
724
725         /*** Check files ***/
726
727         FormatStateList::const_iterator format_it;
728         FilenameStateList::const_iterator filename_it;
729         for (format_it = formats.begin(), filename_it = filenames.begin();
730              format_it != formats.end() && filename_it != filenames.end();
731              ++format_it, ++filename_it) {
732                         check_config (warnings, timespan_state, channel_config_state, *format_it, *filename_it);
733         }
734
735         return warnings;
736 }
737
738 void
739 ExportProfileManager::check_config (boost::shared_ptr<Warnings> warnings,
740                                     TimespanStatePtr timespan_state,
741                                     ChannelConfigStatePtr channel_config_state,
742                                     FormatStatePtr format_state,
743                                     FilenameStatePtr filename_state)
744 {
745         TimespanListPtr timespans = timespan_state->timespans;
746         ChannelConfigPtr channel_config = channel_config_state->config;
747         FormatPtr format = format_state->format;
748         FilenamePtr filename = filename_state->filename;
749
750         /* Check format and maximum channel count */
751         if (!format || !format->type()) {
752                 warnings->errors.push_back (_("No format selected!"));
753         } else if (!channel_config->get_n_chans()) {
754                 warnings->errors.push_back (_("All channels are empty!"));
755         } else if (!check_format (format, channel_config->get_n_chans())) {
756                 warnings->errors.push_back (_("One or more of the selected formats is not compatible with this system!"));
757         } else if (format->channel_limit() < channel_config->get_n_chans()) {
758                 warnings->errors.push_back
759                   (string_compose (_("%1 supports only %2 channels, but you have %3 channels in your channel configuration"),
760                                      format->format_name(),
761                                      format->channel_limit(),
762                                      channel_config->get_n_chans()));
763         }
764
765         if (!warnings->errors.empty()) { return; }
766
767         /* Check filenames */
768
769 //      filename->include_timespan = (timespans->size() > 1); Disabled for now...
770
771         for (std::list<TimespanPtr>::iterator timespan_it = timespans->begin(); timespan_it != timespans->end(); ++timespan_it) {
772                 filename->set_timespan (*timespan_it);
773
774                 if (channel_config->get_split()) {
775                         filename->include_channel = true;
776
777                         for (uint32_t chan = 1; chan <= channel_config->get_n_chans(); ++chan) {
778                                 filename->set_channel (chan);
779
780                                 string path = filename->get_path (format);
781
782                                 if (sys::exists (sys::path (path))) {
783                                         warnings->conflicting_filenames.push_back (path);
784                                 }
785                         }
786
787                 } else {
788                         string path = filename->get_path (format);
789
790                         if (sys::exists (sys::path (path))) {
791                                 warnings->conflicting_filenames.push_back (path);
792                         }
793                 }
794         }
795 }
796
797 bool
798 ExportProfileManager::check_format (FormatPtr format, uint32_t channels)
799 {
800         switch (format->type()) {
801           case ExportFormatBase::T_Sndfile:
802                 return check_sndfile_format (format, channels);
803
804           default:
805                 throw ExportFailed (X_("Invalid format given for ExportFileFactory::check!"));
806         }
807 }
808
809 bool
810 ExportProfileManager::check_sndfile_format (FormatPtr format, unsigned int channels)
811 {
812         SF_INFO sf_info;
813         sf_info.channels = channels;
814         sf_info.samplerate = format->sample_rate ();
815         sf_info.format = format->format_id () | format->sample_format ();
816
817         return (sf_format_check (&sf_info) == SF_TRUE ? true : false);
818 }
819
820 }; // namespace ARDOUR