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