changeset 411:52303ec15cd2

* Permit holding Shift while dragging an instant or other edited thing, to override the initial drag resistance (for #1928943 sticky time instants) * better handling of updates during progressive decode load * ready() signal from model (used by vect)
author Chris Cannam
date Mon, 19 May 2008 17:23:11 +0000 (2008-05-19)
parents 9c7ebf2cd956
children 5e4238d08caa
files base/StorageAdviser.cpp base/StorageAdviser.h data/fft/FFTDataServer.cpp data/fileio/MatrixFile.cpp data/model/AlignmentModel.cpp data/model/Model.h data/model/WaveFileModel.cpp
diffstat 7 files changed, 70 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/base/StorageAdviser.cpp	Fri May 16 13:27:07 2008 +0000
+++ b/base/StorageAdviser.cpp	Mon May 19 17:23:11 2008 +0000
@@ -28,6 +28,9 @@
 long StorageAdviser::m_memoryPlanned = 0;
 
 StorageAdviser::Recommendation
+StorageAdviser::m_baseRecommendation = StorageAdviser::NoRecommendation;
+
+StorageAdviser::Recommendation
 StorageAdviser::recommend(Criteria criteria,
 			  int minimumSize,
 			  int maximumSize)
@@ -38,6 +41,10 @@
               << ", maximumSize " << maximumSize << std::endl;
 #endif
 
+    if (m_baseRecommendation != NoRecommendation) {
+        return m_baseRecommendation; // for now
+    }
+
     QString path = TempDirectory::getInstance()->getPath();
     int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit());
     int memoryFree, memoryTotal;
@@ -194,3 +201,9 @@
 //              << m_discPlanned << std::endl;
 }
 
+void
+StorageAdviser::setFixedRecommendation(Recommendation recommendation)
+{
+    m_baseRecommendation = recommendation;
+}
+
--- a/base/StorageAdviser.h	Fri May 16 13:27:07 2008 +0000
+++ b/base/StorageAdviser.h	Mon May 19 17:23:11 2008 +0000
@@ -78,9 +78,17 @@
      */
     static void notifyDoneAllocation(AllocationArea area, int size);
 
+    /**
+     * Force all subsequent recommendations to use the (perhaps
+     * partial) specification given here.  If NoRecommendation given
+     * here, this will reset to the default free behaviour.
+     */
+    static void setFixedRecommendation(Recommendation recommendation);
+
 private:
     static long m_discPlanned;
     static long m_memoryPlanned;
+    static Recommendation m_baseRecommendation;
 };
 
 #endif
--- a/data/fft/FFTDataServer.cpp	Fri May 16 13:27:07 2008 +0000
+++ b/data/fft/FFTDataServer.cpp	Mon May 19 17:23:11 2008 +0000
@@ -666,6 +666,8 @@
             delete m_fillThread;
             m_fillThread = 0;
             deleteProcessingData();
+        } else if (!m_fillThread->isRunning()) {
+            m_fillThread->start();
         } else {
             m_condition.wakeAll();
         }
@@ -1130,6 +1132,7 @@
         std::cerr << "WARNING: FFTDataServer::fillColumn(" << x << "): "
                   << "x > width (" << x << " > " << m_width << ")"
                   << std::endl;
+//        abort(); //!!!
         return;
     }
 
@@ -1315,10 +1318,17 @@
 void
 FFTDataServer::FillThread::run()
 {
+#ifdef DEBUG_FFT_SERVER_FILL
+    std::cerr << "FFTDataServer::FillThread::run()" << std::endl;
+#endif
+    
     m_extent = 0;
     m_completion = 0;
     
     while (!m_server.m_model->isReady() && !m_server.m_exiting) {
+#ifdef DEBUG_FFT_SERVER_FILL
+        std::cerr << "FFTDataServer::FillThread::run(): waiting for model " << m_server.m_model << " to be ready" << std::endl;
+#endif
         sleep(1);
     }
     if (m_server.m_exiting) return;
--- a/data/fileio/MatrixFile.cpp	Fri May 16 13:27:07 2008 +0000
+++ b/data/fileio/MatrixFile.cpp	Mon May 19 17:23:11 2008 +0000
@@ -272,7 +272,8 @@
         m_defaultCacheWidth = w;
     }
 
-    static size_t maxCacheMB = 16;
+//!!!    static size_t maxCacheMB = 16;
+    static size_t maxCacheMB = 4;
     if (2 * m_defaultCacheWidth * h * m_cellSize > maxCacheMB * 1024 * 1024) { //!!!
         m_defaultCacheWidth = (maxCacheMB * 1024 * 1024) / (2 * h * m_cellSize);
         if (m_defaultCacheWidth < 16) m_defaultCacheWidth = 16;
@@ -425,7 +426,8 @@
     assert(m_mode == ReadWrite);
 
 #ifdef DEBUG_MATRIX_FILE_READ_SET
-    std::cerr << "MatrixFile::setColumnAt(" << x << ")" << std::endl;
+//    std::cerr << "MatrixFile::setColumnAt(" << x << ")" << std::endl;
+    std::cerr << ".";
 #endif
 
     ssize_t w = 0;
@@ -517,6 +519,8 @@
     std::cerr << "MatrixFile(" << this << ":" << m_fileName.toStdString() << ")::resume(): fd is " << m_fd << std::endl;
 }
 
+static int alloc = 0;
+
 void
 MatrixFile::primeCache(size_t x, bool goingLeft)
 {
@@ -586,9 +590,14 @@
 #endif
 
                 if (m_cache.data) {
-                    if (m_spareData) free(m_spareData);
+                    if (m_spareData) {
+                        std::cerr << this << ": Freeing spare data" << std::endl;
+                        free(m_spareData);
+                    }
+                    std::cerr << this << ": Moving old cache data to spare" << std::endl;
                     m_spareData = m_cache.data;
                 }
+                std::cerr << this << ": Moving request data to cache" << std::endl;
                 m_cache.data = request.data;
 
                 m_readThread->done(m_requestToken);
@@ -611,7 +620,11 @@
         std::cerr << "cancelled " << m_requestToken << std::endl;
 #endif
 
-        if (m_spareData) free(m_spareData);
+        if (m_spareData) {
+            std::cerr << this << ": Freeing spare data" << std::endl;
+            free(m_spareData);
+        }
+        std::cerr << this << ": Moving request data to spare" << std::endl;
         m_spareData = request.data;
         m_readThread->done(m_requestToken);
 
@@ -627,6 +640,9 @@
     request.mutex = &m_fdMutex;
     request.start = m_headerSize + rx * m_height * m_cellSize;
     request.size = rw * m_height * m_cellSize;
+
+    std::cerr << this << ": Moving spare data to request, and resizing to " << rw * m_height * m_cellSize << std::endl;
+
     request.data = (char *)realloc(m_spareData, rw * m_height * m_cellSize);
     MUNLOCK(request.data, rw * m_height * m_cellSize);
     m_spareData = 0;
--- a/data/model/AlignmentModel.cpp	Fri May 16 13:27:07 2008 +0000
+++ b/data/model/AlignmentModel.cpp	Mon May 19 17:23:11 2008 +0000
@@ -108,7 +108,7 @@
 bool
 AlignmentModel::isReady(int *completion) const
 {
-    if (!m_pathBegun) {
+    if (!m_pathBegun && m_rawPath) {
         if (completion) *completion = 0;
         return false;
     }
--- a/data/model/Model.h	Fri May 16 13:27:07 2008 +0000
+++ b/data/model/Model.h	Mon May 19 17:23:11 2008 +0000
@@ -227,6 +227,12 @@
     void completionChanged();
 
     /**
+     * Emitted when internal processing is complete (i.e. when
+     * isReady() would return true, with completion at 100).
+     */
+    void ready();
+
+    /**
      * Emitted when the completion percentage changes for the
      * calculation of this model's alignment model.
      */
--- a/data/model/WaveFileModel.cpp	Fri May 16 13:27:07 2008 +0000
+++ b/data/model/WaveFileModel.cpp	Mon May 19 17:23:11 2008 +0000
@@ -632,6 +632,7 @@
         emit modelChanged(m_lastFillExtent, getEndFrame());
     }
     emit modelChanged();
+    emit ready();
 #ifdef DEBUG_WAVE_FILE_MODEL
     cerr << "WaveFileModel::cacheFilled" << endl;
 #endif
@@ -646,7 +647,7 @@
                                         sqrt(2) + 0.01));
     
     size_t frame = 0;
-    size_t readBlockSize = 16384;
+    int readBlockSize = 16384;
     SampleBlock block;
 
     if (!m_model.isOK()) return;
@@ -666,6 +667,9 @@
     float *means = new float[2 * channels];
     size_t count[2];
     count[0] = count[1] = 0;
+    for (int i = 0; i < 2 * channels; ++i) {
+        means[i] = 0.f;
+    }
 
     bool first = true;
 
@@ -686,18 +690,18 @@
 
 //            std::cerr << "block is " << block.size() << std::endl;
 
-            for (size_t i = 0; i < readBlockSize; ++i) {
+            for (int i = 0; i < readBlockSize; ++i) {
 		
                 if (channels * i + channels > block.size()) break;
 
-                for (size_t ch = 0; ch < size_t(channels); ++ch) {
+                for (int ch = 0; ch < channels; ++ch) {
 
-                    size_t index = channels * i + ch;
+                    int index = channels * i + ch;
                     float sample = block[index];
                     
-                    for (size_t ct = 0; ct < 2; ++ct) { // cache type
+                    for (int ct = 0; ct < 2; ++ct) { // cache type
                         
-                        size_t rangeIndex = ch * 2 + ct;
+                        int rangeIndex = ch * 2 + ct;
                         
                         if (sample > range[rangeIndex].max() || count[ct] == 0) {
                             range[rangeIndex].setMax(sample);
@@ -722,6 +726,7 @@
                             range[rangeIndex].setAbsmean(means[rangeIndex]);
                             m_model.m_cache[ct].push_back(range[rangeIndex]);
                             range[rangeIndex] = Range();
+                            means[rangeIndex] = 0.f;
                         }
 
                         count[ct] = 0;
@@ -760,6 +765,7 @@
                     range[rangeIndex].setAbsmean(means[rangeIndex]);
                     m_model.m_cache[ct].push_back(range[rangeIndex]);
                     range[rangeIndex] = Range();
+                    means[rangeIndex] = 0.f;
                 }
 
                 count[ct] = 0;