summaryrefslogtreecommitdiff
path: root/libs/ardour/import.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-06-02 11:20:37 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2014-06-02 11:20:37 -0400
commit74bc0c84686c4a85941b98d17179d3209bf9a2a8 (patch)
tree8b14bd2694fd2c807f455d6ee3330eeb6a3d4033 /libs/ardour/import.cc
parent08a1409b1f5b5558d2eccc28a3ae4cbd44391812 (diff)
substantive changes to the logic and safety for naming of (audio/MIDI) sources, especially when created via import
Diffstat (limited to 'libs/ardour/import.cc')
-rw-r--r--libs/ardour/import.cc96
1 files changed, 23 insertions, 73 deletions
diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc
index e63143e695..6f7b3d0616 100644
--- a/libs/ardour/import.cc
+++ b/libs/ardour/import.cc
@@ -116,78 +116,31 @@ open_importable_source (const string& path, framecnt_t samplerate, ARDOUR::SrcQu
}
}
-static std::string
-get_non_existent_filename (HeaderFormat hf, DataType type, const bool allow_replacing, const std::string& destdir, const std::string& basename, uint channel, uint channels)
-{
- char buf[PATH_MAX+1];
- bool goodfile = false;
- 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) {
- 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 {
- 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) {
- 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 {
- 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)) {
-
- cnt++;
-
- } else {
-
- goodfile = true;
- }
-
- } while (!goodfile);
-
- return buf;
-}
-
-static vector<string>
-get_paths_for_new_sources (HeaderFormat hf, const bool allow_replacing, const string& import_file_path, const string& session_dir, uint channels)
+vector<string>
+Session::get_paths_for_new_sources (bool /*allow_replacing*/, const string& import_file_path, uint32_t channels)
{
vector<string> new_paths;
const string basename = basename_nosuffix (import_file_path);
- SessionDirectory sdir(session_dir);
-
for (uint n = 0; n < channels; ++n) {
const DataType type = SMFSource::safe_midi_file_extension (import_file_path) ? DataType::MIDI : DataType::AUDIO;
+ string filepath;
+
+ switch (type) {
+ case DataType::MIDI:
+ filepath = new_midi_source_path (basename);
+ break;
+ case DataType::AUDIO:
+ filepath = new_audio_source_path (basename, channels, n, false, false);
+ break;
+ }
- std::string filepath = (type == DataType::MIDI)
- ? sdir.midi_path() : sdir.sound_path();
+ if (filepath.empty()) {
+ error << string_compose (_("Cannot find new filename for imported file %1"), import_file_path) << endmsg;
+ return vector<string>();
+ }
- filepath = Glib::build_filename (filepath,
- get_non_existent_filename (hf, type, allow_replacing, filepath, basename, n, channels));
new_paths.push_back (filepath);
}
@@ -274,12 +227,12 @@ write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status,
{
const framecnt_t nframes = ResampledImportableSource::blocksize;
boost::shared_ptr<AudioFileSource> afs;
- uint channels = source->channels();
+ uint32_t channels = source->channels();
boost::scoped_array<float> data(new float[nframes * channels]);
vector<boost::shared_array<Sample> > channel_data;
- for (uint n = 0; n < channels; ++n) {
+ for (uint32_t n = 0; n < channels; ++n) {
channel_data.push_back(boost::shared_array<Sample>(new Sample[nframes]));
}
@@ -323,14 +276,14 @@ write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status,
progress_multiplier = 0.5;
progress_base = 0.5;
}
-
- uint read_count = 0;
+
+ framecnt_t read_count = 0;
while (!status.cancel) {
framecnt_t nread, nfread;
- uint x;
- uint chn;
+ uint32_t x;
+ uint32_t chn;
if ((nread = source->read (data.get(), nframes)) == 0) {
break;
@@ -513,10 +466,7 @@ Session::import_files (ImportStatus& status)
}
}
- vector<string> new_paths = get_paths_for_new_sources (config.get_native_file_header_format(),
- status.replace_existing_source, *p,
- get_best_session_directory_for_new_source (),
- channels);
+ vector<string> new_paths = get_paths_for_new_sources (status.replace_existing_source, *p, channels);
Sources newfiles;
framepos_t natural_position = source ? source->natural_position() : 0;