diff layer/SpectrogramLayer.cpp @ 48:97b0643bd799

* A bit more work on main window / document / commands stuff. This is still pretty unstable. * Enable CSV file reader also to read files with other separators (e.g. .lab files with space separators) * Show "(R)" on waveform display when resampling during playback * Add ability to import additional audio files (can't process them yet) * Fixes to spectrogram cache for multiple views * Fix to avoid floating-point exception in sparse model when resolution not set yet
author Chris Cannam
date Mon, 06 Mar 2006 17:20:25 +0000
parents 2e2ad8510e52
children 128ebfeeebee
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Fri Mar 03 17:52:21 2006 +0000
+++ b/layer/SpectrogramLayer.cpp	Mon Mar 06 17:20:25 2006 +0000
@@ -1270,14 +1270,24 @@
 
 //	std::cerr << "SpectrogramLayer::CacheFillThread::run in loop" << std::endl;
 
-/*!!! Need a way of finding out whether this layer is dormant in 
-      all the views that are currently visible... or not
-
-	if (m_layer.m_dormancy[) {
-*/
-	if (0) { //!!!
+	bool haveUndormantViews = false;
+
+	for (std::map<const void *, bool>::iterator i =
+		 m_layer.m_dormancy.begin();
+	     i != m_layer.m_dormancy.end(); ++i) {
+
+	    if (!i->second) {
+		haveUndormantViews = true;
+		break;
+	    }
+	}
+
+	if (!haveUndormantViews) {
+
+	    if (m_layer.m_cacheInvalid && m_layer.m_cache) {
+		std::cerr << "All views dormant, freeing spectrogram cache"
+			  << std::endl;
 	
-	    if (m_layer.m_cacheInvalid) {
 		delete m_layer.m_cache;
 		m_layer.m_cache = 0;
 	    }
@@ -1288,8 +1298,11 @@
 
 	    while (!m_layer.m_model->isReady()) {
 		m_layer.m_condition.wait(&m_layer.m_mutex, 100);
+		if (m_layer.m_exiting) break;
 	    }
 
+	    if (m_layer.m_exiting) break;
+
 	    m_layer.m_cacheInvalid = false;
 	    m_fillExtent = 0;
 	    m_fillCompletion = 0;
@@ -1699,10 +1712,15 @@
     }
 
     if (isLayerDormant(v)) {
-	std::cerr << "SpectrogramLayer::paint(): Layer is dormant" << std::endl;
-	return;
+	std::cerr << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << std::endl;
     }
 
+    // Need to do this even if !isLayerDormant, as that could mean v
+    // is not in the dormancy map at all -- we need it to be present
+    // and accountable for when determining whether we need the cache
+    // in the cache-fill thread above.
+    m_dormancy[v] = false;
+
 #ifdef DEBUG_SPECTROGRAM_REPAINT
     std::cerr << "SpectrogramLayer::paint(): About to lock" << std::endl;
 #endif