add a pure virtual FileSource::close() method so that FileSource::set_path() can...
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 20 Apr 2015 20:31:06 +0000 (16:31 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 20 Apr 2015 20:31:06 +0000 (16:31 -0400)
libs/ardour/ardour/coreaudiosource.h
libs/ardour/ardour/file_source.h
libs/ardour/ardour/silentfilesource.h
libs/ardour/ardour/smf_source.h
libs/ardour/ardour/sndfilesource.h
libs/ardour/ardour/srcfilesource.h
libs/ardour/coreaudiosource.cc
libs/ardour/file_source.cc
libs/ardour/smf_source.cc
libs/ardour/sndfilesource.cc
libs/ardour/srcfilesource.cc

index f12a67ded7fae8ad8c05a8e1e38cf16a38add86a..5e8e696bf9ebd3100cd9835edd69e3c11a37746b 100644 (file)
@@ -48,6 +48,7 @@ class LIBARDOUR_API CoreAudioSource : public AudioFileSource {
        static int get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg);
 
   protected:
+       void close ();
        framecnt_t read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const;
        framecnt_t write_unlocked (Sample *, framecnt_t) { return 0; }
 
index 4f313c5eac9c6b5e44455a334ecfc0590fae2c35..0929c3303fa5947fc3b29fd203c0d73b17f02548 100644 (file)
@@ -89,9 +89,9 @@ public:
         */
        int rename (const std::string& name);
 
-       virtual void release_descriptor () {}
+       virtual void close () = 0;
 
-protected:
+  protected:
        FileSource (Session& session, DataType type,
                    const std::string& path,
                    const std::string& origin,
index cf6462247ae05ca1d07d8a7894e53bfddaf23fab..80f4b361b233517693003840722d45967ab46f86 100644 (file)
@@ -40,6 +40,7 @@ public:
        bool clamped_at_unity() const { return false; }
 
 protected:
+       void close() {}
        friend class SourceFactory;
 
        SilentFileSource (Session& s, const XMLNode& x, framecnt_t len, float srate)
index d088f2d867a3e8d6aa8606ada90d803b23d24629..35e0c892970da18c338c430ebfc048924f70b32c 100644 (file)
@@ -72,6 +72,7 @@ public:
        void prevent_deletion ();
 
   protected:
+       void close ();
        void set_path (const std::string& newpath);
        void flush_midi (const Lock& lock);
 
index 11ec6fe33c6cf800737843257b2698aa9fa94aeb..5a4a11515c16d499f1bde9daddb41d4c9316d6cd 100644 (file)
@@ -75,6 +75,8 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
        static int get_soundfile_info (const std::string& path, SoundFileInfo& _info, std::string& error_msg);
 
   protected:
+       void close ();
+
        void set_path (const std::string& p);
        void set_header_timeline_position ();
 
index 78564c8b8893a7562ce2c1cb72c189c9f8e6b923..073329cc29474fa51b440b5a4b428a7ee02aeb0d 100644 (file)
@@ -52,6 +52,7 @@ public:
        bool clamped_at_unity() const { return false; }
 
 protected:
+       void close ();
        framecnt_t read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const;
        framecnt_t write_unlocked (Sample */*dst*/, framecnt_t /*cnt*/) { return 0; }
 
index 010905d120cc371beaa8437b0e6613a8674bed8c..33753f481f2a22a960168020e0704ccb78a3f248 100644 (file)
@@ -104,6 +104,12 @@ CoreAudioSource::~CoreAudioSource ()
 {
 }
 
+void
+CoreAudioSource::close ()
+{
+       af.Close ();
+}
+
 int
 CoreAudioSource::safe_read (Sample* dst, framepos_t start, framecnt_t cnt, AudioBufferList& abl) const
 {
index b4ecb157c5038e916a22e0a2391b4fa5559c15a1..507f0df49c84647144cc616cfa4b1c8b4ec430d8 100644 (file)
@@ -544,6 +544,7 @@ FileSource::set_within_session_from_path (const std::string& path)
 void
 FileSource::set_path (const std::string& newpath)
 {
+       close ();
         _path = newpath;
        set_within_session_from_path (newpath);
        if (_within_session) {
index d2d96247fc707274a3e46439ba0886a34e8d1bc8..cc547ed9f5bd88cdd255acc30cee4e8ad9599eb5 100644 (file)
@@ -202,6 +202,12 @@ SMFSource::open_for_write ()
        return 0;
 }
 
+void
+SMFSource::close ()
+{
+       /* nothing to do: file descriptor is never kept open */
+}
+
 /** All stamps in audio frames */
 framecnt_t
 SMFSource::read_unlocked (const Lock&                    lock,
index cc6cfdb4befc865ad775723f26ed583f0c15d07d..5acfe7b119246983cce6e02fe7856333853a29a4 100644 (file)
@@ -180,7 +180,7 @@ SndFileSource::SndFileSource (Session& s, const string& path, const string& orig
                        throw failed_constructor();
                }
        } else {
-               /* normal mode: do not open the file here - do that in write_unlocked() as needed
+               /* normal mode: do not open the file here - do that in {read,write}_unlocked() as needed
                 */
        }
 }
@@ -230,6 +230,15 @@ SndFileSource::init_sndfile ()
        AudioFileSource::HeaderPositionOffsetChanged.connect_same_thread (header_position_connection, boost::bind (&SndFileSource::handle_header_position_change, this));
 }
 
+void
+SndFileSource::close ()
+{
+       if (_sndfile) {
+               sf_close (_sndfile);
+               _sndfile = 0;
+       }
+}
+
 int
 SndFileSource::open ()
 {
@@ -334,10 +343,7 @@ SndFileSource::open ()
 
 SndFileSource::~SndFileSource ()
 {
-       if (_sndfile) {
-               sf_close (_sndfile);
-               _sndfile = 0;
-       }
+       close ();
        delete _broadcast_info;
        delete [] xfade_buf;
 }
@@ -364,10 +370,10 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
                 return cnt;
         }
 
-       if (_sndfile == 0) {
-               error << string_compose (_("could not allocate file %1 for reading."), _path) << endmsg;
+        if (const_cast<SndFileSource*>(this)->open()) {
+               error << string_compose (_("could not open file %1 for reading."), _path) << endmsg;
                return 0;
-       }
+        }
 
        if (start > _length) {
 
index e54afbfaba738e64c50381109d7a9998bf639a67..276a31e46b5343746844f7fa8cf60f0a8d55bbbb 100644 (file)
@@ -84,6 +84,15 @@ SrcFileSource::~SrcFileSource ()
        delete [] _src_buffer;
 }
 
+void
+SrcFileSource::close ()
+{
+       boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (_source);
+       if (fs) {
+               fs->close ();
+       }
+}
+
 framecnt_t
 SrcFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const
 {