summaryrefslogtreecommitdiff
path: root/libs/ardour/session.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-09-07 06:05:26 +0200
committerRobin Gareus <robin@gareus.org>2017-09-07 06:05:26 +0200
commit6654c5376078c3ab5acfbf4e573fb11ffc9f44be (patch)
treebae931db831088f6fa6b3431aab4c9fc89a753c2 /libs/ardour/session.cc
parent40edbb95193576839d6a06dccf9e2faf7e8e3e0a (diff)
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.
Diffstat (limited to 'libs/ardour/session.cc')
-rw-r--r--libs/ardour/session.cc29
1 files changed, 11 insertions, 18 deletions
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<string> 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<space_and_path>::iterator i;
uint32_t existing = 0;
for (vector<string>::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