diff data/model/WaveFileModel.cpp @ 187:89b05b679dc3

* Fixes to update logic in writable wave file model
author Chris Cannam
date Thu, 12 Oct 2006 16:10:49 +0000
parents bd1260261412
children f86b74d1b143
line wrap: on
line diff
--- a/data/model/WaveFileModel.cpp	Thu Oct 12 14:56:28 2006 +0000
+++ b/data/model/WaveFileModel.cpp	Thu Oct 12 16:10:49 2006 +0000
@@ -45,8 +45,6 @@
     m_exiting(false)
 {
     m_reader = AudioFileReaderFactory::createReader(path);
-    connect(m_reader, SIGNAL(frameCountChanged()),
-            this, SLOT(frameCountChanged()));
     setObjectName(QFileInfo(path).fileName());
     if (isOK()) fillCache();
 }
@@ -60,13 +58,8 @@
     m_exiting(false)
 {
     m_reader = reader;
-    connect(m_reader, SIGNAL(frameCountChanged()),
-            this, SLOT(frameCountChanged()));
     setObjectName(QFileInfo(path).fileName());
-    if (isOK()) {
-        std::cerr << "OK; filling cache" << std::endl;
-        fillCache();
-    }
+    fillCache();
 }
 
 WaveFileModel::~WaveFileModel()
@@ -389,23 +382,6 @@
 }   
 
 void
-WaveFileModel::frameCountChanged()
-{
-    m_mutex.lock();
-    if (m_updateTimer) {
-        std::cerr << "WaveFileModel::frameCountChanged: updating existing fill thread" << std::endl;
-        m_fillThread->frameCountChanged();
-        m_mutex.unlock();
-    } else {
-        std::cerr << "WaveFileModel::frameCountChanged: restarting [inefficient]" << std::endl;
-        m_cache[0].clear();
-        m_cache[1].clear();
-        m_mutex.unlock();
-        fillCache();
-    }
-}
-
-void
 WaveFileModel::fillTimerTimedOut()
 {
     if (m_fillThread) {
@@ -435,14 +411,6 @@
 }
 
 void
-WaveFileModel::RangeCacheFillThread::frameCountChanged()
-{
-    m_frameCount = m_model.getFrameCount();
-    std::cerr << "WaveFileModel::RangeCacheFillThread::frameCountChanged: now "
-              << m_frameCount << std::endl;
-}
-
-void
 WaveFileModel::RangeCacheFillThread::run()
 {
     size_t cacheBlockSize[2];
@@ -457,17 +425,26 @@
     if (!m_model.isOK()) return;
     
     size_t channels = m_model.getChannelCount();
+    bool updating = m_model.m_reader->isUpdating();
+
+    if (updating) {
+        while (channels == 0 && !m_model.m_exiting) {
+            std::cerr << "WaveFileModel::fill: Waiting for channels..." << std::endl;
+            sleep(1);
+            channels = m_model.getChannelCount();
+        }
+    }
 
     Range *range = new Range[2 * channels];
     size_t count[2];
     count[0] = count[1] = 0;
 
     bool first = true;
-    bool updating = m_model.m_reader->isUpdating();
 
     while (first || updating) {
 
         updating = m_model.m_reader->isUpdating();
+        m_frameCount = m_model.getFrameCount();
 
         std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl;
 
@@ -522,7 +499,9 @@
 
         first = false;
         if (m_model.m_exiting) break;
-        if (updating) sleep(1);
+        if (updating) {
+            sleep(1);
+        }
     }
 
     if (!m_model.m_exiting) {