From 6654c5376078c3ab5acfbf4e573fb11ffc9f44be Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 7 Sep 2017 06:05:26 +0200 Subject: Fix bumping .mid file name (snapshots & playlist copy) When forking regions, copying playlists or saving snapshots we do not have a reference to the track and cannot use the track's name as basis for the new filename like Editor::fork_region() does. A cloned midi region's name is based on the original region name. This prevents endless addition "name-1-1-1-1-1-1-1-1.mid", adding to the region's basename. --- libs/ardour/session.cc | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'libs/ardour/session.cc') diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 785977dc75..8814d01978 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -5277,15 +5277,10 @@ Session::new_audio_source_path (const string& base, uint32_t nchan, uint32_t cha string Session::new_midi_source_path (const string& base, bool need_lock) { - uint32_t cnt; - char buf[PATH_MAX+1]; - const uint32_t limit = 10000; - string legalized; string possible_path; string possible_name; - buf[0] = '\0'; - legalized = legalize_for_path (base); + possible_name = legalize_for_path (base); // Find a "version" of the file name that doesn't exist in any of the possible directories. std::vector sdirs = source_search_path(DataType::MIDI); @@ -5300,17 +5295,15 @@ Session::new_midi_source_path (const string& base, bool need_lock) */ std::reverse(sdirs.begin(), sdirs.end()); - for (cnt = 1; cnt <= limit; ++cnt) { + while (true) { + possible_name = bump_name_once (possible_name, '-'); vector::iterator i; uint32_t existing = 0; for (vector::const_iterator i = sdirs.begin(); i != sdirs.end(); ++i) { - snprintf (buf, sizeof(buf), "%s-%u.mid", legalized.c_str(), cnt); - possible_name = buf; - - possible_path = Glib::build_filename (*i, possible_name); + possible_path = Glib::build_filename (*i, possible_name + ".mid"); if (Glib::file_test (possible_path, Glib::FILE_TEST_EXISTS)) { existing++; @@ -5321,17 +5314,17 @@ Session::new_midi_source_path (const string& base, bool need_lock) } } - if (existing == 0) { - break; - } - - if (cnt > limit) { + if (possible_path.size () >= PATH_MAX) { error << string_compose( - _("There are already %1 recordings for %2, which I consider too many."), - limit, base) << endmsg; + _("There are already many recordings for %1, resulting in a too long file-path %2."), + base, possible_path) << endmsg; destroy (); return 0; } + + if (existing == 0) { + break; + } } /* No need to "find best location" for software/app-based RAID, because -- cgit v1.2.3