comparison layer/SpectrogramLayer.cpp @ 988:4f4f0e158ecf 3.0-integration

Merge from branch simple-fft-model
author Chris Cannam
date Wed, 01 Jul 2015 13:27:03 +0100
parents 98827470ada2 aef8f6fff278
children 1a6304c547bf
comparison
equal deleted inserted replaced
987:3f7cdfc56dce 988:4f4f0e158ecf
76 m_normalization(NoNormalization), 76 m_normalization(NoNormalization),
77 m_lastEmittedZoomStep(-1), 77 m_lastEmittedZoomStep(-1),
78 m_synchronous(false), 78 m_synchronous(false),
79 m_haveDetailedScale(false), 79 m_haveDetailedScale(false),
80 m_lastPaintBlockWidth(0), 80 m_lastPaintBlockWidth(0),
81 m_updateTimer(0),
82 m_candidateFillStartFrame(0),
83 m_exiting(false), 81 m_exiting(false),
84 m_sliceableModel(0) 82 m_sliceableModel(0)
85 { 83 {
86 if (config == FullRangeDb) { 84 if (config == FullRangeDb) {
87 m_initialMaxFrequency = 0; 85 m_initialMaxFrequency = 0;
116 initialisePalette(); 114 initialisePalette();
117 } 115 }
118 116
119 SpectrogramLayer::~SpectrogramLayer() 117 SpectrogramLayer::~SpectrogramLayer()
120 { 118 {
121 delete m_updateTimer;
122 m_updateTimer = 0;
123
124 invalidateFFTModels(); 119 invalidateFFTModels();
125 } 120 }
126 121
127 void 122 void
128 SpectrogramLayer::setModel(const DenseTimeValueModel *model) 123 SpectrogramLayer::setModel(const DenseTimeValueModel *model)
590 585
591 //!!! when are views removed from the map? on setLayerDormant? 586 //!!! when are views removed from the map? on setLayerDormant?
592 const LayerGeometryProvider *v = i->first; 587 const LayerGeometryProvider *v = i->first;
593 588
594 #ifdef DEBUG_SPECTROGRAM_REPAINT 589 #ifdef DEBUG_SPECTROGRAM_REPAINT
595 SVDEBUG << "SpectrogramLayer::invalidateImageCaches(" 590 cerr << "SpectrogramLayer::invalidateImageCaches("
596 << startFrame << ", " << endFrame << "): view range is " 591 << startFrame << ", " << endFrame << "): view range is "
597 << v->getStartFrame() << ", " << v->getEndFrame() 592 << v->getStartFrame() << ", " << v->getEndFrame()
598 << endl; 593 << endl;
599 594
600 cerr << "Valid area was: " << i->second.validArea.x() << ", " 595 cerr << "Valid area was: " << i->second.validArea.x() << ", "
610 #endif 605 #endif
611 return; 606 return;
612 } 607 }
613 int x = v->getXForFrame(startFrame); 608 int x = v->getXForFrame(startFrame);
614 #ifdef DEBUG_SPECTROGRAM_REPAINT 609 #ifdef DEBUG_SPECTROGRAM_REPAINT
615 SVDEBUG << "clipping from 0 to " << x-1 << endl; 610 cerr << "clipping from 0 to " << x-1 << endl;
616 #endif 611 #endif
617 if (x > 1) { 612 if (x > 1) {
618 i->second.validArea &= 613 i->second.validArea &=
619 QRect(0, 0, x-1, v->getPaintHeight()); 614 QRect(0, 0, x-1, v->getPaintHeight());
620 } else { 615 } else {
627 #endif 622 #endif
628 return; 623 return;
629 } 624 }
630 int x = v->getXForFrame(endFrame); 625 int x = v->getXForFrame(endFrame);
631 #ifdef DEBUG_SPECTROGRAM_REPAINT 626 #ifdef DEBUG_SPECTROGRAM_REPAINT
632 SVDEBUG << "clipping from " << x+1 << " to " << v->getPaintWidth() 627 cerr << "clipping from " << x+1 << " to " << v->getPaintWidth()
633 << endl; 628 << endl;
634 #endif 629 #endif
635 if (x < v->getPaintWidth()) { 630 if (x < v->getPaintWidth()) {
636 i->second.validArea &= 631 i->second.validArea &=
637 QRect(x+1, 0, v->getPaintWidth()-(x+1), v->getPaintHeight()); 632 QRect(x+1, 0, v->getPaintWidth()-(x+1), v->getPaintHeight());
966 SpectrogramLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) 961 SpectrogramLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
967 { 962 {
968 if (dormant) { 963 if (dormant) {
969 964
970 #ifdef DEBUG_SPECTROGRAM_REPAINT 965 #ifdef DEBUG_SPECTROGRAM_REPAINT
971 SVDEBUG << "SpectrogramLayer::setLayerDormant(" << dormant << ")" 966 cerr << "SpectrogramLayer::setLayerDormant(" << dormant << ")"
972 << endl; 967 << endl;
973 #endif 968 #endif
974 969
975 if (isLayerDormant(v)) { 970 if (isLayerDormant(v)) {
976 return; 971 return;
979 Layer::setLayerDormant(v, true); 974 Layer::setLayerDormant(v, true);
980 975
981 const View *view = v->getView(); 976 const View *view = v->getView();
982 977
983 invalidateImageCaches(); 978 invalidateImageCaches();
979
984 m_imageCaches.erase(view); 980 m_imageCaches.erase(view);
985 981
986 if (m_fftModels.find(view) != m_fftModels.end()) { 982 if (m_fftModels.find(view) != m_fftModels.end()) {
987 983
988 if (m_sliceableModel == m_fftModels[view].first) { 984 if (m_sliceableModel == m_fftModels[view]) {
989 bool replaced = false; 985 bool replaced = false;
990 for (ViewFFTMap::iterator i = m_fftModels.begin(); 986 for (ViewFFTMap::iterator i = m_fftModels.begin();
991 i != m_fftModels.end(); ++i) { 987 i != m_fftModels.end(); ++i) {
992 if (i->second.first != m_sliceableModel) { 988 if (i->second != m_sliceableModel) {
993 emit sliceableModelReplaced(m_sliceableModel, i->second.first); 989 emit sliceableModelReplaced(m_sliceableModel, i->second);
994 replaced = true; 990 replaced = true;
995 break; 991 break;
996 } 992 }
997 } 993 }
998 if (!replaced) emit sliceableModelReplaced(m_sliceableModel, 0); 994 if (!replaced) emit sliceableModelReplaced(m_sliceableModel, 0);
999 } 995 }
1000 996
1001 delete m_fftModels[view].first; 997 delete m_fftModels[view];
1002 m_fftModels.erase(view); 998 m_fftModels.erase(view);
1003 999
1004 delete m_peakCaches[view]; 1000 delete m_peakCaches[view];
1005 m_peakCaches.erase(view); 1001 m_peakCaches.erase(view);
1006 } 1002 }
1013 1009
1014 void 1010 void
1015 SpectrogramLayer::cacheInvalid() 1011 SpectrogramLayer::cacheInvalid()
1016 { 1012 {
1017 #ifdef DEBUG_SPECTROGRAM_REPAINT 1013 #ifdef DEBUG_SPECTROGRAM_REPAINT
1018 SVDEBUG << "SpectrogramLayer::cacheInvalid()" << endl; 1014 cerr << "SpectrogramLayer::cacheInvalid()" << endl;
1019 #endif 1015 #endif
1020 1016
1021 invalidateImageCaches(); 1017 invalidateImageCaches();
1022 invalidateMagnitudes(); 1018 invalidateMagnitudes();
1023 } 1019 }
1024 1020
1025 void 1021 void
1026 SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to) 1022 SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to)
1027 { 1023 {
1028 #ifdef DEBUG_SPECTROGRAM_REPAINT 1024 #ifdef DEBUG_SPECTROGRAM_REPAINT
1029 SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; 1025 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl;
1030 #endif 1026 #endif
1031 1027
1032 invalidateImageCaches(from, to); 1028 invalidateImageCaches(from, to);
1033 invalidateMagnitudes(); 1029 invalidateMagnitudes();
1034 }
1035
1036 void
1037 SpectrogramLayer::fillTimerTimedOut()
1038 {
1039 if (!m_model) return;
1040
1041 bool allDone = true;
1042
1043 #ifdef DEBUG_SPECTROGRAM_REPAINT
1044 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: have " << m_fftModels.size() << " FFT models associated with views" << endl;
1045 #endif
1046
1047 for (ViewFFTMap::iterator i = m_fftModels.begin();
1048 i != m_fftModels.end(); ++i) {
1049
1050 const FFTModel *model = i->second.first;
1051 sv_frame_t lastFill = i->second.second;
1052
1053 if (model) {
1054
1055 sv_frame_t fill = model->getFillExtent();
1056
1057 #ifdef DEBUG_SPECTROGRAM_REPAINT
1058 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl;
1059 #endif
1060
1061 if (fill >= lastFill) {
1062 if (fill >= m_model->getEndFrame() && lastFill > 0) {
1063 #ifdef DEBUG_SPECTROGRAM_REPAINT
1064 cerr << "complete!" << endl;
1065 #endif
1066 invalidateImageCaches();
1067 i->second.second = -1;
1068 emit modelChanged();
1069
1070 } else if (fill > lastFill) {
1071 #ifdef DEBUG_SPECTROGRAM_REPAINT
1072 cerr << "SpectrogramLayer: emitting modelChanged("
1073 << lastFill << "," << fill << ")" << endl;
1074 #endif
1075 invalidateImageCaches(lastFill, fill);
1076 i->second.second = fill;
1077 emit modelChangedWithin(lastFill, fill);
1078 }
1079 } else {
1080 #ifdef DEBUG_SPECTROGRAM_REPAINT
1081 cerr << "SpectrogramLayer: going backwards, emitting modelChanged("
1082 << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << endl;
1083 #endif
1084 invalidateImageCaches();
1085 i->second.second = fill;
1086 emit modelChangedWithin(m_model->getStartFrame(), m_model->getEndFrame());
1087 }
1088
1089 if (i->second.second >= 0) {
1090 allDone = false;
1091 }
1092 }
1093 }
1094
1095 if (allDone) {
1096 #ifdef DEBUG_SPECTROGRAM_REPAINT
1097 cerr << "SpectrogramLayer: all complete!" << endl;
1098 #endif
1099 delete m_updateTimer;
1100 m_updateTimer = 0;
1101 }
1102 } 1030 }
1103 1031
1104 bool 1032 bool
1105 SpectrogramLayer::hasLightBackground() const 1033 SpectrogramLayer::hasLightBackground() const
1106 { 1034 {
1574 int fftSize = getFFTSize(v); 1502 int fftSize = getFFTSize(v);
1575 1503
1576 const View *view = v->getView(); 1504 const View *view = v->getView();
1577 1505
1578 if (m_fftModels.find(view) != m_fftModels.end()) { 1506 if (m_fftModels.find(view) != m_fftModels.end()) {
1579 if (m_fftModels[view].first == 0) { 1507 if (m_fftModels[view] == 0) {
1580 #ifdef DEBUG_SPECTROGRAM_REPAINT 1508 #ifdef DEBUG_SPECTROGRAM_REPAINT
1581 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; 1509 cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl;
1582 #endif 1510 #endif
1583 return 0; 1511 return 0;
1584 } 1512 }
1585 if (m_fftModels[view].first->getHeight() != fftSize / 2 + 1) { 1513 if (m_fftModels[view]->getHeight() != fftSize / 2 + 1) {
1586 #ifdef DEBUG_SPECTROGRAM_REPAINT 1514 #ifdef DEBUG_SPECTROGRAM_REPAINT
1587 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[view].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; 1515 cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[view].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl;
1588 #endif 1516 #endif
1589 delete m_fftModels[view].first; 1517 delete m_fftModels[view];
1590 m_fftModels.erase(view); 1518 m_fftModels.erase(view);
1591 delete m_peakCaches[view]; 1519 delete m_peakCaches[view];
1592 m_peakCaches.erase(view); 1520 m_peakCaches.erase(view);
1593 } else { 1521 } else {
1594 #ifdef DEBUG_SPECTROGRAM_REPAINT 1522 #ifdef DEBUG_SPECTROGRAM_REPAINT
1595 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[view].first->getHeight() << endl; 1523 cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[view]->getHeight() << endl;
1596 #endif 1524 #endif
1597 return m_fftModels[view].first; 1525 return m_fftModels[view];
1598 } 1526 }
1599 } 1527 }
1600 1528
1601 if (m_fftModels.find(view) == m_fftModels.end()) { 1529 if (m_fftModels.find(view) == m_fftModels.end()) {
1602 1530
1611 QMessageBox::critical 1539 QMessageBox::critical
1612 (0, tr("FFT cache failed"), 1540 (0, tr("FFT cache failed"),
1613 tr("Failed to create the FFT model for this spectrogram.\n" 1541 tr("Failed to create the FFT model for this spectrogram.\n"
1614 "There may be insufficient memory or disc space to continue.")); 1542 "There may be insufficient memory or disc space to continue."));
1615 delete model; 1543 delete model;
1616 m_fftModels[view] = FFTFillPair(0, 0); 1544 m_fftModels[view] = 0;
1617 return 0; 1545 return 0;
1618 } 1546 }
1619 1547
1620 if (!m_sliceableModel) { 1548 if (!m_sliceableModel) {
1621 #ifdef DEBUG_SPECTROGRAM 1549 #ifdef DEBUG_SPECTROGRAM
1623 #endif 1551 #endif
1624 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model); 1552 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model);
1625 m_sliceableModel = model; 1553 m_sliceableModel = model;
1626 } 1554 }
1627 1555
1628 m_fftModels[view] = FFTFillPair(model, 0); 1556 m_fftModels[view] = model;
1629 1557 }
1630 delete m_updateTimer; 1558
1631 m_updateTimer = new QTimer((SpectrogramLayer *)this); 1559 return m_fftModels[view];
1632 connect(m_updateTimer, SIGNAL(timeout()),
1633 this, SLOT(fillTimerTimedOut()));
1634 m_updateTimer->start(200);
1635 }
1636
1637 return m_fftModels[view].first;
1638 } 1560 }
1639 1561
1640 Dense3DModelPeakCache * 1562 Dense3DModelPeakCache *
1641 SpectrogramLayer::getPeakCache(const LayerGeometryProvider *v) const 1563 SpectrogramLayer::getPeakCache(const LayerGeometryProvider *v) const
1642 { 1564 {
1652 const Model * 1574 const Model *
1653 SpectrogramLayer::getSliceableModel() const 1575 SpectrogramLayer::getSliceableModel() const
1654 { 1576 {
1655 if (m_sliceableModel) return m_sliceableModel; 1577 if (m_sliceableModel) return m_sliceableModel;
1656 if (m_fftModels.empty()) return 0; 1578 if (m_fftModels.empty()) return 0;
1657 m_sliceableModel = m_fftModels.begin()->second.first; 1579 m_sliceableModel = m_fftModels.begin()->second;
1658 return m_sliceableModel; 1580 return m_sliceableModel;
1659 } 1581 }
1660 1582
1661 void 1583 void
1662 SpectrogramLayer::invalidateFFTModels() 1584 SpectrogramLayer::invalidateFFTModels()
1663 { 1585 {
1664 for (ViewFFTMap::iterator i = m_fftModels.begin(); 1586 for (ViewFFTMap::iterator i = m_fftModels.begin();
1665 i != m_fftModels.end(); ++i) { 1587 i != m_fftModels.end(); ++i) {
1666 delete i->second.first; 1588 delete i->second;
1667 } 1589 }
1668 for (PeakCacheMap::iterator i = m_peakCaches.begin(); 1590 for (PeakCacheMap::iterator i = m_peakCaches.begin();
1669 i != m_peakCaches.end(); ++i) { 1591 i != m_peakCaches.end(); ++i) {
1670 delete i->second; 1592 delete i->second;
1671 } 1593 }
1720 mag.sample(m_columnMags[s]); 1642 mag.sample(m_columnMags[s]);
1721 } 1643 }
1722 } 1644 }
1723 1645
1724 #ifdef DEBUG_SPECTROGRAM_REPAINT 1646 #ifdef DEBUG_SPECTROGRAM_REPAINT
1725 SVDEBUG << "SpectrogramLayer::updateViewMagnitudes returning from cols " 1647 cerr << "SpectrogramLayer::updateViewMagnitudes returning from cols "
1726 << s0 << " -> " << s1 << " inclusive" << endl; 1648 << s0 << " -> " << s1 << " inclusive" << endl;
1727 #endif 1649 #endif
1728 1650
1729 if (!mag.isSet()) return false; 1651 if (!mag.isSet()) return false;
1730 if (mag == m_viewMags[v]) return false; 1652 if (mag == m_viewMags[v]) return false;
1745 // It's practically FORTRAN 77 in its clarity and linearity. 1667 // It's practically FORTRAN 77 in its clarity and linearity.
1746 1668
1747 Profiler profiler("SpectrogramLayer::paint", false); 1669 Profiler profiler("SpectrogramLayer::paint", false);
1748 1670
1749 #ifdef DEBUG_SPECTROGRAM_REPAINT 1671 #ifdef DEBUG_SPECTROGRAM_REPAINT
1750 SVDEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl; 1672 cerr << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << endl;
1751 1673
1752 cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl; 1674 cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
1753 #endif 1675 #endif
1754 1676
1755 sv_frame_t startFrame = v->getStartFrame(); 1677 sv_frame_t startFrame = v->getStartFrame();
1756 if (startFrame < 0) m_candidateFillStartFrame = 0;
1757 else m_candidateFillStartFrame = startFrame;
1758 1678
1759 if (!m_model || !m_model->isOK() || !m_model->isReady()) { 1679 if (!m_model || !m_model->isOK() || !m_model->isReady()) {
1760 return; 1680 return;
1761 } 1681 }
1762 1682
1783 const View *view = v->getView(); 1703 const View *view = v->getView();
1784 1704
1785 ImageCache &cache = m_imageCaches[view]; 1705 ImageCache &cache = m_imageCaches[view];
1786 1706
1787 #ifdef DEBUG_SPECTROGRAM_REPAINT 1707 #ifdef DEBUG_SPECTROGRAM_REPAINT
1788 SVDEBUG << "SpectrogramLayer::paint(): image cache valid area " << cache. 1708 cerr << "SpectrogramLayer::paint(): image cache valid area " << cache.
1789 1709
1790 validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl; 1710 validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl;
1791 #endif
1792
1793 #ifdef DEBUG_SPECTROGRAM_REPAINT
1794 bool stillCacheing = (m_updateTimer != 0);
1795 SVDEBUG << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << endl;
1796 #endif 1711 #endif
1797 1712
1798 int zoomLevel = v->getZoomLevel(); 1713 int zoomLevel = v->getZoomLevel();
1799 1714
1800 int x0 = 0; 1715 int x0 = 0;
2147 2062
2148 if (w == 0) { 2063 if (w == 0) {
2149 SVDEBUG << "*** NOTE: w == 0" << endl; 2064 SVDEBUG << "*** NOTE: w == 0" << endl;
2150 } 2065 }
2151 2066
2152 #ifdef DEBUG_SPECTROGRAM_REPAINT
2153 int pixels = 0;
2154 #endif
2155
2156 Profiler outerprof("SpectrogramLayer::paint: all cols"); 2067 Profiler outerprof("SpectrogramLayer::paint: all cols");
2157 2068
2158 // The draw buffer contains a fragment at either our pixel 2069 // The draw buffer contains a fragment at either our pixel
2159 // resolution (if there is more than one time-bin per pixel) or 2070 // resolution (if there is more than one time-bin per pixel) or
2160 // time-bin resolution (if a time-bin spans more than one pixel). 2071 // time-bin resolution (if a time-bin spans more than one pixel).
2301 2212
2302 Profiler profiler2("SpectrogramLayer::paint: draw image"); 2213 Profiler profiler2("SpectrogramLayer::paint: draw image");
2303 2214
2304 if (recreateWholeImageCache) { 2215 if (recreateWholeImageCache) {
2305 #ifdef DEBUG_SPECTROGRAM_REPAINT 2216 #ifdef DEBUG_SPECTROGRAM_REPAINT
2306 SVDEBUG << "Recreating image cache: width = " << v->getPaintWidth() 2217 cerr << "Recreating image cache: width = " << v->getPaintWidth()
2307 << ", height = " << h << endl; 2218 << ", height = " << h << endl;
2308 #endif 2219 #endif
2309 cache.image = QImage(v->getPaintWidth(), h, QImage::Format_ARGB32_Premultiplied); 2220 cache.image = QImage(v->getPaintWidth(), h, QImage::Format_ARGB32_Premultiplied);
2310 } 2221 }
2311 2222
2312 if (w > 0) { 2223 if (w > 0) {
2313 #ifdef DEBUG_SPECTROGRAM_REPAINT 2224 #ifdef DEBUG_SPECTROGRAM_REPAINT
2314 SVDEBUG << "Painting " << w << "x" << h 2225 cerr << "Painting " << w << "x" << h
2315 << " from draw buffer at " << 0 << "," << 0 2226 << " from draw buffer at " << 0 << "," << 0
2316 << " to " << w << "x" << h << " on cache at " 2227 << " to " << w << "x" << h << " on cache at "
2317 << x0 << "," << 0 << endl; 2228 << x0 << "," << 0 << endl;
2318 #endif 2229 #endif
2319 2230
2321 2232
2322 if (bufferBinResolution) { 2233 if (bufferBinResolution) {
2323 int scaledLeft = v->getXForFrame(leftBoundaryFrame); 2234 int scaledLeft = v->getXForFrame(leftBoundaryFrame);
2324 int scaledRight = v->getXForFrame(rightBoundaryFrame); 2235 int scaledRight = v->getXForFrame(rightBoundaryFrame);
2325 #ifdef DEBUG_SPECTROGRAM_REPAINT 2236 #ifdef DEBUG_SPECTROGRAM_REPAINT
2326 SVDEBUG << "Rescaling image from " << bufwid 2237 cerr << "Rescaling image from " << bufwid
2327 << "x" << h << " to " 2238 << "x" << h << " to "
2328 << scaledRight-scaledLeft << "x" << h << endl; 2239 << scaledRight-scaledLeft << "x" << h << endl;
2329 #endif 2240 #endif
2330 Preferences::SpectrogramXSmoothing xsmoothing = 2241 Preferences::SpectrogramXSmoothing xsmoothing =
2331 Preferences::getInstance()->getSpectrogramXSmoothing(); 2242 Preferences::getInstance()->getSpectrogramXSmoothing();
2336 ((xsmoothing == Preferences::SpectrogramXInterpolated) ? 2247 ((xsmoothing == Preferences::SpectrogramXInterpolated) ?
2337 Qt::SmoothTransformation : Qt::FastTransformation)); 2248 Qt::SmoothTransformation : Qt::FastTransformation));
2338 int scaledLeftCrop = v->getXForFrame(leftCropFrame); 2249 int scaledLeftCrop = v->getXForFrame(leftCropFrame);
2339 int scaledRightCrop = v->getXForFrame(rightCropFrame); 2250 int scaledRightCrop = v->getXForFrame(rightCropFrame);
2340 #ifdef DEBUG_SPECTROGRAM_REPAINT 2251 #ifdef DEBUG_SPECTROGRAM_REPAINT
2341 SVDEBUG << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " 2252 cerr << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to "
2342 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; 2253 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl;
2343 #endif 2254 #endif
2344 cachePainter.drawImage 2255 cachePainter.drawImage
2345 (QRect(scaledLeftCrop, 0, 2256 (QRect(scaledLeftCrop, 0,
2346 scaledRightCrop - scaledLeftCrop, h), 2257 scaledRightCrop - scaledLeftCrop, h),
2357 } 2268 }
2358 2269
2359 QRect pr = rect & cache.validArea; 2270 QRect pr = rect & cache.validArea;
2360 2271
2361 #ifdef DEBUG_SPECTROGRAM_REPAINT 2272 #ifdef DEBUG_SPECTROGRAM_REPAINT
2362 SVDEBUG << "Painting " << pr.width() << "x" << pr.height() 2273 cerr << "Painting " << pr.width() << "x" << pr.height()
2363 << " from cache at " << pr.x() << "," << pr.y() 2274 << " from cache at " << pr.x() << "," << pr.y()
2364 << " to window" << endl; 2275 << " to window" << endl;
2365 #endif 2276 #endif
2366 2277
2367 paint.drawImage(pr.x(), pr.y(), cache.image, 2278 paint.drawImage(pr.x(), pr.y(), cache.image,
2377 2288
2378 if ((m_normalization != NormalizeVisibleArea) || !overallMagChanged) { 2289 if ((m_normalization != NormalizeVisibleArea) || !overallMagChanged) {
2379 2290
2380 if (cache.validArea.x() > 0) { 2291 if (cache.validArea.x() > 0) {
2381 #ifdef DEBUG_SPECTROGRAM_REPAINT 2292 #ifdef DEBUG_SPECTROGRAM_REPAINT
2382 SVDEBUG << "SpectrogramLayer::paint() updating left (0, " 2293 cerr << "SpectrogramLayer::paint() updating left (0, "
2383 << cache.validArea.x() << ")" << endl; 2294 << cache.validArea.x() << ")" << endl;
2384 #endif 2295 #endif
2385 v->getView()->update(0, 0, cache.validArea.x(), h); 2296 v->getView()->update(0, 0, cache.validArea.x(), h);
2386 } 2297 }
2387 2298
2388 if (cache.validArea.x() + cache.validArea.width() < 2299 if (cache.validArea.x() + cache.validArea.width() <
2389 cache.image.width()) { 2300 cache.image.width()) {
2390 #ifdef DEBUG_SPECTROGRAM_REPAINT 2301 #ifdef DEBUG_SPECTROGRAM_REPAINT
2391 SVDEBUG << "SpectrogramLayer::paint() updating right (" 2302 cerr << "SpectrogramLayer::paint() updating right ("
2392 << cache.validArea.x() + cache.validArea.width() 2303 << cache.validArea.x() + cache.validArea.width()
2393 << ", " 2304 << ", "
2394 << cache.image.width() - (cache.validArea.x() + 2305 << cache.image.width() - (cache.validArea.x() +
2395 cache.validArea.width()) 2306 cache.validArea.width())
2396 << ")" << endl; 2307 << ")" << endl;
2410 } 2321 }
2411 2322
2412 illuminateLocalFeatures(v, paint); 2323 illuminateLocalFeatures(v, paint);
2413 2324
2414 #ifdef DEBUG_SPECTROGRAM_REPAINT 2325 #ifdef DEBUG_SPECTROGRAM_REPAINT
2415 SVDEBUG << "SpectrogramLayer::paint() returning" << endl; 2326 cerr << "SpectrogramLayer::paint() returning" << endl;
2416 #endif 2327 #endif
2417 2328
2418 if (!m_synchronous) { 2329 if (!m_synchronous) {
2419 m_lastPaintBlockWidth = paintBlockWidth; 2330 m_lastPaintBlockWidth = paintBlockWidth;
2420 (void)gettimeofday(&tv, 0); 2331 (void)gettimeofday(&tv, 0);
2648 MagnitudeRange mag; 2559 MagnitudeRange mag;
2649 2560
2650 if (sx != psx) { 2561 if (sx != psx) {
2651 if (fft) { 2562 if (fft) {
2652 #ifdef DEBUG_SPECTROGRAM_REPAINT 2563 #ifdef DEBUG_SPECTROGRAM_REPAINT
2653 SVDEBUG << "Retrieving column " << sx << " from fft directly" << endl; 2564 cerr << "Retrieving column " << sx << " from fft directly" << endl;
2654 #endif 2565 #endif
2655 if (m_colourScale == PhaseColourScale) { 2566 if (m_colourScale == PhaseColourScale) {
2656 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2567 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2657 } else if (m_normalization == NormalizeColumns) { 2568 } else if (m_normalization == NormalizeColumns) {
2658 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2569 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2659 } else if (m_normalization == NormalizeHybrid) { 2570 } else if (m_normalization == NormalizeHybrid) {
2660 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2571 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2661 double max = fft->getMaximumMagnitudeAt(sx); 2572 float max = fft->getMaximumMagnitudeAt(sx);
2662 float scale = log10(max + 1.f); 2573 float scale = log10f(max + 1.f);
2663 cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl; 2574 cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl;
2664 for (int i = minbin; i <= maxbin; ++i) { 2575 for (int i = minbin; i <= maxbin; ++i) {
2665 autoarray[i - minbin] *= scale; 2576 autoarray[i - minbin] *= scale;
2666 } 2577 }
2667 } else { 2578 } else {
2668 fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2579 fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2669 } 2580 }
2670 } else { 2581 } else {
2671 #ifdef DEBUG_SPECTROGRAM_REPAINT 2582 #ifdef DEBUG_SPECTROGRAM_REPAINT
2672 SVDEBUG << "Retrieving column " << sx << " from peaks cache" << endl; 2583 cerr << "Retrieving column " << sx << " from peaks cache" << endl;
2673 #endif 2584 #endif
2674 c = sourceModel->getColumn(sx); 2585 c = sourceModel->getColumn(sx);
2675 if (m_normalization == NormalizeColumns || 2586 if (m_normalization == NormalizeColumns ||
2676 m_normalization == NormalizeHybrid) { 2587 m_normalization == NormalizeHybrid) {
2677 for (int y = 0; y < h; ++y) { 2588 for (int y = 0; y < h; ++y) {
2853 } 2764 }
2854 2765
2855 int 2766 int
2856 SpectrogramLayer::getCompletion(LayerGeometryProvider *v) const 2767 SpectrogramLayer::getCompletion(LayerGeometryProvider *v) const
2857 { 2768 {
2858 if (m_updateTimer == 0) return 100;
2859
2860 const View *view = v->getView(); 2769 const View *view = v->getView();
2861 2770
2862 if (m_fftModels.find(view) == m_fftModels.end()) return 100; 2771 if (m_fftModels.find(view) == m_fftModels.end()) return 100;
2863 2772
2864 int completion = m_fftModels[view].first->getCompletion(); 2773 int completion = m_fftModels[view]->getCompletion();
2865 #ifdef DEBUG_SPECTROGRAM_REPAINT 2774 #ifdef DEBUG_SPECTROGRAM_REPAINT
2866 SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; 2775 cerr << "SpectrogramLayer::getCompletion: completion = " << completion << endl;
2867 #endif 2776 #endif
2868 return completion; 2777 return completion;
2869 } 2778 }
2870 2779
2871 QString 2780 QString
2872 SpectrogramLayer::getError(LayerGeometryProvider *v) const 2781 SpectrogramLayer::getError(LayerGeometryProvider *v) const
2873 { 2782 {
2874 const View *view = v->getView(); 2783 const View *view = v->getView();
2875 if (m_fftModels.find(view) == m_fftModels.end()) return ""; 2784 if (m_fftModels.find(view) == m_fftModels.end()) return "";
2876 return m_fftModels[view].first->getError(); 2785 return m_fftModels[view]->getError();
2877 } 2786 }
2878 2787
2879 bool 2788 bool
2880 SpectrogramLayer::getValueExtents(double &min, double &max, 2789 SpectrogramLayer::getValueExtents(double &min, double &max,
2881 bool &logarithmic, QString &unit) const 2790 bool &logarithmic, QString &unit) const