summaryrefslogtreecommitdiff
path: root/libs/ardour/session_state.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-09-23 20:34:28 +0200
committerRobin Gareus <robin@gareus.org>2016-09-23 20:34:28 +0200
commit8018bed0ded65003279dfbdf446bae2697378488 (patch)
tree00f5148ce33e6af3737596b64b8e89269926d794 /libs/ardour/session_state.cc
parentf7cb5b1a6b26cd13868c6b379760d545097118d9 (diff)
add an option to exclude unused Audio Sources when archiving the session
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r--libs/ardour/session_state.cc92
1 files changed, 54 insertions, 38 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index d1e20030d6..14de04163c 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -4924,7 +4924,11 @@ static void set_progress (Progress* p, size_t n, size_t t)
}
int
-Session::archive_session (const std::string& dest, const std::string& name, ArchiveEncode compress_audio, Progress* progress)
+Session::archive_session (const std::string& dest,
+ const std::string& name,
+ ArchiveEncode compress_audio,
+ bool only_used_sources,
+ Progress* progress)
{
if (dest.empty () || name.empty ()) {
return -1;
@@ -5014,34 +5018,68 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch
std::map<boost::shared_ptr<AudioFileSource>, std::string> orig_sources;
- // TODO: build Source list once
- // add option to only include *used* sources (see Session::cleanup_sources)
+ set<boost::shared_ptr<Source> > sources_used_by_this_snapshot;
+ if (only_used_sources) {
+ playlists->sync_all_regions_with_regions ();
+ playlists->foreach (boost::bind (merge_all_sources, _1, &sources_used_by_this_snapshot), false);
+ }
- if (compress_audio != NO_ENCODE) {
+ // collect audio sources for this session, calc total size for encoding
+ // add option to only include *used* sources (see Session::cleanup_sources)
+ size_t total_size = 0;
+ {
Glib::Threads::Mutex::Lock lm (source_lock);
- size_t total_size = 0;
- if (progress) {
- for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
- boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (i->second);
- if (!afs) {
+ for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
+ boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (i->second);
+ if (!afs || afs->readable_length () == 0) {
+ continue;
+ }
+
+ if (only_used_sources) {
+ if (!afs->used()) {
continue;
}
- if (afs->readable_length () == 0) {
+ if (sources_used_by_this_snapshot.find (afs) == sources_used_by_this_snapshot.end ()) {
continue;
}
+ }
+
+ std::string from = afs->path();
+
+ if (compress_audio != NO_ENCODE) {
total_size += afs->readable_length ();
+ } else {
+ if (afs->within_session()) {
+ filemap[from] = make_new_media_path (from, name, name);
+ } else {
+ filemap[from] = make_new_media_path (from, name, name);
+ remove_dir_from_search_path (Glib::path_get_dirname (from), DataType::AUDIO);
+ }
}
+ }
+ }
+
+ /* encode audio */
+ if (compress_audio != NO_ENCODE) {
+ if (progress) {
progress->set_progress (2); // set to "encoding"
progress->set_progress (0);
}
+ Glib::Threads::Mutex::Lock lm (source_lock);
for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (i->second);
- if (!afs) {
+ if (!afs || afs->readable_length () == 0) {
continue;
}
- if (afs->readable_length () == 0) {
- continue;
+
+ if (only_used_sources) {
+ if (!afs->used()) {
+ continue;
+ }
+ if (sources_used_by_this_snapshot.find (afs) == sources_used_by_this_snapshot.end ()) {
+ continue;
+ }
}
orig_sources[afs] = afs->path();
@@ -5053,6 +5091,7 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch
if (progress) {
progress->descend ((float)afs->readable_length () / total_size);
}
+
try {
SndFileSource* ns = new SndFileSource (*this, *(afs.get()), new_path, compress_audio == FLAC_16BIT, progress);
afs->replace_file (new_path);
@@ -5060,6 +5099,7 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch
} catch (...) {
cerr << "failed to encode " << afs->path() << " to " << new_path << "\n";
}
+
if (progress) {
progress->ascend ();
}
@@ -5098,9 +5138,7 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch
#endif
if (from.find (audiofile_dir_string) != string::npos) {
- if (!compress_audio != NO_ENCODE) {
- filemap[from] = make_new_media_path (from, name, name);
- }
+ ; // handled above
} else if (from.find (midifile_dir_string) != string::npos) {
filemap[from] = make_new_media_path (from, name, name);
} else if (from.find (videofile_dir_string) != string::npos) {
@@ -5127,28 +5165,6 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch
}
}
- /* include external media */
- {
- Glib::Threads::Mutex::Lock lm (source_lock);
- for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
- boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (i->second);
- if (!fs) {
- continue;
- }
- if (fs->within_session()) {
- continue;
- }
-
- if (fs->type () != DataType::AUDIO) {
- continue;
- }
-
- std::string from = fs->path();
- filemap[from] = make_new_media_path (from, name, name);
- remove_dir_from_search_path (Glib::path_get_dirname (from), DataType::AUDIO);
- }
- }
-
/* write session file */
_path = to_dir;
g_mkdir_with_parents (externals_dir ().c_str (), 0755);