fixes for various bugs including dangling ref to route in session, opening sessions...
[ardour.git] / libs / ardour / audiofilesource.cc
index 66bf3ed561e4cc5fb410db94964bb55de991302a..9564fff53b79b6bf7183caf7907ec9f423b320a3 100644 (file)
@@ -63,8 +63,8 @@ char   AudioFileSource::bwf_country_code[3] = "US";
 char   AudioFileSource::bwf_organization_code[4] = "LAS";
 char   AudioFileSource::bwf_serial_number[13] = "000000000000";
 
-AudioFileSource::AudioFileSource (string idstr, Flag flags)
-       : AudioSource (idstr), _flags (flags)
+AudioFileSource::AudioFileSource (Session& s, string idstr, Flag flags)
+       : AudioSource (s, idstr), _flags (flags)
 {
        /* constructor used for existing external to session files. file must exist already */
 
@@ -74,8 +74,8 @@ AudioFileSource::AudioFileSource (string idstr, Flag flags)
 
 }
 
-AudioFileSource::AudioFileSource (std::string path, Flag flags, SampleFormat samp_format, HeaderFormat hdr_format)
-       : AudioSource (path), _flags (flags)
+AudioFileSource::AudioFileSource (Session& s, std::string path, Flag flags, SampleFormat samp_format, HeaderFormat hdr_format)
+       : AudioSource (s, path), _flags (flags)
 {
        /* constructor used for new internal-to-session files. file cannot exist */
 
@@ -84,8 +84,8 @@ AudioFileSource::AudioFileSource (std::string path, Flag flags, SampleFormat sam
        }
 }
 
-AudioFileSource::AudioFileSource (const XMLNode& node)
-       : AudioSource (node), _flags (Flag (Writable|CanRename))
+AudioFileSource::AudioFileSource (Session& s, const XMLNode& node)
+       : AudioSource (s, node), _flags (Flag (Writable|CanRename))
 {
        /* constructor used for existing internal-to-session files. file must exist */
 
@@ -109,7 +109,7 @@ AudioFileSource::~AudioFileSource ()
 bool
 AudioFileSource::removable () const
 {
-       return (_flags & Removable) && ((_flags & RemoveAtDestroy) || ((_flags & RemovableIfEmpty) && is_empty (_path)));
+       return (_flags & Removable) && ((_flags & RemoveAtDestroy) || ((_flags & RemovableIfEmpty) && length() == 0));
 }
 
 int
@@ -118,6 +118,7 @@ AudioFileSource::init (string pathstr, bool must_exist)
        bool is_new = false;
 
        _length = 0;
+       timeline_position = 0;
        next_peak_clear_should_notify = false;
        
        if (!find (pathstr, must_exist, is_new)) {
@@ -135,7 +136,7 @@ AudioFileSource::init (string pathstr, bool must_exist)
 string
 AudioFileSource::peak_path (string audio_path)
 {
-       return Session::peak_path_from_audio_path (audio_path);
+       return _session.peak_path_from_audio_path (audio_path);
 }
 
 string
@@ -502,14 +503,14 @@ AudioFileSource::set_search_path (string p)
 }
 
 void
-AudioFileSource::set_header_position_offset (jack_nframes_t offset)
+AudioFileSource::set_header_position_offset (nframes_t offset)
 {
        header_position_offset = offset;
        HeaderPositionOffsetChanged ();
 }
 
 void
-AudioFileSource::set_timeline_position (jack_nframes_t pos)
+AudioFileSource::set_timeline_position (nframes_t pos)
 {
        timeline_position = pos;
 }
@@ -518,7 +519,7 @@ void
 AudioFileSource::set_allow_remove_if_empty (bool yn)
 {
        if (writable()) {
-               allow_remove_if_empty = yn;
+               _flags = Flag (_flags | RemovableIfEmpty);
        }
 }
 
@@ -552,10 +553,10 @@ AudioFileSource::set_name (string newname, bool destructive)
 }
 
 bool
-AudioFileSource::is_empty (string path)
+AudioFileSource::is_empty (Session& s, string path)
 {
        bool ret = false;
-       boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createReadable (path, NoPeakFile, false));
+       boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createReadable (s, path, NoPeakFile, false));
 
        if (afs) {
                ret = (afs->length() == 0);