try to sensibly handle repeated imports of the same file. the same thing might be required for embeds

git-svn-id: svn://localhost/ardour2/branches/3.0@7975 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-11-05 20:36:44 +00:00
parent e98cf169eb
commit aa78fb928b
4 changed files with 71 additions and 3 deletions

View File

@ -359,6 +359,7 @@ Editor::do_import (vector<string> paths, ImportDisposition chns, ImportMode mode
if (cancel) {
ok = false;
} else {
ipw.show ();
ok = (import_sndfiles (paths, mode, quality, pos, 1, 1, track, false) == 0);
}
@ -392,6 +393,8 @@ Editor::do_import (vector<string> paths, ImportDisposition chns, ImportMode mode
pos = -1;
}
ipw.show ();
switch (chns) {
case Editing::ImportDistinctFiles:
@ -505,6 +508,41 @@ 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;
@ -749,6 +787,12 @@ Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos,
region_name = region_name_from_path (paths.front(), (sources.size() > 1), false);
/* we checked in import_sndfiles() that there were not too many */
while (RegionFactory::region_by_name (region_name)) {
region_name = bump_name_once (region_name, '.');
}
PropertyList plist;
plist.add (ARDOUR::Properties::start, 0);
@ -929,7 +973,7 @@ Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t
existing_track = mt.front();
}
existing_track->set_name (region->name());
}

View File

@ -49,6 +49,7 @@ InterthreadProgressWindow::InterthreadProgressWindow (ARDOUR::InterThreadInfo* i
set_default_size (200, 100);
show_all ();
hide ();
Glib::signal_timeout().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::update), 100);
}

View File

@ -42,7 +42,9 @@ class RegionFactory {
public:
typedef std::map<PBD::ID,boost::shared_ptr<Region> > RegionMap;
static boost::shared_ptr<Region> wholefile_region_by_name (const std::string& name);
static boost::shared_ptr<Region> region_by_id (const PBD::ID&);
static boost::shared_ptr<Region> region_by_name (const std::string& name);
static const RegionMap all_regions() { return region_map; }
static void clear_map ();

View File

@ -327,13 +327,34 @@ RegionFactory::region_by_id (const PBD::ID& id)
RegionMap::iterator i = region_map.find (id);
if (i == region_map.end()) {
cerr << "ID " << id << " not found in region map\n";
return boost::shared_ptr<Region>();
}
return i->second;
}
boost::shared_ptr<Region>
RegionFactory::wholefile_region_by_name (const std::string& name)
{
for (RegionMap::iterator i = region_map.begin(); i != region_map.end(); ++i) {
if (i->second->whole_file() && i->second->name() == name) {
return i->second;
}
}
return boost::shared_ptr<Region>();
}
boost::shared_ptr<Region>
RegionFactory::region_by_name (const std::string& name)
{
for (RegionMap::iterator i = region_map.begin(); i != region_map.end(); ++i) {
if (i->second->name() == name) {
return i->second;
}
}
return boost::shared_ptr<Region>();
}
void
RegionFactory::clear_map ()
{