diff layer/SpectrogramLayer.cpp @ 810:b68af2be4545 tonioni

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:42:25 +0100
parents 4c8ca536b54f
children 856dbe997dcd
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Mon Jun 16 12:50:27 2014 +0100
+++ b/layer/SpectrogramLayer.cpp	Wed Jun 18 13:42:25 2014 +0100
@@ -141,8 +141,8 @@
     connectSignals(m_model);
 
     connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid()));
-    connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
-	    this, SLOT(cacheInvalid(size_t, size_t)));
+    connect(m_model, SIGNAL(modelChangedWithin(int, int)),
+	    this, SLOT(cacheInvalid(int, int)));
 
     emit modelReplaced();
 }
@@ -572,7 +572,7 @@
 }
 
 void
-SpectrogramLayer::invalidateImageCaches(size_t startFrame, size_t endFrame)
+SpectrogramLayer::invalidateImageCaches(int startFrame, int endFrame)
 {
     for (ViewImageCache::iterator i = m_imageCaches.begin();
          i != m_imageCaches.end(); ++i) {
@@ -592,7 +592,7 @@
                   << i->second.validArea.height() << endl;
 #endif
 
-        if (long(startFrame) > v->getStartFrame()) {
+        if (int(startFrame) > v->getStartFrame()) {
             if (startFrame >= v->getEndFrame()) {
 #ifdef DEBUG_SPECTROGRAM_REPAINT
                 cerr << "Modified start frame is off right of view" << endl;
@@ -610,7 +610,7 @@
                 i->second.validArea = QRect();
             }
         } else {
-            if (long(endFrame) < v->getStartFrame()) {
+            if (int(endFrame) < v->getStartFrame()) {
 #ifdef DEBUG_SPECTROGRAM_REPAINT
                 cerr << "Modified end frame is off left of view" << endl;
 #endif
@@ -681,7 +681,7 @@
 }
 
 void
-SpectrogramLayer::setWindowSize(size_t ws)
+SpectrogramLayer::setWindowSize(int ws)
 {
     if (m_windowSize == ws) return;
 
@@ -695,14 +695,14 @@
     emit layerParametersChanged();
 }
 
-size_t
+int
 SpectrogramLayer::getWindowSize() const
 {
     return m_windowSize;
 }
 
 void
-SpectrogramLayer::setWindowHopLevel(size_t v)
+SpectrogramLayer::setWindowHopLevel(int v)
 {
     if (m_windowHopLevel == v) return;
 
@@ -717,14 +717,14 @@
 //    fillCache();
 }
 
-size_t
+int
 SpectrogramLayer::getWindowHopLevel() const
 {
     return m_windowHopLevel;
 }
 
 void
-SpectrogramLayer::setZeroPadLevel(size_t v)
+SpectrogramLayer::setZeroPadLevel(int v)
 {
     if (m_zeroPadLevel == v) return;
 
@@ -738,7 +738,7 @@
     emit layerParametersChanged();
 }
 
-size_t
+int
 SpectrogramLayer::getZeroPadLevel() const
 {
     return m_zeroPadLevel;
@@ -804,7 +804,7 @@
 }
 
 void
-SpectrogramLayer::setMinFrequency(size_t mf)
+SpectrogramLayer::setMinFrequency(int mf)
 {
     if (m_minFrequency == mf) return;
 
@@ -818,14 +818,14 @@
     emit layerParametersChanged();
 }
 
-size_t
+int
 SpectrogramLayer::getMinFrequency() const
 {
     return m_minFrequency;
 }
 
 void
-SpectrogramLayer::setMaxFrequency(size_t mf)
+SpectrogramLayer::setMaxFrequency(int mf)
 {
     if (m_maxFrequency == mf) return;
 
@@ -839,7 +839,7 @@
     emit layerParametersChanged();
 }
 
-size_t
+int
 SpectrogramLayer::getMaxFrequency() const
 {
     return m_maxFrequency;
@@ -1049,7 +1049,7 @@
 }
 
 void
-SpectrogramLayer::cacheInvalid(size_t from, size_t to)
+SpectrogramLayer::cacheInvalid(int from, int to)
 {
 #ifdef DEBUG_SPECTROGRAM_REPAINT
     SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl;
@@ -1074,11 +1074,11 @@
          i != m_fftModels.end(); ++i) {
 
         const FFTModel *model = i->second.first;
-        size_t lastFill = i->second.second;
+        int lastFill = i->second.second;
 
         if (model) {
 
-            size_t fill = model->getFillExtent();
+            int fill = model->getFillExtent();
 
 #ifdef DEBUG_SPECTROGRAM_REPAINT
             SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl;
@@ -1100,7 +1100,7 @@
 #endif
                     invalidateImageCaches(lastFill, fill);
                     i->second.second = fill;
-                    emit modelChanged(lastFill, fill);
+                    emit modelChangedWithin(lastFill, fill);
                 }
             } else {
 #ifdef DEBUG_SPECTROGRAM_REPAINT
@@ -1109,7 +1109,7 @@
 #endif
                 invalidateImageCaches();
                 i->second.second = fill;
-                emit modelChanged(m_model->getStartFrame(), m_model->getEndFrame());
+                emit modelChangedWithin(m_model->getStartFrame(), m_model->getEndFrame());
             }
 
             if (i->second.second >= 0) {
@@ -1270,7 +1270,7 @@
     float minf = float(sr) / m_fftSize;
 
     if (m_minFrequency > 0.0) {
-	size_t minbin = size_t((double(m_minFrequency) * m_fftSize) / sr + 0.01);
+	int minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.01);
 	if (minbin < 1) minbin = 1;
 	minf = minbin * sr / m_fftSize;
     }
@@ -1285,7 +1285,7 @@
     float maxf = float(sr) / 2;
 
     if (m_maxFrequency > 0.0) {
-	size_t maxbin = size_t((double(m_maxFrequency) * m_fftSize) / sr + 0.1);
+	int maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1);
 	if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2;
 	maxf = maxbin * sr / m_fftSize;
     }
@@ -1348,8 +1348,8 @@
 bool
 SpectrogramLayer::getXBinRange(View *v, int x, float &s0, float &s1) const
 {
-    size_t modelStart = m_model->getStartFrame();
-    size_t modelEnd = m_model->getEndFrame();
+    int modelStart = m_model->getStartFrame();
+    int modelEnd = m_model->getEndFrame();
 
     // Each pixel column covers an exact range of sample frames:
     int f0 = v->getFrameForX(x) - modelStart;
@@ -1362,7 +1362,7 @@
     // And that range may be drawn from a possibly non-integral
     // range of spectrogram windows:
 
-    size_t windowIncrement = getWindowIncrement();
+    int windowIncrement = getWindowIncrement();
     s0 = float(f0) / windowIncrement;
     s1 = float(f1) / windowIncrement;
 
@@ -1434,9 +1434,6 @@
 
     int sr = m_model->getSampleRate();
 
-    size_t windowSize = m_windowSize;
-    size_t windowIncrement = getWindowIncrement();
-
     bool haveAdj = false;
 
     bool peaksOnly = (m_binDisplay == PeakBins ||
@@ -1457,7 +1454,6 @@
 	    if (!fft->isOverThreshold(s, q, m_threshold * (m_fftSize/2))) continue;
 
 	    float freq = binfreq;
-	    bool steady = false;
 	    
 	    if (s < int(fft->getWidth()) - 1) {
 
@@ -1501,7 +1497,7 @@
 
     bool rv = false;
 
-    size_t zp = getZeroPadLevel(v);
+    int zp = getZeroPadLevel(v);
     q0i *= zp + 1;
     q1i *= zp + 1;
 
@@ -1547,7 +1543,7 @@
     return rv;
 }
    
-size_t
+int
 SpectrogramLayer::getZeroPadLevel(const View *v) const
 {
     //!!! tidy all this stuff
@@ -1564,13 +1560,13 @@
 
     int sr = m_model->getSampleRate();
     
-    size_t maxbin = m_fftSize / 2;
+    int maxbin = m_fftSize / 2;
     if (m_maxFrequency > 0) {
 	maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1);
 	if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2;
     }
 
-    size_t minbin = 1;
+    int minbin = 1;
     if (m_minFrequency > 0) {
 	minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.1);
 	if (minbin < 1) minbin = 1;
@@ -1590,7 +1586,7 @@
     }
 }
 
-size_t
+int
 SpectrogramLayer::getFFTSize(const View *v) const
 {
     return m_fftSize * (getZeroPadLevel(v) + 1);
@@ -1601,7 +1597,7 @@
 {
     if (!m_model) return 0;
 
-    size_t fftSize = getFFTSize(v);
+    int fftSize = getFFTSize(v);
 
     if (m_fftModels.find(v) != m_fftModels.end()) {
         if (m_fftModels[v].first == 0) {
@@ -1784,7 +1780,7 @@
     cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
 #endif
 
-    long startFrame = v->getStartFrame();
+    int startFrame = v->getStartFrame();
     if (startFrame < 0) m_candidateFillStartFrame = 0;
     else m_candidateFillStartFrame = startFrame;
 
@@ -1800,10 +1796,10 @@
     // 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.
-    //!!! no longer use cache-fill thread
+    //!!! no inter use cache-fill thread
     const_cast<SpectrogramLayer *>(this)->Layer::setLayerDormant(v, false);
 
-    size_t fftSize = getFFTSize(v);
+    int fftSize = getFFTSize(v);
 /*
     FFTModel *fft = getFFTModel(v);
     if (!fft) {
@@ -2123,13 +2119,13 @@
     // Note fftSize is the actual zero-padded fft size, m_fftSize the
     // nominal fft size.
     
-    size_t maxbin = m_fftSize / 2;
+    int maxbin = m_fftSize / 2;
     if (m_maxFrequency > 0) {
 	maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.001);
 	if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2;
     }
 
-    size_t minbin = 1;
+    int minbin = 1;
     if (m_minFrequency > 0) {
 	minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.001);
 //        cerr << "m_minFrequency = " << m_minFrequency << " -> minbin = " << minbin << endl;
@@ -2160,7 +2156,7 @@
 /*
     float yforbin[maxbin - minbin + 1];
 
-    for (size_t q = minbin; q <= maxbin; ++q) {
+    for (int q = minbin; q <= maxbin; ++q) {
         float f0 = (float(q) * sr) / fftSize;
         yforbin[q - minbin] =
             v->getYForFrequency(f0, displayMinFreq, displayMaxFreq,
@@ -2170,20 +2166,16 @@
     MagnitudeRange overallMag = m_viewMags[v];
     bool overallMagChanged = false;
 
-    bool fftSuspended = false;
-
 #ifdef DEBUG_SPECTROGRAM_REPAINT
     cerr << ((float(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << endl;
 #endif
 
-    bool runOutOfData = false;
-
     if (w == 0) {
         SVDEBUG << "*** NOTE: w == 0" << endl;
     }
 
 #ifdef DEBUG_SPECTROGRAM_REPAINT
-    size_t pixels = 0;
+    int pixels = 0;
 #endif
 
     Profiler outerprof("SpectrogramLayer::paint: all cols");
@@ -2204,22 +2196,22 @@
     bool bufferBinResolution = false;
     if (increment > zoomLevel) bufferBinResolution = true;
 
-    long leftBoundaryFrame = -1, leftCropFrame = -1;
-    long rightBoundaryFrame = -1, rightCropFrame = -1;
+    int leftBoundaryFrame = -1, leftCropFrame = -1;
+    int rightBoundaryFrame = -1, rightCropFrame = -1;
 
     int bufwid;
 
     if (bufferBinResolution) {
 
         for (int x = x0; ; --x) {
-            long f = v->getFrameForX(x);
+            int f = v->getFrameForX(x);
             if ((f / increment) * increment == f) {
                 if (leftCropFrame == -1) leftCropFrame = f;
                 else if (x < x0 - 2) { leftBoundaryFrame = f; break; }
             }
         }
         for (int x = x0 + w; ; ++x) {
-            long f = v->getFrameForX(x);
+            int f = v->getFrameForX(x);
             if ((f / increment) * increment == f) {
                 if (rightCropFrame == -1) rightCropFrame = f;
                 else if (x > x0 + w + 2) { rightBoundaryFrame = f; break; }
@@ -2499,8 +2491,6 @@
         
         if (binforx[x] < 0) continue;
 
-        float columnMax = 0.f;
-
         int sx0 = binforx[x];
         int sx1 = sx0;
         if (x+1 < w) sx1 = binforx[x+1];
@@ -2894,7 +2884,7 @@
     if (m_updateTimer == 0) return 100;
     if (m_fftModels.find(v) == m_fftModels.end()) return 100;
 
-    size_t completion = m_fftModels[v].first->getCompletion();
+    int completion = m_fftModels[v].first->getCompletion();
 #ifdef DEBUG_SPECTROGRAM_REPAINT
     SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl;
 #endif
@@ -2943,8 +2933,8 @@
     if (min < 0) min = 0;
     if (max > m_model->getSampleRate()/2) max = m_model->getSampleRate()/2;
     
-    size_t minf = lrintf(min);
-    size_t maxf = lrintf(max);
+    int minf = lrintf(min);
+    int maxf = lrintf(max);
 
     if (m_minFrequency == minf && m_maxFrequency == maxf) return true;
 
@@ -2976,7 +2966,7 @@
 
 bool
 SpectrogramLayer::snapToFeatureFrame(View *, int &frame,
-				     size_t &resolution,
+				     int &resolution,
 				     SnapType snap) const
 {
     resolution = getWindowIncrement();
@@ -3090,7 +3080,7 @@
                            View::OutlinedText);
     }
 
-    long frame = v->getFrameForX(cursorPos.x());
+    int frame = v->getFrameForX(cursorPos.x());
     RealTime rt = RealTime::frame2RealTime(frame, m_model->getSampleRate());
     QString rtLabel = QString("%1 s").arg(rt.toText(true).c_str());
     QString frameLabel = QString("%1").arg(frame);
@@ -3292,7 +3282,7 @@
     int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4);
     int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0);
 
-    size_t bins = m_fftSize / 2;
+    int bins = m_fftSize / 2;
     int sr = m_model->getSampleRate();
 
     if (m_maxFrequency > 0) {
@@ -3508,7 +3498,7 @@
     int maxStep = mapper.getPositionForValue(0);
     int minStep = mapper.getPositionForValue(float(sr) / 2);
 
-    size_t initialMax = m_initialMaxFrequency;
+    int initialMax = m_initialMaxFrequency;
     if (initialMax == 0) initialMax = sr / 2;
 
     defaultStep = mapper.getPositionForValue(initialMax) - minStep;
@@ -3684,13 +3674,13 @@
     int channel = attributes.value("channel").toInt(&ok);
     if (ok) setChannel(channel);
 
-    size_t windowSize = attributes.value("windowSize").toUInt(&ok);
+    int windowSize = attributes.value("windowSize").toUInt(&ok);
     if (ok) setWindowSize(windowSize);
 
-    size_t windowHopLevel = attributes.value("windowHopLevel").toUInt(&ok);
+    int windowHopLevel = attributes.value("windowHopLevel").toUInt(&ok);
     if (ok) setWindowHopLevel(windowHopLevel);
     else {
-        size_t windowOverlap = attributes.value("windowOverlap").toUInt(&ok);
+        int windowOverlap = attributes.value("windowOverlap").toUInt(&ok);
         // a percentage value
         if (ok) {
             if (windowOverlap == 0) setWindowHopLevel(0);
@@ -3707,13 +3697,13 @@
     float threshold = attributes.value("threshold").toFloat(&ok);
     if (ok) setThreshold(threshold);
 
-    size_t minFrequency = attributes.value("minFrequency").toUInt(&ok);
+    int minFrequency = attributes.value("minFrequency").toUInt(&ok);
     if (ok) {
         SVDEBUG << "SpectrogramLayer::setProperties: setting min freq to " << minFrequency << endl;
         setMinFrequency(minFrequency);
     }
 
-    size_t maxFrequency = attributes.value("maxFrequency").toUInt(&ok);
+    int maxFrequency = attributes.value("maxFrequency").toUInt(&ok);
     if (ok) {
         SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl;
         setMaxFrequency(maxFrequency);