new automation state model, sort of working, but not really
[ardour.git] / libs / ardour / source_factory.cc
index e5bbe96d5ee04840d22b5e310fe26f37cff4d2d1..7e639590c5737bfa7305920544a37d6e288dad75 100644 (file)
@@ -18,6 +18,8 @@
     $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;
                }
@@ -66,17 +92,23 @@ SourceFactory::create (const XMLNode& node)
 #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;
        }
@@ -86,10 +118,13 @@ SourceFactory::create (const XMLNode& node)
 
 #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);
                }
@@ -97,7 +132,10 @@ SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool a
        }
 
        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);
                }
@@ -105,7 +143,10 @@ SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool a
        }
 
        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);
                }
@@ -118,9 +159,12 @@ SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool a
 #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);
        }
@@ -130,25 +174,31 @@ SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool a
 #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);
                }