comparison layer/SpectrogramLayer.cpp @ 1459:42c87368287c

Merge from branch single-point
author Chris Cannam
date Fri, 17 May 2019 10:02:52 +0100
parents 6cf3cb6641e1
children 66bf1abfefc1
comparison
equal deleted inserted replaced
1441:8d5bf4ab98ef 1459:42c87368287c
1409 } 1409 }
1410 1410
1411 FFTModel *oldModel = m_fftModel; 1411 FFTModel *oldModel = m_fftModel;
1412 m_fftModel = newModel; 1412 m_fftModel = newModel;
1413 1413
1414 if (canStoreWholeCache()) { // i.e. if enough memory 1414 bool createWholeCache = false;
1415 checkCacheSpace(&m_peakCacheDivisor, &createWholeCache);
1416
1417 if (createWholeCache) {
1415 m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1); 1418 m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1);
1416 m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor); 1419 m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor);
1417 } else { 1420 } else {
1418 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor); 1421 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor);
1419 } 1422 }
1420 1423
1421 emit sliceableModelReplaced(oldModel, m_fftModel); 1424 emit sliceableModelReplaced(oldModel, m_fftModel);
1422 delete oldModel; 1425 delete oldModel;
1423 } 1426 }
1424 1427
1425 bool 1428 void
1426 SpectrogramLayer::canStoreWholeCache() const 1429 SpectrogramLayer::checkCacheSpace(int *suggestedPeakDivisor,
1427 { 1430 bool *createWholeCache) const
1428 if (!m_fftModel) { 1431 {
1429 return false; // or true, doesn't really matter 1432 *suggestedPeakDivisor = 8;
1430 } 1433 *createWholeCache = false;
1434
1435 if (!m_fftModel) return;
1431 1436
1432 size_t sz = 1437 size_t sz =
1433 size_t(m_fftModel->getWidth()) * 1438 size_t(m_fftModel->getWidth()) *
1434 size_t(m_fftModel->getHeight()) * 1439 size_t(m_fftModel->getHeight()) *
1435 sizeof(float); 1440 sizeof(float);
1436 1441
1437 try { 1442 try {
1438 SVDEBUG << "Requesting advice from StorageAdviser on whether to create whole-model cache" << endl; 1443 SVDEBUG << "Requesting advice from StorageAdviser on whether to create whole-model cache" << endl;
1444 // The lower amount here is the amount required for the
1445 // slightly higher-resolution version of the peak cache
1446 // without a whole-model cache; the higher amount is that for
1447 // the whole-model cache. The factors of 1024 are because
1448 // StorageAdviser rather stupidly works in kilobytes
1439 StorageAdviser::Recommendation recommendation = 1449 StorageAdviser::Recommendation recommendation =
1440 StorageAdviser::recommend 1450 StorageAdviser::recommend
1441 (StorageAdviser::Criteria(StorageAdviser::SpeedCritical | 1451 (StorageAdviser::Criteria(StorageAdviser::SpeedCritical |
1442 StorageAdviser::PrecisionCritical | 1452 StorageAdviser::PrecisionCritical |
1443 StorageAdviser::FrequentLookupLikely), 1453 StorageAdviser::FrequentLookupLikely),
1444 sz / 1024, sz / 1024); 1454 (sz / 8) / 1024, sz / 1024);
1445 if ((recommendation & StorageAdviser::UseDisc) || 1455 if (recommendation & StorageAdviser::UseDisc) {
1446 (recommendation & StorageAdviser::ConserveSpace)) {
1447 SVDEBUG << "Seems inadvisable to create whole-model cache" << endl; 1456 SVDEBUG << "Seems inadvisable to create whole-model cache" << endl;
1448 return false; 1457 } else if (recommendation & StorageAdviser::ConserveSpace) {
1449 } else { 1458 SVDEBUG << "Seems inadvisable to create whole-model cache but acceptable to use the slightly higher-resolution peak cache" << endl;
1459 *suggestedPeakDivisor = 4;
1460 } else {
1450 SVDEBUG << "Seems fine to create whole-model cache" << endl; 1461 SVDEBUG << "Seems fine to create whole-model cache" << endl;
1451 return true; 1462 *createWholeCache = true;
1452 } 1463 }
1453 } catch (const InsufficientDiscSpace &) { 1464 } catch (const InsufficientDiscSpace &) {
1454 SVDEBUG << "Seems like a terrible idea to create whole-model cache" << endl; 1465 SVDEBUG << "Seems like a terrible idea to create whole-model cache" << endl;
1455 return false;
1456 } 1466 }
1457 } 1467 }
1458 1468
1459 const Model * 1469 const Model *
1460 SpectrogramLayer::getSliceableModel() const 1470 SpectrogramLayer::getSliceableModel() const
1790 sv_frame_t right = left + resolution; 1800 sv_frame_t right = left + resolution;
1791 1801
1792 switch (snap) { 1802 switch (snap) {
1793 case SnapLeft: frame = left; break; 1803 case SnapLeft: frame = left; break;
1794 case SnapRight: frame = right; break; 1804 case SnapRight: frame = right; break;
1795 case SnapNearest:
1796 case SnapNeighbouring: 1805 case SnapNeighbouring:
1797 if (frame - left > right - frame) frame = right; 1806 if (frame - left > right - frame) frame = right;
1798 else frame = left; 1807 else frame = left;
1799 break; 1808 break;
1800 } 1809 }
1859 void 1868 void
1860 SpectrogramLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint, 1869 SpectrogramLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint,
1861 QPoint cursorPos) const 1870 QPoint cursorPos) const
1862 { 1871 {
1863 paint.save(); 1872 paint.save();
1864 1873
1865 int sw = getVerticalScaleWidth(v, m_haveDetailedScale, paint); 1874 int sw = getVerticalScaleWidth(v, m_haveDetailedScale, paint);
1866 1875
1867 QFont fn = paint.font(); 1876 QFont fn = paint.font();
1868 if (fn.pointSize() > 8) { 1877 if (fn.pointSize() > 8) {
1869 fn.setPointSize(fn.pointSize() - 1); 1878 fn.setPointSize(fn.pointSize() - 1);