summaryrefslogtreecommitdiff
path: root/libs/ardour/session_state.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-09-15 14:41:27 +0200
committerRobin Gareus <robin@gareus.org>2015-09-15 14:44:05 +0200
commit04e7cfabbe58605e6770adbd9e27bf871a957bef (patch)
tree422e05f8dc36f1e9c9138eba704668b7f23bba56 /libs/ardour/session_state.cc
parent551e20b926e164b3579d5e6b39f5e2fcb1ced93e (diff)
prepare peak-file cleanup/recreate.
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r--libs/ardour/session_state.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index f893c18a1b..0c66b91578 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -2846,6 +2846,66 @@ Session::cleanup_regions ()
save_state ("");
}
+bool
+Session::can_cleanup_peakfiles () const
+{
+ if (deletion_in_progress()) {
+ return false;
+ }
+ if (!_writable || (_state_of_the_state & CannotSave)) {
+ warning << _("Cannot cleanup peak-files for read-only session.") << endmsg;
+ return false;
+ }
+ if (record_status() == Recording) {
+ error << _("Cannot cleanup peak-files while recording") << endmsg;
+ return false;
+ }
+ return true;
+}
+
+int
+Session::cleanup_peakfiles ()
+{
+ Glib::Threads::Mutex::Lock lm (peak_cleanup_lock, Glib::Threads::TRY_LOCK);
+ if (!lm.locked()) {
+ return -1;
+ }
+
+ assert (can_cleanup_peakfiles ());
+ assert (!peaks_cleanup_in_progres());
+
+ _state_of_the_state = StateOfTheState (_state_of_the_state | PeakCleanup);
+
+ int timeout = 5000; // 5 seconds
+ while (!SourceFactory::files_with_peaks.empty()) {
+ Glib::usleep (1000);
+ if (--timeout < 0) {
+ warning << _("Timeout waiting for peak-file creation to terminate before cleanup, please try again later.") << endmsg;
+ _state_of_the_state = StateOfTheState (_state_of_the_state & (~PeakCleanup));
+ return -1;
+ }
+ }
+
+ for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
+ boost::shared_ptr<AudioSource> as;
+ if ((as = boost::dynamic_pointer_cast<AudioSource> (i->second)) != 0) {
+ as->close_peakfile();
+ }
+ }
+
+ PBD::clear_directory (session_directory().peak_path());
+
+ _state_of_the_state = StateOfTheState (_state_of_the_state & (~PeakCleanup));
+
+ for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
+ boost::shared_ptr<AudioSource> as;
+ if ((as = boost::dynamic_pointer_cast<AudioSource> (i->second)) != 0) {
+ SourceFactory::setup_peakfile(as, true);
+ }
+ }
+ return 0;
+}
+
int
Session::cleanup_sources (CleanupReport& rep)
{