+int
+SourceFactory::setup_peakfile (boost::shared_ptr<Source> s, bool async)
+{
+ boost::shared_ptr<AudioSource> as (boost::dynamic_pointer_cast<AudioSource> (s));
+
+ if (as) {
+
+ // immediately set 'peakfile-path' for empty and NoPeakFile sources
+ if (async && !as->empty() && !(as->flags() & Source::NoPeakFile)) {
+
+ Glib::Threads::Mutex::Lock lm (peak_building_lock);
+ files_with_peaks.push_back (boost::weak_ptr<AudioSource> (as));
+ PeaksToBuild.broadcast ();
+
+ } else {
+
+ if (as->setup_peakfile ()) {
+ error << string_compose("SourceFactory: could not set up peakfile for %1", as->name()) << endmsg;
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+boost::shared_ptr<Source>
+SourceFactory::createSilent (Session& s, const XMLNode& node, framecnt_t nframes, float sr)
+{
+ Source* src = new SilentFileSource (s, node, nframes, sr);
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
+ // boost_debug_shared_ptr_mark_interesting (src, "Source");
+#endif
+ boost::shared_ptr<Source> ret (src);
+ // no analysis data - the file is non-existent
+ SourceCreated (ret);
+ return ret;
+}
+
+boost::shared_ptr<Source>
+SourceFactory::create (Session& s, const XMLNode& node, bool defer_peaks)
+{
+ DataType type = DataType::AUDIO;
+ XMLProperty const * prop = node.property("type");
+
+ if (prop) {
+ type = DataType (prop->value());
+ }
+
+ if (type == DataType::AUDIO) {
+
+ /* it could be nested */
+
+ if (node.property ("playlist") != 0) {
+
+ try {
+ boost::shared_ptr<AudioPlaylistSource> ap (new AudioPlaylistSource (s, node));
+
+ if (setup_peakfile (ap, true)) {
+ return boost::shared_ptr<Source>();
+ }
+
+ ap->check_for_analysis_data_on_disk ();
+
+ SourceCreated (ap);
+ return ap;
+
+ } catch (failed_constructor&) {
+ /* oh well, so much for that then ... */
+ }
+
+ } else {
+
+
+ try {
+ Source* src = new SndFileSource (s, node);
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
+ // boost_debug_shared_ptr_mark_interesting (src, "Source");
+#endif
+ boost::shared_ptr<Source> ret (src);
+ if (setup_peakfile (ret, defer_peaks)) {
+ return boost::shared_ptr<Source>();
+ }
+ ret->check_for_analysis_data_on_disk ();
+ SourceCreated (ret);
+ return ret;
+ }
+
+ catch (failed_constructor& err) {