$Id$
*/
+#include <pbd/error.h>
+
#include <ardour/source_factory.h>
#include <ardour/sndfilesource.h>
#include <ardour/destructive_filesource.h>
using namespace ARDOUR;
using namespace std;
+using namespace PBD;
sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
+int
+SourceFactory::setup_peakfile (boost::shared_ptr<Source> s)
+{
+ 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;
+ }
+ }
+
+ return 0;
+}
+
#ifdef HAVE_COREAUDIO
boost::shared_ptr<Source>
-SourceFactory::create (const XMLNode& node)
+SourceFactory::create (Session& s, const XMLNode& node)
{
if (node.property (X_("destructive")) != 0) {
-
- boost::shared_ptr<Source> ret (new DestructiveFileSource (node));
+
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
SourceCreated (ret);
return ret;
} else {
try {
- boost::shared_ptr<Source> ret (new CoreAudioSource (node));
+ boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
SourceCreated (ret);
return ret;
}
catch (failed_constructor& err) {
- boost::shared_ptr<Source> ret (new SndFileSource (node));
+ boost::shared_ptr<Source> ret (new SndFileSource (s, node));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
SourceCreated (ret);
return ret;
}
#else
boost::shared_ptr<Source>
-SourceFactory::create (const XMLNode& node)
+SourceFactory::create (Session& s, const XMLNode& node)
{
if (node.property (X_("destructive")) != 0) {
- boost::shared_ptr<Source> ret (new DestructiveFileSource (node));
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
SourceCreated (ret);
return ret;
} else {
- boost::shared_ptr<Source> ret (new SndFileSource (node));
+ boost::shared_ptr<Source> ret (new SndFileSource (s, node));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
SourceCreated (ret);
return ret;
}
#ifdef HAVE_COREAUDIO
boost::shared_ptr<Source>
-SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool announce)
+SourceFactory::createReadable (Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
{
if (flags & Destructive) {
- boost::shared_ptr<Source> ret (new DestructiveFileSource (idstr, flags));
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (s, idstr, flags));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
if (announce) {
SourceCreated (ret);
}
}
try {
- boost::shared_ptr<Source> ret (new CoreAudioSource (idstr, flags));
+ boost::shared_ptr<Source> ret (new CoreAudioSource (s, idstr, flags));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
if (announce) {
SourceCreated (ret);
}
}
catch (failed_constructor& err) {
- boost::shared_ptr<Source> ret (new SndFileSource (idstr, flags));
+ boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
if (announce) {
SourceCreated (ret);
}
#else
boost::shared_ptr<Source>
-SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool announce)
+SourceFactory::createReadable (Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
{
- boost::shared_ptr<Source> ret (new SndFileSource (idstr, flags));
+ boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
if (announce) {
SourceCreated (ret);
}
#endif // HAVE_COREAUDIO
boost::shared_ptr<Source>
-SourceFactory::createWritable (std::string path, bool destructive, jack_nframes_t rate, bool announce)
+SourceFactory::createWritable (Session& s, std::string path, bool destructive, nframes_t rate, bool announce)
{
/* this might throw failed_constructor(), which is OK */
if (destructive) {
- boost::shared_ptr<Source> ret (new DestructiveFileSource (path,
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (s, path,
Config->get_native_file_data_format(),
Config->get_native_file_header_format(),
rate));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
if (announce) {
SourceCreated (ret);
}
return ret;
} else {
- boost::shared_ptr<Source> ret (new SndFileSource (path,
+ boost::shared_ptr<Source> ret (new SndFileSource (s, path,
Config->get_native_file_data_format(),
Config->get_native_file_header_format(),
rate));
+ if (setup_peakfile (ret)) {
+ return boost::shared_ptr<Source>();
+ }
if (announce) {
SourceCreated (ret);
}