summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-09-09 16:44:43 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-09-09 16:44:43 +0000
commitbf27a5c45ccf8a697534fe95a09184e3e48f5e17 (patch)
treec65755d77e1fa16e4ab80839e7d80185a3662362
parentde97630a217ab38e59827ba05a24edab5ba0b5b0 (diff)
async generation of peakfiles for embedded files
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2439 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/editor_audio_import.cc3
-rw-r--r--libs/ardour/ardour/source_factory.h8
-rw-r--r--libs/ardour/audiosource.cc6
-rw-r--r--libs/ardour/source_factory.cc37
4 files changed, 31 insertions, 23 deletions
diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc
index 8af1c6a601..ac29b5264e 100644
--- a/gtk2_ardour/editor_audio_import.cc
+++ b/gtk2_ardour/editor_audio_import.cc
@@ -511,7 +511,8 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
(*session, path, n,
(mode == ImportAsTapeTrack ?
AudioFileSource::Destructive :
- AudioFileSource::Flag (0))));
+ AudioFileSource::Flag (0)),
+ true, true));
} else {
source = boost::dynamic_pointer_cast<AudioFileSource> (s);
}
diff --git a/libs/ardour/ardour/source_factory.h b/libs/ardour/ardour/source_factory.h
index c979a575cf..94ceb9c441 100644
--- a/libs/ardour/ardour/source_factory.h
+++ b/libs/ardour/ardour/source_factory.h
@@ -38,15 +38,15 @@ class SourceFactory {
public:
static sigc::signal<void,boost::shared_ptr<Source> > SourceCreated;
- static boost::shared_ptr<Source> create (Session&, const XMLNode& node);
+ static boost::shared_ptr<Source> create (Session&, const XMLNode& node, bool async = false);
static boost::shared_ptr<Source> createSilent (Session&, const XMLNode& node, nframes_t nframes, float sample_rate);
// MIDI sources will have to be hacked in here somehow
- static boost::shared_ptr<Source> createReadable (Session&, std::string path, int chn, AudioFileSource::Flag flags, bool announce = true);
- static boost::shared_ptr<Source> createWritable (Session&, std::string name, bool destructive, nframes_t rate, bool announce = true);
+ static boost::shared_ptr<Source> createReadable (Session&, std::string path, int chn, AudioFileSource::Flag flags, bool announce = true, bool async = false);
+ static boost::shared_ptr<Source> createWritable (Session&, std::string name, bool destructive, nframes_t rate, bool announce = true, bool async = false);
private:
- static int setup_peakfile (boost::shared_ptr<Source>);
+ static int setup_peakfile (boost::shared_ptr<Source>, bool async);
};
}
diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc
index 0043df7d2e..3511b0c519 100644
--- a/libs/ardour/audiosource.cc
+++ b/libs/ardour/audiosource.cc
@@ -333,7 +333,7 @@ AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nfr
/* open, read, close */
if ((_peakfile = ::open (peakpath.c_str(), O_RDONLY, 0664)) < 0) {
- error << string_compose(_("AudioSource: cannot open peakpath \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
+ error << string_compose(_("AudioSource: cannot open peakpath (a) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
return -1;
}
@@ -407,7 +407,7 @@ AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nfr
/* open ... close during out: handling */
if ((_peakfile = ::open (peakpath.c_str(), O_RDONLY, 0664)) < 0) {
- error << string_compose(_("AudioSource: cannot open peakpath \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
+ error << string_compose(_("AudioSource: cannot open peakpath (b) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
return 0;
}
@@ -646,7 +646,7 @@ int
AudioSource::prepare_for_peakfile_writes ()
{
if ((peakfile = ::open (peakpath.c_str(), O_RDWR|O_CREAT, 0664)) < 0) {
- error << string_compose(_("AudioSource: cannot open peakpath \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
+ error << string_compose(_("AudioSource: cannot open peakpath (c) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
return -1;
}
return 0;
diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc
index 6ecd79844d..cd20060cfa 100644
--- a/libs/ardour/source_factory.cc
+++ b/libs/ardour/source_factory.cc
@@ -18,6 +18,8 @@
$Id$
*/
+#include <glibmm/thread.h>
+
#include <pbd/error.h>
#include <ardour/source_factory.h>
@@ -34,17 +36,22 @@
using namespace ARDOUR;
using namespace std;
using namespace PBD;
+using namespace sigc;
sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
int
-SourceFactory::setup_peakfile (boost::shared_ptr<Source> s)
+SourceFactory::setup_peakfile (boost::shared_ptr<Source> s, bool async)
{
boost::shared_ptr<AudioSource> as (boost::dynamic_pointer_cast<AudioSource> (s));
if (as) {
- if (as->setup_peakfile ()) {
- error << string_compose("SourceFactory: could not set up peakfile for %1", as->name()) << endmsg;
- return -1;
+ if (async) {
+ Glib::Thread::create (hide_return (mem_fun (*as, &AudioSource::setup_peakfile)), false);
+ } else {
+ if (as->setup_peakfile ()) {
+ error << string_compose("SourceFactory: could not set up peakfile for %1", as->name()) << endmsg;
+ return -1;
+ }
}
}
@@ -61,7 +68,7 @@ SourceFactory::createSilent (Session& s, const XMLNode& node, nframes_t nframes,
#ifdef HAVE_COREAUDIO
boost::shared_ptr<Source>
-SourceFactory::create (Session& s, const XMLNode& node)
+SourceFactory::create (Session& s, const XMLNode& node, bool async)
{
try {
boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
@@ -78,7 +85,7 @@ SourceFactory::create (Session& s, const XMLNode& node)
/* this is allowed to throw */
boost::shared_ptr<Source> ret (new SndFileSource (s, node));
- if (setup_peakfile (ret)) {
+ if (setup_peakfile (ret, async)) {
return boost::shared_ptr<Source>();
}
SourceCreated (ret);
@@ -91,13 +98,13 @@ SourceFactory::create (Session& s, const XMLNode& node)
#else
boost::shared_ptr<Source>
-SourceFactory::create (Session& s, const XMLNode& node)
+SourceFactory::create (Session& s, const XMLNode& node, bool async)
{
/* this is allowed to throw */
boost::shared_ptr<Source> ret (new SndFileSource (s, node));
- if (setup_peakfile (ret)) {
+ if (setup_peakfile (ret, async)) {
return boost::shared_ptr<Source>();
}
@@ -109,13 +116,13 @@ SourceFactory::create (Session& s, const XMLNode& node)
#ifdef HAVE_COREAUDIO
boost::shared_ptr<Source>
-SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
+SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce, bool async)
{
if (!(flags & Destructive)) {
try {
boost::shared_ptr<Source> ret (new CoreAudioSource (s, path, chn, flags));
- if (setup_peakfile (ret)) {
+ if (setup_peakfile (ret, async)) {
return boost::shared_ptr<Source>();
}
if (announce) {
@@ -141,7 +148,7 @@ SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource
} else {
boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
- if (setup_peakfile (ret)) {
+ if (setup_peakfile (ret, async)) {
return boost::shared_ptr<Source>();
}
if (announce) {
@@ -156,11 +163,11 @@ SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource
#else
boost::shared_ptr<Source>
-SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
+SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce, bool async)
{
boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
- if (setup_peakfile (ret)) {
+ if (setup_peakfile (ret, async)) {
return boost::shared_ptr<Source>();
}
@@ -174,7 +181,7 @@ SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource
#endif // HAVE_COREAUDIO
boost::shared_ptr<Source>
-SourceFactory::createWritable (Session& s, std::string path, bool destructive, nframes_t rate, bool announce)
+SourceFactory::createWritable (Session& s, std::string path, bool destructive, nframes_t rate, bool announce, bool async)
{
/* this might throw failed_constructor(), which is OK */
@@ -186,7 +193,7 @@ SourceFactory::createWritable (Session& s, std::string path, bool destructive, n
(destructive ? AudioFileSource::Flag (SndFileSource::default_writable_flags | AudioFileSource::Destructive) :
SndFileSource::default_writable_flags)));
- if (setup_peakfile (ret)) {
+ if (setup_peakfile (ret, async)) {
return boost::shared_ptr<Source>();
}
if (announce) {