move all destructive functionality into SndFileSource as a mode, and drop Destructive...
[ardour.git] / libs / ardour / audiofilesource.cc
index 0eb416e90505efba83b9f69871922bb626636ec9..1fbde870a0a4c65ca50faae76764257f09741961 100644 (file)
@@ -59,10 +59,6 @@ string AudioFileSource::search_path;
 sigc::signal<void> AudioFileSource::HeaderPositionOffsetChanged;
 uint64_t           AudioFileSource::header_position_offset = 0;
 
-/* XXX turn this into a Config option */
-char   AudioFileSource::bwf_country_code[3] = "US";
-/* XXX turn this into a Config option */
-char   AudioFileSource::bwf_organization_code[4] = "LAS";
 /* XXX maybe this too */
 char   AudioFileSource::bwf_serial_number[13] = "000000000000";
 
@@ -70,6 +66,7 @@ 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 */
+       _is_embedded = AudioFileSource::determine_embeddedness (idstr);
 
        if (init (idstr, true)) {
                throw failed_constructor ();
@@ -81,6 +78,7 @@ AudioFileSource::AudioFileSource (Session& s, std::string path, Flag flags, Samp
        : AudioSource (s, path), _flags (flags)
 {
        /* constructor used for new internal-to-session files. file cannot exist */
+       _is_embedded = false;
 
        if (init (path, false)) {
                throw failed_constructor ();
@@ -109,6 +107,12 @@ AudioFileSource::~AudioFileSource ()
        }
 }
 
+bool
+AudioFileSource::determine_embeddedness (std::string path)
+{
+       return (path.find("/") == 0);
+}
+
 bool
 AudioFileSource::removable () const
 {
@@ -281,6 +285,17 @@ AudioFileSource::set_state (const XMLNode& node)
 
        }
 
+       if ((prop = node.property (X_("name"))) != 0) {
+               _is_embedded = AudioFileSource::determine_embeddedness (prop->value());
+       } else {
+               _is_embedded = false;
+       }
+
+       if ((prop = node.property (X_("destructive"))) != 0) {
+               /* old style, from the period when we had DestructiveFileSource */
+               _flags = Flag (_flags | Destructive);
+       }
+
        return 0;
 }
 
@@ -322,6 +337,11 @@ AudioFileSource::mark_take (string id)
 int
 AudioFileSource::move_to_trash (const string trash_dir_name)
 {
+       if (is_embedded()) {
+               cerr << "tried to move an embedded region to trash" << endl;
+               return -1;
+       }
+
        string newpath;
 
        if (!writable()) {
@@ -469,7 +489,11 @@ AudioFileSource::find (string pathstr, bool must_exist, bool& isnew)
                /* external files and/or very very old style sessions include full paths */
                
                _path = pathstr;
-               _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
+               if (is_embedded()) {
+                       _name = pathstr;
+               } else {
+                       _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
+               }
                
                if (access (_path.c_str(), R_OK) != 0) {