when renaming redirects, scan all routes AND sends AND port inserts for the name...
[ardour.git] / libs / ardour / audiofilesource.cc
index ac5a6e7b8ca144375669d4d19656935127ceb4e1..b1ec8a3baa7c543b5a283c5f344b2bf3d982d49d 100644 (file)
@@ -96,6 +96,7 @@ AudioFileSource::AudioFileSource (Session& s, ustring path, Flag flags)
                throw failed_constructor ();
        }
 
+       fix_writable_flags ();
 }
 
 AudioFileSource::AudioFileSource (Session& s, ustring path, Flag flags, SampleFormat samp_format, HeaderFormat hdr_format)
@@ -108,6 +109,8 @@ AudioFileSource::AudioFileSource (Session& s, ustring path, Flag flags, SampleFo
        if (init (path, false)) {
                throw failed_constructor ();
        }
+
+       fix_writable_flags ();
 }
 
 AudioFileSource::AudioFileSource (Session& s, const XMLNode& node, bool must_exist)
@@ -125,6 +128,8 @@ AudioFileSource::AudioFileSource (Session& s, const XMLNode& node, bool must_exi
        if (init (foo, must_exist)) {
                throw failed_constructor ();
        }
+
+       fix_writable_flags ();
 }
 
 AudioFileSource::~AudioFileSource ()
@@ -135,6 +140,14 @@ AudioFileSource::~AudioFileSource ()
        }
 }
 
+void
+AudioFileSource::fix_writable_flags ()
+{
+       if (!_session.writable()) {
+               _flags = Flag (_flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy|CanRename));
+       }
+}
+
 bool
 AudioFileSource::determine_embeddedness (ustring path)
 {
@@ -147,6 +160,12 @@ AudioFileSource::removable () const
        return (_flags & Removable) && ((_flags & RemoveAtDestroy) || ((_flags & RemovableIfEmpty) && length() == 0));
 }
 
+bool
+AudioFileSource::writable() const
+{
+       return (_flags & Writable);
+}
+
 int
 AudioFileSource::init (ustring pathstr, bool must_exist)
 {
@@ -154,7 +173,11 @@ AudioFileSource::init (ustring pathstr, bool must_exist)
        timeline_position = 0;
        _peaks_built = false;
 
-       if (!find (pathstr, must_exist, is_embedded(), file_is_new, _channel, _path, _name)) {
+       /* is_embedded() can't work yet, because our _path is not set */
+
+       bool embedded = determine_embeddedness (pathstr);
+
+       if (!find (pathstr, must_exist, embedded, file_is_new, _channel, _path, _name)) {
                throw non_existent_source ();
        }
 
@@ -294,6 +317,8 @@ AudioFileSource::set_state (const XMLNode& node)
 
        }
 
+       fix_writable_flags ();
+
        if ((prop = node.property (X_("channel"))) != 0) {
                _channel = atoi (prop->value());
        } else {
@@ -320,7 +345,7 @@ AudioFileSource::mark_for_remove ()
        // This operation is not allowed for sources for destructive tracks or embedded files.
        // Fortunately mark_for_remove() is never called for embedded files. This function
        // must be fixed if that ever happens.
-       if (_flags & Destructive) {
+       if (!_session.writable() || (_flags & Destructive)) {
                return;
        }
 
@@ -568,7 +593,7 @@ AudioFileSource::find (ustring pathstr, bool must_exist, bool embedded,
                if (embedded) {
                        name = pathstr;
                } else {
-                       name = pathstr.substr (pathstr.find_last_of ('/') + 1);
+                       name = Glib::path_get_basename (pathstr);
                }
 
                if (!Glib::file_test (pathstr, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
@@ -634,6 +659,8 @@ AudioFileSource::set_allow_remove_if_empty (bool yn)
        } else {
                _flags = Flag (_flags & ~RemovableIfEmpty);
        }
+
+       fix_writable_flags ();
 }
 
 int
@@ -707,9 +734,8 @@ AudioFileSource::safe_file_extension(ustring file)
                ".maud", ".MAUD",
                ".vwe", ".VWE",
                ".paf",
-#ifdef HAVE_FLAC
                ".flac", ".FLAC",
-#endif // HAVE_FLAC
+               ".ogg", ".OGG",
 #ifdef HAVE_COREAUDIO
                ".mp3", ".MP3",
                ".aac", ".AAC",