Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1211:7a19738b9762 3.0-integration
Recreate FFT model when something changes, not the next time it's requested (avoids extra work when only retrieving the model)
author | Chris Cannam |
---|---|
date | Thu, 05 Jan 2017 11:10:57 +0000 |
parents | f7bb22999d2e |
children | a1ee3108d1d3 |
comparison
equal
deleted
inserted
replaced
1210:efc7586de499 | 1211:7a19738b9762 |
---|---|
127 } | 127 } |
128 | 128 |
129 SpectrogramLayer::~SpectrogramLayer() | 129 SpectrogramLayer::~SpectrogramLayer() |
130 { | 130 { |
131 invalidateRenderers(); | 131 invalidateRenderers(); |
132 invalidateFFTModel(); | 132 |
133 delete m_fftModel; | |
134 delete m_peakCache; | |
133 } | 135 } |
134 | 136 |
135 pair<ColourScaleType, double> | 137 pair<ColourScaleType, double> |
136 SpectrogramLayer::convertToColourScale(int value) | 138 SpectrogramLayer::convertToColourScale(int value) |
137 { | 139 { |
191 // cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << endl; | 193 // cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << endl; |
192 | 194 |
193 if (model == m_model) return; | 195 if (model == m_model) return; |
194 | 196 |
195 m_model = model; | 197 m_model = model; |
196 invalidateFFTModel(); | 198 |
199 recreateFFTModel(); | |
197 | 200 |
198 if (!m_model || !m_model->isOK()) return; | 201 if (!m_model || !m_model->isOK()) return; |
199 | 202 |
200 connectSignals(m_model); | 203 connectSignals(m_model); |
201 | 204 |
671 { | 674 { |
672 if (m_channel == ch) return; | 675 if (m_channel == ch) return; |
673 | 676 |
674 invalidateRenderers(); | 677 invalidateRenderers(); |
675 m_channel = ch; | 678 m_channel = ch; |
676 invalidateFFTModel(); | 679 recreateFFTModel(); |
677 | 680 |
678 emit layerParametersChanged(); | 681 emit layerParametersChanged(); |
679 } | 682 } |
680 | 683 |
681 int | 684 int |
715 | 718 |
716 invalidateRenderers(); | 719 invalidateRenderers(); |
717 | 720 |
718 m_windowSize = ws; | 721 m_windowSize = ws; |
719 | 722 |
720 invalidateFFTModel(); | 723 recreateFFTModel(); |
721 | 724 |
722 emit layerParametersChanged(); | 725 emit layerParametersChanged(); |
723 } | 726 } |
724 | 727 |
725 int | 728 int |
735 | 738 |
736 invalidateRenderers(); | 739 invalidateRenderers(); |
737 | 740 |
738 m_windowHopLevel = v; | 741 m_windowHopLevel = v; |
739 | 742 |
740 invalidateFFTModel(); | 743 recreateFFTModel(); |
741 | 744 |
742 emit layerParametersChanged(); | 745 emit layerParametersChanged(); |
743 | 746 |
744 // fillCache(); | 747 // fillCache(); |
745 } | 748 } |
757 | 760 |
758 invalidateRenderers(); | 761 invalidateRenderers(); |
759 | 762 |
760 m_windowType = w; | 763 m_windowType = w; |
761 | 764 |
762 invalidateFFTModel(); | 765 recreateFFTModel(); |
763 | 766 |
764 emit layerParametersChanged(); | 767 emit layerParametersChanged(); |
765 } | 768 } |
766 | 769 |
767 WindowType | 770 WindowType |
1323 } | 1326 } |
1324 | 1327 |
1325 return rv; | 1328 return rv; |
1326 } | 1329 } |
1327 | 1330 |
1328 FFTModel * | 1331 void |
1329 SpectrogramLayer::getFFTModel() const | 1332 SpectrogramLayer::recreateFFTModel() |
1330 { | 1333 { |
1331 if (!m_model) return 0; | 1334 #ifdef DEBUG_SPECTROGRAM |
1332 | 1335 cerr << "SpectrogramLayer::recreateFFTModel called" << endl; |
1333 int fftSize = getFFTSize(); | 1336 #endif |
1334 | 1337 |
1335 //!!! it is now surely slower to do this on every getFFTModel() | 1338 if (!m_model || !m_model->isOK()) { |
1336 //!!! request than it would be to recreate the model immediately | 1339 emit sliceableModelReplaced(m_fftModel, 0); |
1337 //!!! when something changes instead of just invalidating it | 1340 delete m_fftModel; |
1338 | 1341 delete m_peakCache; |
1339 if (m_fftModel && | 1342 m_fftModel = 0; |
1340 m_fftModel->getHeight() == fftSize / 2 + 1 && | 1343 m_peakCache = 0; |
1341 m_fftModel->getWindowIncrement() == getWindowIncrement()) { | 1344 return; |
1342 return m_fftModel; | 1345 } |
1343 } | 1346 |
1344 | 1347 FFTModel *oldModel = m_fftModel; |
1345 delete m_peakCache; | 1348 |
1346 m_peakCache = 0; | |
1347 | |
1348 delete m_fftModel; | |
1349 m_fftModel = new FFTModel(m_model, | 1349 m_fftModel = new FFTModel(m_model, |
1350 m_channel, | 1350 m_channel, |
1351 m_windowType, | 1351 m_windowType, |
1352 m_windowSize, | 1352 m_windowSize, |
1353 getWindowIncrement(), | 1353 getWindowIncrement(), |
1354 fftSize); | 1354 getFFTSize()); |
1355 | 1355 |
1356 delete m_peakCache; | |
1357 m_peakCache = 0; | |
1358 | |
1356 if (!m_fftModel->isOK()) { | 1359 if (!m_fftModel->isOK()) { |
1357 QMessageBox::critical | 1360 QMessageBox::critical |
1358 (0, tr("FFT cache failed"), | 1361 (0, tr("FFT cache failed"), |
1359 tr("Failed to create the FFT model for this spectrogram.\n" | 1362 tr("Failed to create the FFT model for this spectrogram.\n" |
1360 "There may be insufficient memory or disc space to continue.")); | 1363 "There may be insufficient memory or disc space to continue.")); |
1361 delete m_fftModel; | 1364 delete m_fftModel; |
1362 m_fftModel = 0; | 1365 m_fftModel = 0; |
1363 return 0; | 1366 return; |
1364 } | 1367 } |
1365 | 1368 |
1366 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, m_fftModel); | 1369 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor); |
1367 | 1370 |
1368 return m_fftModel; | 1371 emit sliceableModelReplaced(oldModel, m_fftModel); |
1369 } | 1372 |
1370 | 1373 delete oldModel; |
1371 Dense3DModelPeakCache * | |
1372 SpectrogramLayer::getPeakCache() const | |
1373 { | |
1374 //!!! see comment in getFFTModel | |
1375 | |
1376 if (!m_peakCache) { | |
1377 FFTModel *f = getFFTModel(); | |
1378 if (!f) return 0; | |
1379 m_peakCache = new Dense3DModelPeakCache(f, m_peakCacheDivisor); | |
1380 } | |
1381 return m_peakCache; | |
1382 } | 1374 } |
1383 | 1375 |
1384 const Model * | 1376 const Model * |
1385 SpectrogramLayer::getSliceableModel() const | 1377 SpectrogramLayer::getSliceableModel() const |
1386 { | 1378 { |
1387 return m_fftModel; | 1379 return m_fftModel; |
1388 } | |
1389 | |
1390 void | |
1391 SpectrogramLayer::invalidateFFTModel() | |
1392 { | |
1393 #ifdef DEBUG_SPECTROGRAM | |
1394 cerr << "SpectrogramLayer::invalidateFFTModel called" << endl; | |
1395 #endif | |
1396 | |
1397 emit sliceableModelReplaced(m_fftModel, 0); | |
1398 | |
1399 delete m_fftModel; | |
1400 delete m_peakCache; | |
1401 | |
1402 m_fftModel = 0; | |
1403 m_peakCache = 0; | |
1404 } | 1380 } |
1405 | 1381 |
1406 void | 1382 void |
1407 SpectrogramLayer::invalidateMagnitudes() | 1383 SpectrogramLayer::invalidateMagnitudes() |
1408 { | 1384 { |