From c80e8727dffd2a0958ae377aff5f0e7e2904770f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 21 Sep 2016 13:04:25 +0200 Subject: report archive encoding progress --- libs/ardour/session_state.cc | 45 ++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'libs/ardour/session_state.cc') diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index be8e308283..532dcabbc8 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -5002,10 +5002,6 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch /* prepare archive */ string archive = Glib::build_filename (dest, name + ".tar.xz"); -#ifndef NDEBUG - cout << "ARCHIVE: " << archive << "\n"; -#endif - PBD::ScopedConnectionList progress_connection; PBD::FileArchive ar (archive); if (progress) { @@ -5032,8 +5028,27 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch std::map, std::string> orig_sources; + // TODO: build Source list once + // add option to only include *used* sources (see Session::cleanup_sources) + if (compress_audio != NO_ENCODE) { 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 afs = boost::dynamic_pointer_cast (i->second); + if (!afs) { + continue; + } + if (afs->readable_length () == 0) { + continue; + } + total_size += afs->readable_length (); + } + progress->set_progress (2); // set to "encoding" + progress->set_progress (0); + } + for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) { boost::shared_ptr afs = boost::dynamic_pointer_cast (i->second); if (!afs) { @@ -5049,18 +5064,27 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch new_path = Glib::build_filename (Glib::path_get_dirname (new_path), PBD::basename_nosuffix (new_path) + ".flac"); g_mkdir_with_parents (Glib::path_get_dirname (new_path).c_str (), 0755); - // TODO: set progress to "encoding", use total readable_length () somehow. - // .. or a custom progress report like save-as. + if (progress) { + progress->descend ((float)afs->readable_length () / total_size); + } try { - SndFileSource* ns = new SndFileSource (*this, *(afs.get()), new_path, compress_audio == FLAC_16BIT, NULL /*progress*/); + SndFileSource* ns = new SndFileSource (*this, *(afs.get()), new_path, compress_audio == FLAC_16BIT, progress); afs->replace_file (new_path); delete ns; } catch (...) { cerr << "failed to encode " << afs->path() << " to " << new_path << "\n"; } + if (progress) { + progress->ascend (); + } } } + if (progress) { + progress->set_progress (-1); // set to "archiving" + progress->set_progress (0); + } + /* index files relevant for this session */ for (vector::const_iterator sd = session_dirs.begin(); sd != session_dirs.end(); ++sd) { vector files; @@ -5196,13 +5220,6 @@ Session::archive_session (const std::string& dest, const std::string& name, Arch i->first->replace_file (i->second); } -#ifndef NDEBUG - /* done -- now zip */ - for (std::map::const_iterator i = filemap.begin(); i != filemap.end (); ++i) { - cout << "archive " << (*i).first << " as " << (*i).second << "\n"; - } -#endif - int rv = ar.create (filemap); remove_directory (to_dir); -- cgit v1.2.3