X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fardour%2Fsource_factory.cc;h=b0803a9d34cbf9d55f2f9cedc8fd0f5ddfb90f99;hb=dbafe45a280cc6c33bb7dca72202c109012cd8eb;hp=198a429c5d702f81bd7a45397e14f9f3af3d7acd;hpb=f76de9afb98611452c2cb0c4d233db362ef29924;p=ardour.git diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc index 198a429c5d..b0803a9d34 100644 --- a/libs/ardour/source_factory.cc +++ b/libs/ardour/source_factory.cc @@ -22,23 +22,23 @@ #include "libardour-config.h" #endif +#include "pbd/boost_debug.h" #include "pbd/error.h" #include "pbd/convert.h" #include "pbd/pthread_utils.h" #include "pbd/stacktrace.h" +#include "ardour/audioplaylist.h" +#include "ardour/audio_playlist_source.h" +#include "ardour/midi_playlist.h" +#include "ardour/midi_playlist_source.h" #include "ardour/source_factory.h" #include "ardour/sndfilesource.h" #include "ardour/silentfilesource.h" -#include "ardour/rc_configuration.h" #include "ardour/smf_source.h" #include "ardour/session.h" #ifdef HAVE_COREAUDIO -#define USE_COREAUDIO_FOR_FILES -#endif - -#ifdef USE_COREAUDIO_FOR_FILES #include "ardour/coreaudiosource.h" #endif @@ -49,7 +49,7 @@ using namespace ARDOUR; using namespace std; using namespace PBD; -sigc::signal > SourceFactory::SourceCreated; +PBD::Signal1 > SourceFactory::SourceCreated; Glib::Cond* SourceFactory::PeaksToBuild; Glib::StaticMutex SourceFactory::peak_building_lock = GLIBMM_STATIC_MUTEX_INIT; std::list > SourceFactory::files_with_peaks; @@ -57,7 +57,7 @@ std::list > SourceFactory::files_with_peaks; static void peak_thread_work () { - PBD::notify_gui_about_thread_creation (pthread_self(), string ("peakbuilder-") + to_string (pthread_self(), std::dec)); + SessionEvent::create_per_thread_pool (X_("PeakFile Builder "), 64); while (true) { @@ -120,9 +120,13 @@ SourceFactory::setup_peakfile (boost::shared_ptr s, bool async) } boost::shared_ptr -SourceFactory::createSilent (Session& s, const XMLNode& node, nframes_t nframes, float sr) +SourceFactory::createSilent (Session& s, const XMLNode& node, framecnt_t nframes, float sr) { - boost::shared_ptr ret (new SilentFileSource (s, node, nframes, 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 ret (src); // no analysis data - the file is non-existent SourceCreated (ret); return ret; @@ -140,50 +144,84 @@ SourceFactory::create (Session& s, const XMLNode& node, bool defer_peaks) if (type == DataType::AUDIO) { - try { + /* it could be nested */ - boost::shared_ptr ret (new SndFileSource (s, node)); - if (setup_peakfile (ret, defer_peaks)) { - return boost::shared_ptr(); - } - ret->check_for_analysis_data_on_disk (); - SourceCreated (ret); - return ret; - } + if (node.property ("playlist") != 0) { - catch (failed_constructor& err) { + try { + boost::shared_ptr ap (new AudioPlaylistSource (s, node)); + + if (setup_peakfile (ap, true)) { + return boost::shared_ptr(); + } -#ifdef USE_COREAUDIO_FOR_FILES + ap->check_for_analysis_data_on_disk (); - /* this is allowed to throw */ + SourceCreated (ap); + return ap; - boost::shared_ptr ret (new CoreAudioSource (s, node)); + } catch (failed_constructor&) { + /* oh well, so much for that then ... */ + } - if (setup_peakfile (ret, defer_peaks)) { - return boost::shared_ptr(); + } 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 ret (src); + if (setup_peakfile (ret, defer_peaks)) { + return boost::shared_ptr(); + } + ret->check_for_analysis_data_on_disk (); + SourceCreated (ret); + return ret; } - ret->check_for_analysis_data_on_disk (); - SourceCreated (ret); - return ret; + catch (failed_constructor& err) { + +#ifdef HAVE_COREAUDIO + + /* this is allowed to throw */ + + Source *src = new CoreAudioSource (s, node); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif + boost::shared_ptr ret (src); + + if (setup_peakfile (ret, defer_peaks)) { + return boost::shared_ptr(); + } + + ret->check_for_analysis_data_on_disk (); + SourceCreated (ret); + return ret; #else - throw; // rethrow + throw; // rethrow #endif + } } - } else if (type == DataType::MIDI) { - boost::shared_ptr ret (new SMFSource (s, node)); - ret->check_for_analysis_data_on_disk (); - SourceCreated (ret); - return ret; + boost::shared_ptr src (new SMFSource (s, node)); + src->load_model (true, true); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif + src->check_for_analysis_data_on_disk (); + SourceCreated (src); + return src; } return boost::shared_ptr(); } boost::shared_ptr -SourceFactory::createReadable (DataType type, Session& s, const string& path, bool embedded, - int chn, Source::Flag flags, bool announce, bool defer_peaks) +SourceFactory::createReadable (DataType type, Session& s, const string& path, + int chn, Source::Flag flags, bool announce, bool defer_peaks) { if (type == DataType::AUDIO) { @@ -191,7 +229,11 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path, bo try { - boost::shared_ptr ret (new SndFileSource (s, path, embedded, chn, flags)); + Source* src = new SndFileSource (s, path, chn, flags); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif + boost::shared_ptr ret (src); if (setup_peakfile (ret, defer_peaks)) { return boost::shared_ptr(); @@ -205,9 +247,13 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path, bo } catch (failed_constructor& err) { -#ifdef USE_COREAUDIO_FOR_FILES +#ifdef HAVE_COREAUDIO - boost::shared_ptr ret (new CoreAudioSource (s, path, embedded, chn, flags)); + Source* src = new CoreAudioSource (s, path, chn, flags); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif + boost::shared_ptr ret (src); if (setup_peakfile (ret, defer_peaks)) { return boost::shared_ptr(); } @@ -228,7 +274,12 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path, bo } else if (type == DataType::MIDI) { - boost::shared_ptr ret (new SMFSource (s, path, embedded, SMFSource::Flag(0))); + SMFSource* src = new SMFSource (s, path, SMFSource::Flag(0)); + src->load_model (true, true); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif + boost::shared_ptr ret (src); if (announce) { SourceCreated (ret); @@ -242,19 +293,23 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path, bo } boost::shared_ptr -SourceFactory::createWritable (DataType type, Session& s, const std::string& path, bool embedded, - bool destructive, nframes_t rate, bool announce, bool defer_peaks) +SourceFactory::createWritable (DataType type, Session& s, const std::string& path, const std::string& origin, + bool destructive, framecnt_t rate, bool announce, bool defer_peaks) { /* this might throw failed_constructor(), which is OK */ if (type == DataType::AUDIO) { - boost::shared_ptr ret (new SndFileSource (s, path, embedded, + Source* src = new SndFileSource (s, path, origin, s.config.get_native_file_data_format(), s.config.get_native_file_header_format(), rate, (destructive ? Source::Flag (SndFileSource::default_writable_flags | Source::Destructive) - : SndFileSource::default_writable_flags))); + : SndFileSource::default_writable_flags)); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif + boost::shared_ptr ret (src); if (setup_peakfile (ret, defer_peaks)) { return boost::shared_ptr(); @@ -268,18 +323,87 @@ SourceFactory::createWritable (DataType type, Session& s, const std::string& pat return ret; } else if (type == DataType::MIDI) { + // XXX writable flags should belong to MidiSource too + boost::shared_ptr src (new SMFSource (s, path, SndFileSource::default_writable_flags)); + assert (src->writable ()); - boost::shared_ptr ret (new SMFSource (s, path, embedded, Source::Flag(0))); + src->load_model (true, true); +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS + // boost_debug_shared_ptr_mark_interesting (src, "Source"); +#endif // no analysis data - this is a new file if (announce) { - SourceCreated (ret); + SourceCreated (src); } - return ret; + return src; } return boost::shared_ptr (); } +boost::shared_ptr +SourceFactory::createFromPlaylist (DataType type, Session& s, boost::shared_ptr p, const PBD::ID& orig, const std::string& name, + uint32_t chn, frameoffset_t start, framecnt_t len, bool copy, bool defer_peaks) +{ + if (type == DataType::AUDIO) { + try { + + boost::shared_ptr ap = boost::dynamic_pointer_cast(p); + + if (ap) { + + if (copy) { + ap.reset (new AudioPlaylist (ap, start, len, name, true)); + start = 0; + } + + Source* src = new AudioPlaylistSource (s, orig, name, ap, chn, start, len, Source::Flag (0)); + boost::shared_ptr ret (src); + + if (setup_peakfile (ret, defer_peaks)) { + return boost::shared_ptr(); + } + + ret->check_for_analysis_data_on_disk (); + SourceCreated (ret); + return ret; + } + } + + catch (failed_constructor& err) { + /* relax - return at function scope */ + } + + } else if (type == DataType::MIDI) { + + try { + + boost::shared_ptr ap = boost::dynamic_pointer_cast(p); + + if (ap) { + + if (copy) { + ap.reset (new MidiPlaylist (ap, start, len, name, true)); + start = 0; + } + + Source* src = new MidiPlaylistSource (s, orig, name, ap, chn, start, len, Source::Flag (0)); + boost::shared_ptr ret (src); + + SourceCreated (ret); + return ret; + } + } + + catch (failed_constructor& err) { + /* relax - return at function scope */ + } + + } + + return boost::shared_ptr(); +} +