diff data/fileio/MP3FileReader.cpp @ 383:94fc0591ea43 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents f39d33b0b265
children
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp	Fri Nov 30 17:36:14 2007 +0000
+++ b/data/fileio/MP3FileReader.cpp	Wed Feb 27 10:32:45 2008 +0000
@@ -17,6 +17,8 @@
 #ifdef HAVE_MAD
 
 #include "MP3FileReader.h"
+#include "ProgressPrinter.h"
+
 #include "system/System.h"
 
 #include <sys/types.h>
@@ -111,6 +113,9 @@
                 (QObject::tr("Decoding %1...").arg(QFileInfo(m_path).fileName()),
                  QObject::tr("Stop"), 0, 100);
             m_progress->hide();
+        } else {
+            ProgressPrinter *pp = new ProgressPrinter(tr("Decoding..."), this);
+            connect(this, SIGNAL(progress(int)), pp, SLOT(progress(int)));
         }
 
         if (!decode(m_filebuffer, m_fileSize)) {
@@ -130,7 +135,7 @@
         m_decodeThread = new DecodeThread(this);
         m_decodeThread->start();
 
-        while (m_channelCount == 0 && !m_done) {
+        while ((m_channelCount == 0 || m_fileRate == 0) && !m_done) {
             usleep(10);
         }
     }
@@ -343,7 +348,7 @@
         initialiseDecodeCache();
 
         if (m_cacheMode == CacheInTemporaryFile) {
-            m_completion = 1;
+//            m_completion = 1;
             std::cerr << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << std::endl;
             startSerialised("MP3FileReader::Decode");
         }
@@ -353,19 +358,23 @@
         double bitrate = m_bitrateNum / m_bitrateDenom;
         double duration = double(m_fileSize * 8) / bitrate;
         double elapsed = double(m_frameCount) / m_sampleRate;
-        double percent = ((elapsed * 100.0) / duration);
-        int progress = int(percent);
-        if (progress < 1) progress = 1;
-        if (progress > 99) progress = 99;
-        m_completion = progress;
-        if (m_progress) {
-            if (progress > m_progress->value()) {
-                m_progress->setValue(progress);
-                m_progress->show();
-                m_progress->raise();
-                qApp->processEvents();
-                if (m_progress->wasCanceled()) {
-                    m_cancelled = true;
+        double percent = 100;
+        if (duration > 0.0) percent = ((elapsed * 100.0) / duration);
+        int p = int(percent);
+        if (p < 1) p = 1;
+        if (p > 99) p = 99;
+        if (m_completion != p || (m_progress && !m_progress->isVisible())) {
+            m_completion = p;
+            emit progress(m_completion);
+            if (m_progress) {
+                if (m_completion > m_progress->value()) {
+                    m_progress->setValue(m_completion);
+                    m_progress->show();
+                    m_progress->raise();
+                    qApp->processEvents();
+                    if (m_progress->wasCanceled()) {
+                        m_cancelled = true;
+                    }
                 }
             }
         }