changeset 906:12ab113ca2b1 cxx11

A few more fixes
author Chris Cannam
date Mon, 09 Mar 2015 15:59:04 +0000
parents b66fb15de477
children 28d05ae8741c
files layer/Layer.h layer/SliceLayer.cpp layer/SliceLayer.h layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h
diffstat 5 files changed, 75 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.h	Mon Mar 09 14:35:21 2015 +0000
+++ b/layer/Layer.h	Mon Mar 09 15:59:04 2015 +0000
@@ -525,7 +525,7 @@
     void modelChanged();
     void modelCompletionChanged();
     void modelAlignmentCompletionChanged();
-    void modelChangedWithin(int startFrame, int endFrame);
+    void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
     void modelReplaced();
 
     void layerParametersChanged();
--- a/layer/SliceLayer.cpp	Mon Mar 09 14:35:21 2015 +0000
+++ b/layer/SliceLayer.cpp	Mon Mar 09 15:59:04 2015 +0000
@@ -119,21 +119,21 @@
     if (minbin < 0) minbin = 0;
     if (maxbin < 0) maxbin = 0;
     
-    int sampleRate = m_sliceableModel->getSampleRate();
+    sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate();
 
-    int f0 = m_currentf0;
-    int f1 = m_currentf1;
+    sv_frame_t f0 = m_currentf0;
+    sv_frame_t f1 = m_currentf1;
 
     RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
     RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
     
-    range = f1 - f0 + 1;
+    range = int(f1 - f0 + 1);
 
     QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str());
 
     if (includeBinDescription) {
 
-        float minvalue = 0.f;
+        float minvalue = 0.0;
         if (minbin < int(m_values.size())) minvalue = m_values[minbin];
 
         float maxvalue = minvalue;
@@ -179,23 +179,23 @@
     }
 }
 
-float
-SliceLayer::getXForBin(int bin, int count, float w) const
+double
+SliceLayer::getXForBin(int bin, int count, double w) const
 {
-    float x = 0;
+    double x = 0;
 
     switch (m_binScale) {
 
     case LinearBins:
-        x = (float(w) * bin) / count;
+        x = (w * bin) / count;
         break;
         
     case LogBins:
-        x = (float(w) * log10f(bin + 1)) / log10f(count + 1);
+        x = (w * log10(bin + 1)) / log10(count + 1);
         break;
         
     case InvertedLogBins:
-        x = w - (float(w) * log10f(count - bin - 1)) / log10f(count);
+        x = w - (w * log10(count - bin - 1)) / log10(count);
         break;
     }
 
@@ -203,7 +203,7 @@
 }
 
 int
-SliceLayer::getBinForX(float x, int count, float w) const
+SliceLayer::getBinForX(double x, int count, double w) const
 {
     int bin = 0;
 
@@ -214,21 +214,21 @@
         break;
         
     case LogBins:
-        bin = int(powf(10.f, (x * log10f(count + 1)) / w) - 1 + 0.0001);
+        bin = int(pow(10.0, (x * log10(count + 1)) / w) - 1 + 0.0001);
         break;
 
     case InvertedLogBins:
-        bin = count + 1 - int(powf(10.f, (log10f(count) * (w - x)) / float(w)) + 0.0001);
+        bin = count + 1 - int(pow(10.0, (log10(count) * (w - x)) / double(w)) + 0.0001);
         break;
     }
 
     return bin;
 }
 
-float
-SliceLayer::getYForValue(float value, const View *v, float &norm) const
+double
+SliceLayer::getYForValue(double value, const View *v, double &norm) const
 {
-    norm = 0.f;
+    norm = 0.0;
 
     if (m_yorigins.find(v) == m_yorigins.end()) return 0;
 
@@ -236,9 +236,9 @@
 
     int yorigin = m_yorigins[v];
     int h = m_heights[v];
-    float thresh = getThresholdDb();
+    double thresh = getThresholdDb();
 
-    float y = 0.f;
+    double y = 0.0;
 
     if (h <= 0) return y;
 
@@ -246,45 +246,45 @@
 
     case dBScale:
     {
-        float db = thresh;
-        if (value > 0.f) db = 10.f * log10f(fabsf(value));
+        double db = thresh;
+        if (value > 0.0) db = 10.0 * log10(fabs(value));
         if (db < thresh) db = thresh;
         norm = (db - thresh) / -thresh;
-        y = yorigin - (float(h) * norm);
+        y = yorigin - (double(h) * norm);
         break;
     }
     
     case MeterScale:
         y = AudioLevel::multiplier_to_preview(value, h);
-        norm = float(y) / float(h);
+        norm = double(y) / double(h);
         y = yorigin - y;
         break;
         
     case AbsoluteScale:
-        value = fabsf(value);
+        value = fabs(value);
         // and fall through
         
     case LinearScale:
     default:
         norm = (value - m_threshold);
         if (norm < 0) norm = 0;
-        y = yorigin - (float(h) * norm);
+        y = yorigin - (double(h) * norm);
         break;
     }
     
     return y;
 }
 
-float
-SliceLayer::getValueForY(float y, const View *v) const
+double
+SliceLayer::getValueForY(double y, const View *v) const
 {
-    float value = 0.f;
+    double value = 0.0;
 
     if (m_yorigins.find(v) == m_yorigins.end()) return value;
 
     int yorigin = m_yorigins[v];
     int h = m_heights[v];
-    float thresh = getThresholdDb();
+    double thresh = getThresholdDb();
 
     if (h <= 0) return value;
 
@@ -294,13 +294,13 @@
 
     case dBScale:
     {
-        float db = ((y / h) * -thresh) + thresh;
-        value = powf(10.f, db/10.f);
+        double db = ((y / h) * -thresh) + thresh;
+        value = pow(10.0, db/10.0);
         break;
     }
 
     case MeterScale:
-        value = AudioLevel::preview_to_multiplier(lrintf(y), h);
+        value = AudioLevel::preview_to_multiplier(int(lrint(y)), h);
         break;
 
     case LinearScale:
@@ -354,21 +354,21 @@
 
     m_values.clear();
     for (int bin = 0; bin < mh; ++bin) {
-        m_values.push_back(0.f);
+        m_values.push_back(0.0);
     }
 
-    int f0 = v->getCentreFrame();
+    sv_frame_t f0 = v->getCentreFrame();
     int f0x = v->getXForFrame(f0);
     f0 = v->getFrameForX(f0x);
-    int f1 = v->getFrameForX(f0x + 1);
+    sv_frame_t f1 = v->getFrameForX(f0x + 1);
     if (f1 > f0) --f1;
 
 //    cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl;
 
     int res = m_sliceableModel->getResolution();
-    int col0 = f0 / res;
+    int col0 = int(f0 / res);
     int col1 = col0;
-    if (m_samplingMode != NearestSample) col1 = f1 / res;
+    if (m_samplingMode != NearestSample) col1 = int(f1 / res);
     f0 = col0 * res;
     f1 = (col1 + 1) * res - 1;
 
@@ -379,7 +379,7 @@
 
     BiasCurve curve;
     getBiasCurve(curve);
-    int cs = curve.size();
+    int cs = int(curve.size());
 
     for (int col = col0; col <= col1; ++col) {
         for (int bin = 0; bin < mh; ++bin) {
@@ -394,31 +394,31 @@
         ++divisor;
     }
 
-    float max = 0.f;
+    float max = 0.0;
     for (int bin = 0; bin < mh; ++bin) {
         if (m_samplingMode == SampleMean && divisor > 0) {
-            m_values[bin] /= divisor;
+            m_values[bin] /= float(divisor);
         }
         if (m_values[bin] > max) max = m_values[bin];
     }
-    if (max != 0.f && m_normalize) {
+    if (max != 0.0 && m_normalize) {
         for (int bin = 0; bin < mh; ++bin) {
             m_values[bin] /= max;
         }
     }
 
-    float nx = xorigin;
+    double nx = xorigin;
 
     ColourMapper mapper(m_colourMap, 0, 1);
 
     for (int bin = 0; bin < mh; ++bin) {
 
-        float x = nx;
+        double x = nx;
         nx = xorigin + getXForBin(bin + 1, mh, w);
 
-        float value = m_values[bin];
-        float norm = 0.f;
-        float y = getYForValue(value, v, norm);
+        double value = m_values[bin];
+        double norm = 0.0;
+        double y = getYForValue(value, v, norm);
 
         if (m_plotStyle == PlotLines) {
 
@@ -515,7 +515,7 @@
 void
 SliceLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const
 {
-    float thresh = m_threshold;
+    double thresh = m_threshold;
     if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) {
         thresh = AudioLevel::dB_to_multiplier(getThresholdDb());
     }
@@ -538,7 +538,7 @@
          const_cast<std::vector<int> *>(&m_scalePoints));
 
     if (mult != 1 && mult != 0) {
-        int log = lrintf(log10f(mult));
+        int log = int(lrint(log10(mult)));
         QString a = tr("x10");
         QString b = QString("%1").arg(-log);
         paint.drawText(3, 8 + paint.fontMetrics().ascent(), a);
@@ -627,7 +627,7 @@
 
         cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl;
 
-	val = lrint(log10(m_gain) * 20.0);
+	val = int(lrint(log10(m_gain) * 20.0));
 	if (val < *min) val = *min;
 	if (val > *max) val = *max;
 
@@ -636,11 +636,11 @@
 	*min = -80;
 	*max = 0;
 
-        *deflt = lrintf(AudioLevel::multiplier_to_dB(m_initialThreshold));
+        *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
 	if (*deflt < *min) *deflt = *min;
 	if (*deflt > *max) *deflt = *max;
 
-	val = lrintf(AudioLevel::multiplier_to_dB(m_threshold));
+	val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
 	if (val < *min) val = *min;
 	if (val > *max) val = *max;
 
@@ -757,10 +757,10 @@
 SliceLayer::setProperty(const PropertyName &name, int value)
 {
     if (name == "Gain") {
-	setGain(pow(10, float(value)/20.0));
+	setGain(powf(10, float(value)/20.0f));
     } else if (name == "Threshold") {
-	if (value == -80) setThreshold(0.0);
-	else setThreshold(AudioLevel::dB_to_multiplier(value));
+	if (value == -80) setThreshold(0.0f);
+	else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
     } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
         setFillColourMap(value);
     } else if (name == "Scale") {
@@ -867,7 +867,7 @@
 SliceLayer::getThresholdDb() const
 {
     if (m_threshold == 0.0) return -80.f;
-    float db = AudioLevel::multiplier_to_dB(m_threshold);
+    float db = float(AudioLevel::multiplier_to_dB(m_threshold));
     return db;
 }
 
@@ -942,7 +942,7 @@
 }
 
 bool
-SliceLayer::getValueExtents(float &, float &, bool &, QString &) const
+SliceLayer::getValueExtents(double &, double &, bool &, QString &) const
 {
     return false;
 }
--- a/layer/SliceLayer.h	Mon Mar 09 14:35:21 2015 +0000
+++ b/layer/SliceLayer.h	Mon Mar 09 15:59:04 2015 +0000
@@ -144,8 +144,8 @@
     mutable std::map<const View *, int> m_xorigins;
     mutable std::map<const View *, int> m_yorigins;
     mutable std::map<const View *, int> m_heights;
-    mutable int                    m_currentf0;
-    mutable int                    m_currentf1;
+    mutable sv_frame_t                m_currentf0;
+    mutable sv_frame_t                m_currentf1;
     mutable std::vector<float>        m_values;
 };
 
--- a/layer/SpectrogramLayer.cpp	Mon Mar 09 14:35:21 2015 +0000
+++ b/layer/SpectrogramLayer.cpp	Mon Mar 09 15:59:04 2015 +0000
@@ -141,8 +141,8 @@
     connectSignals(m_model);
 
     connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid()));
-    connect(m_model, SIGNAL(modelChangedWithin(int, int)),
-	    this, SLOT(cacheInvalid(int, int)));
+    connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
+	    this, SLOT(cacheInvalid(sv_frame_t, sv_frame_t)));
 
     emit modelReplaced();
 }
@@ -242,11 +242,11 @@
 	*min = -50;
 	*max = 50;
 
-        *deflt = lrintf(log10(m_initialGain) * 20.0);;
+        *deflt = int(lrint(log10(m_initialGain) * 20.0));
 	if (*deflt < *min) *deflt = *min;
 	if (*deflt > *max) *deflt = *max;
 
-	val = lrintf(log10(m_gain) * 20.0);
+	val = int(lrint(log10(m_gain) * 20.0));
 	if (val < *min) val = *min;
 	if (val > *max) val = *max;
 
@@ -255,11 +255,11 @@
 	*min = -50;
 	*max = 0;
 
-        *deflt = lrintf(AudioLevel::multiplier_to_dB(m_initialThreshold));
+        *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
 	if (*deflt < *min) *deflt = *min;
 	if (*deflt > *max) *deflt = *max;
 
-	val = lrintf(AudioLevel::multiplier_to_dB(m_threshold));
+	val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
 	if (val < *min) val = *min;
 	if (val > *max) val = *max;
 
@@ -481,10 +481,10 @@
 SpectrogramLayer::setProperty(const PropertyName &name, int value)
 {
     if (name == "Gain") {
-	setGain(pow(10, float(value)/20.0));
+	setGain(float(pow(10, float(value)/20.0)));
     } else if (name == "Threshold") {
 	if (value == -50) setThreshold(0.0);
-	else setThreshold(AudioLevel::dB_to_multiplier(value));
+	else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
     } else if (name == "Colour Rotation") {
 	setColourRotation(value);
     } else if (name == "Colour") {
@@ -572,7 +572,7 @@
 }
 
 void
-SpectrogramLayer::invalidateImageCaches(int startFrame, int endFrame)
+SpectrogramLayer::invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame)
 {
     for (ViewImageCache::iterator i = m_imageCaches.begin();
          i != m_imageCaches.end(); ++i) {
@@ -1049,7 +1049,7 @@
 }
 
 void
-SpectrogramLayer::cacheInvalid(int from, int to)
+SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t 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;
-        int lastFill = i->second.second;
+        sv_frame_t lastFill = i->second.second;
 
         if (model) {
 
-            int fill = model->getFillExtent();
+            sv_frame_t fill = model->getFillExtent();
 
 #ifdef DEBUG_SPECTROGRAM_REPAINT
             SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl;
--- a/layer/SpectrogramLayer.h	Mon Mar 09 14:35:21 2015 +0000
+++ b/layer/SpectrogramLayer.h	Mon Mar 09 15:59:04 2015 +0000
@@ -243,7 +243,7 @@
 
 protected slots:
     void cacheInvalid();
-    void cacheInvalid(int startFrame, int endFrame);
+    void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
     
     void preferenceChanged(PropertyContainer::PropertyName name);
 
@@ -315,7 +315,7 @@
     };
     typedef std::map<const View *, ImageCache> ViewImageCache;
     void invalidateImageCaches();
-    void invalidateImageCaches(int startFrame, int endFrame);
+    void invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame);
     mutable ViewImageCache m_imageCaches;
 
     /**
@@ -328,7 +328,7 @@
 
     mutable QTimer *m_updateTimer;
 
-    mutable int m_candidateFillStartFrame;
+    mutable sv_frame_t m_candidateFillStartFrame;
     bool m_exiting;
 
     void initialisePalette();
@@ -343,13 +343,6 @@
     double getEffectiveMinFrequency() const;
     double getEffectiveMaxFrequency() const;
 
-    struct LayerRange {
-	int   startFrame;
-	int    zoomLevel;
-	int modelStart;
-	int modelEnd;
-    };
-
     // Note that the getYBin... methods return the nominal bin in the
     // un-smoothed spectrogram.  This is not necessarily the same bin
     // as is pulled from the spectrogram and drawn at the given
@@ -380,7 +373,7 @@
     Dense3DModelPeakCache *getPeakCache(const View *v) const;
     void invalidateFFTModels();
 
-    typedef std::pair<FFTModel *, int> FFTFillPair; // model, last fill
+    typedef std::pair<FFTModel *, sv_frame_t> FFTFillPair; // model, last fill
     typedef std::map<const View *, FFTFillPair> ViewFFTMap;
     typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap;
     mutable ViewFFTMap m_fftModels;