Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1414:fa986b91d77f
Merge from branch fix-static-analysis
author | Chris Cannam |
---|---|
date | Wed, 09 Jan 2019 15:24:51 +0000 |
parents | c8a6fd3f9dff |
children | 8e40faa56ffd |
comparison
equal
deleted
inserted
replaced
1413:0930a27ebea2 | 1414:fa986b91d77f |
---|---|
54 //#define DEBUG_SPECTROGRAM_REPAINT 1 | 54 //#define DEBUG_SPECTROGRAM_REPAINT 1 |
55 | 55 |
56 using namespace std; | 56 using namespace std; |
57 | 57 |
58 SpectrogramLayer::SpectrogramLayer(Configuration config) : | 58 SpectrogramLayer::SpectrogramLayer(Configuration config) : |
59 m_model(0), | 59 m_model(nullptr), |
60 m_channel(0), | 60 m_channel(0), |
61 m_windowSize(1024), | 61 m_windowSize(1024), |
62 m_windowType(HanningWindow), | 62 m_windowType(HanningWindow), |
63 m_windowHopLevel(2), | 63 m_windowHopLevel(2), |
64 m_oversampling(1), | 64 m_oversampling(1), |
81 m_normalizeVisibleArea(false), | 81 m_normalizeVisibleArea(false), |
82 m_lastEmittedZoomStep(-1), | 82 m_lastEmittedZoomStep(-1), |
83 m_synchronous(false), | 83 m_synchronous(false), |
84 m_haveDetailedScale(false), | 84 m_haveDetailedScale(false), |
85 m_exiting(false), | 85 m_exiting(false), |
86 m_fftModel(0), | 86 m_fftModel(nullptr), |
87 m_wholeCache(0), | 87 m_wholeCache(nullptr), |
88 m_peakCache(0), | 88 m_peakCache(nullptr), |
89 m_peakCacheDivisor(8) | 89 m_peakCacheDivisor(8) |
90 { | 90 { |
91 QString colourConfigName = "spectrogram-colour"; | 91 QString colourConfigName = "spectrogram-colour"; |
92 int colourConfigDefault = int(ColourMapper::Green); | 92 int colourConfigDefault = int(ColourMapper::Green); |
93 | 93 |
146 | 146 |
147 delete m_fftModel; | 147 delete m_fftModel; |
148 delete m_peakCache; | 148 delete m_peakCache; |
149 delete m_wholeCache; | 149 delete m_wholeCache; |
150 | 150 |
151 m_fftModel = 0; | 151 m_fftModel = nullptr; |
152 m_peakCache = 0; | 152 m_peakCache = nullptr; |
153 m_wholeCache = 0; | 153 m_wholeCache = nullptr; |
154 } | 154 } |
155 | 155 |
156 pair<ColourScaleType, double> | 156 pair<ColourScaleType, double> |
157 SpectrogramLayer::convertToColourScale(int value) | 157 SpectrogramLayer::convertToColourScale(int value) |
158 { | 158 { |
580 } | 580 } |
581 if (name == "Threshold") { | 581 if (name == "Threshold") { |
582 return new LinearRangeMapper(-81, -1, -81, -1, tr("dB"), false, | 582 return new LinearRangeMapper(-81, -1, -81, -1, tr("dB"), false, |
583 { { -81, Strings::minus_infinity } }); | 583 { { -81, Strings::minus_infinity } }); |
584 } | 584 } |
585 return 0; | 585 return nullptr; |
586 } | 586 } |
587 | 587 |
588 void | 588 void |
589 SpectrogramLayer::setProperty(const PropertyName &name, int value) | 589 SpectrogramLayer::setProperty(const PropertyName &name, int value) |
590 { | 590 { |
1370 SpectrogramLayer::recreateFFTModel() | 1370 SpectrogramLayer::recreateFFTModel() |
1371 { | 1371 { |
1372 SVDEBUG << "SpectrogramLayer::recreateFFTModel called" << endl; | 1372 SVDEBUG << "SpectrogramLayer::recreateFFTModel called" << endl; |
1373 | 1373 |
1374 if (!m_model || !m_model->isOK()) { | 1374 if (!m_model || !m_model->isOK()) { |
1375 emit sliceableModelReplaced(m_fftModel, 0); | 1375 emit sliceableModelReplaced(m_fftModel, nullptr); |
1376 deleteDerivedModels(); | 1376 deleteDerivedModels(); |
1377 return; | 1377 return; |
1378 } | 1378 } |
1379 | 1379 |
1380 if (m_fftModel) m_fftModel->aboutToDelete(); | 1380 if (m_fftModel) m_fftModel->aboutToDelete(); |
1381 | 1381 |
1382 if (m_peakCache) m_peakCache->aboutToDelete(); | 1382 if (m_peakCache) m_peakCache->aboutToDelete(); |
1383 delete m_peakCache; | 1383 delete m_peakCache; |
1384 m_peakCache = 0; | 1384 m_peakCache = nullptr; |
1385 | 1385 |
1386 if (m_wholeCache) m_wholeCache->aboutToDelete(); | 1386 if (m_wholeCache) m_wholeCache->aboutToDelete(); |
1387 delete m_wholeCache; | 1387 delete m_wholeCache; |
1388 m_wholeCache = 0; | 1388 m_wholeCache = nullptr; |
1389 | 1389 |
1390 FFTModel *newModel = new FFTModel(m_model, | 1390 FFTModel *newModel = new FFTModel(m_model, |
1391 m_channel, | 1391 m_channel, |
1392 m_windowType, | 1392 m_windowType, |
1393 m_windowSize, | 1393 m_windowSize, |
1394 getWindowIncrement(), | 1394 getWindowIncrement(), |
1395 getFFTSize()); | 1395 getFFTSize()); |
1396 | 1396 |
1397 if (!newModel->isOK()) { | 1397 if (!newModel->isOK()) { |
1398 QMessageBox::critical | 1398 QMessageBox::critical |
1399 (0, tr("FFT cache failed"), | 1399 (nullptr, tr("FFT cache failed"), |
1400 tr("Failed to create the FFT model for this spectrogram.\n" | 1400 tr("Failed to create the FFT model for this spectrogram.\n" |
1401 "There may be insufficient memory or disc space to continue.")); | 1401 "There may be insufficient memory or disc space to continue.")); |
1402 delete newModel; | 1402 delete newModel; |
1403 delete m_fftModel; | 1403 delete m_fftModel; |
1404 m_fftModel = 0; | 1404 m_fftModel = nullptr; |
1405 return; | 1405 return; |
1406 } | 1406 } |
1407 | 1407 |
1408 FFTModel *oldModel = m_fftModel; | 1408 FFTModel *oldModel = m_fftModel; |
1409 m_fftModel = newModel; | 1409 m_fftModel = newModel; |
2312 { | 2312 { |
2313 public: | 2313 public: |
2314 SpectrogramRangeMapper(sv_samplerate_t sr, int /* fftsize */) : | 2314 SpectrogramRangeMapper(sv_samplerate_t sr, int /* fftsize */) : |
2315 m_dist(sr / 2), | 2315 m_dist(sr / 2), |
2316 m_s2(sqrt(sqrt(2))) { } | 2316 m_s2(sqrt(sqrt(2))) { } |
2317 ~SpectrogramRangeMapper() { } | 2317 ~SpectrogramRangeMapper() override { } |
2318 | 2318 |
2319 virtual int getPositionForValue(double value) const { | 2319 int getPositionForValue(double value) const override { |
2320 | 2320 |
2321 double dist = m_dist; | 2321 double dist = m_dist; |
2322 | 2322 |
2323 int n = 0; | 2323 int n = 0; |
2324 | 2324 |
2328 } | 2328 } |
2329 | 2329 |
2330 return n; | 2330 return n; |
2331 } | 2331 } |
2332 | 2332 |
2333 virtual int getPositionForValueUnclamped(double value) const { | 2333 int getPositionForValueUnclamped(double value) const override { |
2334 // We don't really support this | 2334 // We don't really support this |
2335 return getPositionForValue(value); | 2335 return getPositionForValue(value); |
2336 } | 2336 } |
2337 | 2337 |
2338 virtual double getValueForPosition(int position) const { | 2338 double getValueForPosition(int position) const override { |
2339 | 2339 |
2340 // Vertical zoom step 0 shows the entire range from DC -> | 2340 // Vertical zoom step 0 shows the entire range from DC -> |
2341 // Nyquist frequency. Step 1 shows 2^(1/4) of the range of | 2341 // Nyquist frequency. Step 1 shows 2^(1/4) of the range of |
2342 // step 0, and so on until the visible range is smaller than | 2342 // step 0, and so on until the visible range is smaller than |
2343 // the frequency step between bins at the current fft size. | 2343 // the frequency step between bins at the current fft size. |
2351 } | 2351 } |
2352 | 2352 |
2353 return dist; | 2353 return dist; |
2354 } | 2354 } |
2355 | 2355 |
2356 virtual double getValueForPositionUnclamped(int position) const { | 2356 double getValueForPositionUnclamped(int position) const override { |
2357 // We don't really support this | 2357 // We don't really support this |
2358 return getValueForPosition(position); | 2358 return getValueForPosition(position); |
2359 } | 2359 } |
2360 | 2360 |
2361 virtual QString getUnit() const { return "Hz"; } | 2361 QString getUnit() const override { return "Hz"; } |
2362 | 2362 |
2363 protected: | 2363 protected: |
2364 double m_dist; | 2364 double m_dist; |
2365 double m_s2; | 2365 double m_s2; |
2366 }; | 2366 }; |
2471 } | 2471 } |
2472 | 2472 |
2473 RangeMapper * | 2473 RangeMapper * |
2474 SpectrogramLayer::getNewVerticalZoomRangeMapper() const | 2474 SpectrogramLayer::getNewVerticalZoomRangeMapper() const |
2475 { | 2475 { |
2476 if (!m_model) return 0; | 2476 if (!m_model) return nullptr; |
2477 return new SpectrogramRangeMapper(m_model->getSampleRate(), getFFTSize()); | 2477 return new SpectrogramRangeMapper(m_model->getSampleRate(), getFFTSize()); |
2478 } | 2478 } |
2479 | 2479 |
2480 void | 2480 void |
2481 SpectrogramLayer::updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const | 2481 SpectrogramLayer::updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const |