handle multiple imports of the same file better (via better source naming); make...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 9 Nov 2010 22:18:52 +0000 (22:18 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 9 Nov 2010 22:18:52 +0000 (22:18 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7989 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_audio_import.cc
gtk2_ardour/search_path_option.cc
gtk2_ardour/search_path_option.h
gtk2_ardour/session_option_editor.cc
libs/ardour/ardour/session.h
libs/ardour/configuration.cc
libs/ardour/import.cc
libs/ardour/session.cc

index 506248a6c7d95283a9d7ba1f0dc5985c31888564..dadde038a85b6d9f7e7ee731c83134efccf33118 100644 (file)
@@ -218,19 +218,16 @@ Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
        string wave_name (Glib::path_get_basename(path));
 
        SourceMap all_sources = _session->get_sources();
-       bool wave_name_exists = false;
+       bool already_exists = false;
+        uint32_t existing;
 
-       for (SourceMap::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
-               string tmp (Glib::path_get_basename (i->second->path()));
-               if (tmp == wave_name) {
-                       wave_name_exists = true;
-                       break;
-               }
-       }
+        if ((existing = _session->count_sources_by_origin (path)) > 0) {
+                already_exists = true;
+        }
 
        int function = 1;
 
-       if (wave_name_exists) {
+       if (already_exists) {
                string message;
                if (all_or_nothing) {
                        // updating is still disabled
@@ -508,41 +505,6 @@ int
 Editor::import_sndfiles (vector<string> paths, ImportMode mode, SrcQuality quality, framepos_t& pos,
                         int target_regions, int target_tracks, boost::shared_ptr<Track>& track, bool replace)
 {
-        /* check for existing wholefile regions of the same name,
-           which can happen when we import foo.wav but end up with foo-L.wav 
-           and foo-R.wav inside the session. this case doesn't trigger
-           source name collisions, so we have to catch it at the region
-           name level.
-        */
-        
-        string region_name = region_name_from_path (paths.front(), true, false);
-        
-        if (RegionFactory::wholefile_region_by_name (region_name)) {
-                string message = string_compose ( _("You appear to have already imported this file, since a region called %1 already exists.\nDo you really want to import it again?"),
-                                                  region_name);
-                MessageDialog dialog (message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true);
-                int ret;
-                
-                dialog.show ();
-                ret = dialog.run ();
-                dialog.hide ();
-                
-                if (ret != RESPONSE_OK) {
-                        return -1;
-                }
-                
-                int l = 0;
-                
-                while (RegionFactory::region_by_name (region_name) && ++l < 999) {
-                        region_name = bump_name_once (region_name, '.');
-                }
-                
-                if (l == 999) {
-                        error << string_compose (_("Too many regions already named something like \"%1\""), paths.front()) << endmsg;
-                        return -1;
-                }
-        }
-
        import_status.paths = paths;
        import_status.done = false;
        import_status.cancel = false;
index be01b9b1aa6893f7977cfcce967bf6c331dba38d..eff991081b2a021bef7173951856efe68842ae05 100644 (file)
@@ -46,6 +46,8 @@ SearchPathOption::SearchPathOption (const string& pathname, const string& label,
         session_label.set_markup (string_compose ("<i>%1</i>", _("the session folder")));
         session_label.set_alignment (0.0, 0.5);
         session_label.show ();
+
+        path_box.pack_start (session_label);
 }
 
 SearchPathOption::~SearchPathOption()
@@ -59,6 +61,7 @@ SearchPathOption::path_chosen ()
 {
         string path = add_chooser.get_filename ();
         add_path (path);
+        changed ();
 }
 
 void
@@ -109,12 +112,6 @@ SearchPathOption::changed ()
         
         for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
 
-                if (p == paths.begin()) {
-                        /* skip first entry, its always "the session"
-                         */
-                        continue;
-                }
-
                 if (!str.empty()) {
                         str += ':';
                 }
@@ -130,11 +127,16 @@ SearchPathOption::add_path (const string& path, bool removable)
         PathEntry* pe = new PathEntry (path, removable);
         paths.push_back (pe);
         path_box.pack_start (pe->box, false, false);
+        pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
 }
 
 void
-SearchPathOption::remove_path (const string& path)
+SearchPathOption::remove_path (PathEntry* pe)
 {
+        path_box.remove (pe->box);
+        paths.remove (pe);
+        delete pe;
+        changed ();
 }
 
 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
index 7163924b8cc1afe29f2b4ae2b3628b60ed688df8..68fb6494817949ee9ccf00ad7e4b0d5c10b3291b 100644 (file)
@@ -42,7 +42,7 @@ class SearchPathOption : public Option
         Gtk::Label session_label;
 
         void add_path (const std::string& path, bool removable=true);
-        void remove_path (const std::string& path);
+        void remove_path (PathEntry*);
         void changed ();
         void path_chosen ();
 };
index ec7ee86c8dee0e63e652921aa64d9724829e0a50..bef5c70433b26fea3f039a8196fa26cc816e9454 100644 (file)
@@ -209,8 +209,6 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
 
        add_option (_("Media"), hf);
         
-        add_option (_("Media"), new OptionEditorHeading (_("Media Locations")));
-
         SearchPathOption* spo = new SearchPathOption ("audio-search-path", _("Search for audio files in:"),
                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::get_audio_search_path),
                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::set_audio_search_path));
index 03e33a6446e17284ea5ec30ca344fb9bcd81e147..91034cd034587c1acd62403252fe4575ce3a94f9 100644 (file)
@@ -541,6 +541,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        boost::shared_ptr<Source> source_by_id (const PBD::ID&);
        boost::shared_ptr<Source> source_by_path_and_channel (const std::string&, uint16_t);
+       uint32_t count_sources_by_origin (const std::string&);
 
        void add_playlist (boost::shared_ptr<Playlist>, bool unused = false);
 
index d5ca426a74d3c8cf9d3493f0c4e6f3bcdc3481c3..dd863ee398578c5c1ce48497d7db8ea07e3e2d1b 100644 (file)
@@ -69,6 +69,9 @@ ConfigVariableBase::set_from_node (XMLNode const & node)
                                if ((prop = child->property ("name")) != 0) {
                                        if (prop->value() == _name) {
                                                if ((prop = child->property ("value")) != 0) {
+                                                        if (_name == "audio-search-path") {
+                                                                sleep (1);
+                                                        }
                                                        set_from_string (prop->value());
                                                        return true;
                                                }
@@ -94,6 +97,7 @@ ConfigVariableBase::set_from_node (XMLNode const & node)
 
                        if (option->name() == _name) {
                                if ((opt_prop = option->property ("val")) != 0) {
+                                        cerr << "Setting " << _name << " to " << opt_prop->value() << endl;
                                        set_from_string (opt_prop->value());
                                        return true;
                                }
index 4fc546ebd5259e26dd3668db62d286c0681cfa1f..3dd2a99ee109f8497d8ef1589e9eb6c78a4c1dda 100644 (file)
@@ -121,40 +121,52 @@ get_non_existent_filename (HeaderFormat hf, DataType type, const bool allow_repl
 {
        char buf[PATH_MAX+1];
        bool goodfile = false;
-       string base(basename);
+       string base = basename;
        string ext = native_header_format_extension (hf, type);
+        uint32_t cnt = 1;
 
        do {
 
                if (type == DataType::AUDIO && channels == 2) {
                        if (channel == 0) {
-                               snprintf (buf, sizeof(buf), "%s-L%s", base.c_str(), ext.c_str());
+                                if (cnt == 1) {
+                                        snprintf (buf, sizeof(buf), "%s-L%s", base.c_str(), ext.c_str());
+                                } else {
+                                        snprintf (buf, sizeof(buf), "%s-%d-L%s", base.c_str(), cnt, ext.c_str());
+                                }
                        } else {
-                               snprintf (buf, sizeof(buf), "%s-R%s", base.c_str(), ext.c_str());
+                                if (cnt == 1) {
+                                        snprintf (buf, sizeof(buf), "%s-R%s", base.c_str(), ext.c_str());
+                                } else {
+                                        snprintf (buf, sizeof(buf), "%s-%d-R%s", base.c_str(), cnt, ext.c_str());
+                                }
                        }
                } else if (channels > 1) {
-                       snprintf (buf, sizeof(buf), "%s-c%d%s", base.c_str(), channel, ext.c_str());
+                        if (cnt == 1) {
+                                snprintf (buf, sizeof(buf), "%s-c%d%s", base.c_str(), channel, ext.c_str());
+                        } else {
+                                snprintf (buf, sizeof(buf), "%s-%d-c%d%s", base.c_str(), cnt, channel, ext.c_str());
+                        }
                } else {
-                       snprintf (buf, sizeof(buf), "%s%s", base.c_str(), ext.c_str());
+                        if (cnt == 1) {
+                                snprintf (buf, sizeof(buf), "%s%s", base.c_str(), ext.c_str());
+                        } else {
+                                snprintf (buf, sizeof(buf), "%s-%d%s", base.c_str(), cnt, ext.c_str());
+                        }
                }
 
-
                string tempname = destdir + "/" + buf;
+                
                if (!allow_replacing && Glib::file_test (tempname, Glib::FILE_TEST_EXISTS)) {
-
-                       /* if the file already exists, we must come up with
-                        *  a new name for it.  for now we just keep appending
-                        *  _ to basename
-                        */
-
-                       base += "_";
+                        
+                        cnt++;
 
                } else {
 
                        goodfile = true;
                }
 
-       } while ( !goodfile);
+       } while (!goodfile);
 
        return buf;
 }
index c5aef9531c334f16d1ca1bd3203015d9837d8372..7bc9b1ad12ef2927109817f969963e7b92ed66be 100644 (file)
@@ -2741,6 +2741,24 @@ Session::source_by_path_and_channel (const string& path, uint16_t chn)
        return boost::shared_ptr<Source>();
 }
 
+uint32_t
+Session::count_sources_by_origin (const string& path)
+{
+        uint32_t cnt = 0;
+       Glib::Mutex::Lock lm (source_lock);
+
+       for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
+               boost::shared_ptr<FileSource> fs
+                       = boost::dynamic_pointer_cast<FileSource>(i->second);
+
+                if (fs && fs->origin() == path) {
+                        ++cnt;
+                }
+       }
+
+       return cnt;
+}
+
 
 string
 Session::change_source_path_by_name (string path, string oldname, string newname, bool destructive)