comparison layer/SpectrogramLayer.cpp @ 985:8053c0dfa919 simple-fft-model

Fill extent is not relevant in simple-fft-model code, as it's always the full extent
author Chris Cannam
date Wed, 01 Jul 2015 11:32:18 +0100
parents b8187c83b93a
children aef8f6fff278
comparison
equal deleted inserted replaced
975:b8187c83b93a 985:8053c0dfa919
46 46
47 #ifndef __GNUC__ 47 #ifndef __GNUC__
48 #include <alloca.h> 48 #include <alloca.h>
49 #endif 49 #endif
50 50
51 //#define DEBUG_SPECTROGRAM_REPAINT 1 51 #define DEBUG_SPECTROGRAM_REPAINT 1
52 52
53 using std::vector; 53 using std::vector;
54 54
55 SpectrogramLayer::SpectrogramLayer(Configuration config) : 55 SpectrogramLayer::SpectrogramLayer(Configuration config) :
56 m_model(0), 56 m_model(0),
78 m_normalizeHybrid(false), 78 m_normalizeHybrid(false),
79 m_lastEmittedZoomStep(-1), 79 m_lastEmittedZoomStep(-1),
80 m_synchronous(false), 80 m_synchronous(false),
81 m_haveDetailedScale(false), 81 m_haveDetailedScale(false),
82 m_lastPaintBlockWidth(0), 82 m_lastPaintBlockWidth(0),
83 m_updateTimer(0),
84 m_candidateFillStartFrame(0),
85 m_exiting(false), 83 m_exiting(false),
86 m_sliceableModel(0) 84 m_sliceableModel(0)
87 { 85 {
88 if (config == FullRangeDb) { 86 if (config == FullRangeDb) {
89 m_initialMaxFrequency = 0; 87 m_initialMaxFrequency = 0;
118 initialisePalette(); 116 initialisePalette();
119 } 117 }
120 118
121 SpectrogramLayer::~SpectrogramLayer() 119 SpectrogramLayer::~SpectrogramLayer()
122 { 120 {
123 delete m_updateTimer;
124 m_updateTimer = 0;
125
126 invalidateFFTModels(); 121 invalidateFFTModels();
127 } 122 }
128 123
129 void 124 void
130 SpectrogramLayer::setModel(const DenseTimeValueModel *model) 125 SpectrogramLayer::setModel(const DenseTimeValueModel *model)
579 574
580 //!!! when are views removed from the map? on setLayerDormant? 575 //!!! when are views removed from the map? on setLayerDormant?
581 const View *v = i->first; 576 const View *v = i->first;
582 577
583 #ifdef DEBUG_SPECTROGRAM_REPAINT 578 #ifdef DEBUG_SPECTROGRAM_REPAINT
584 SVDEBUG << "SpectrogramLayer::invalidateImageCaches(" 579 cerr << "SpectrogramLayer::invalidateImageCaches("
585 << startFrame << ", " << endFrame << "): view range is " 580 << startFrame << ", " << endFrame << "): view range is "
586 << v->getStartFrame() << ", " << v->getEndFrame() 581 << v->getStartFrame() << ", " << v->getEndFrame()
587 << endl; 582 << endl;
588 583
589 cerr << "Valid area was: " << i->second.validArea.x() << ", " 584 cerr << "Valid area was: " << i->second.validArea.x() << ", "
599 #endif 594 #endif
600 return; 595 return;
601 } 596 }
602 int x = v->getXForFrame(startFrame); 597 int x = v->getXForFrame(startFrame);
603 #ifdef DEBUG_SPECTROGRAM_REPAINT 598 #ifdef DEBUG_SPECTROGRAM_REPAINT
604 SVDEBUG << "clipping from 0 to " << x-1 << endl; 599 cerr << "clipping from 0 to " << x-1 << endl;
605 #endif 600 #endif
606 if (x > 1) { 601 if (x > 1) {
607 i->second.validArea &= 602 i->second.validArea &=
608 QRect(0, 0, x-1, v->height()); 603 QRect(0, 0, x-1, v->height());
609 } else { 604 } else {
616 #endif 611 #endif
617 return; 612 return;
618 } 613 }
619 int x = v->getXForFrame(endFrame); 614 int x = v->getXForFrame(endFrame);
620 #ifdef DEBUG_SPECTROGRAM_REPAINT 615 #ifdef DEBUG_SPECTROGRAM_REPAINT
621 SVDEBUG << "clipping from " << x+1 << " to " << v->width() 616 cerr << "clipping from " << x+1 << " to " << v->width()
622 << endl; 617 << endl;
623 #endif 618 #endif
624 if (x < v->width()) { 619 if (x < v->width()) {
625 i->second.validArea &= 620 i->second.validArea &=
626 QRect(x+1, 0, v->width()-(x+1), v->height()); 621 QRect(x+1, 0, v->width()-(x+1), v->height());
994 SpectrogramLayer::setLayerDormant(const View *v, bool dormant) 989 SpectrogramLayer::setLayerDormant(const View *v, bool dormant)
995 { 990 {
996 if (dormant) { 991 if (dormant) {
997 992
998 #ifdef DEBUG_SPECTROGRAM_REPAINT 993 #ifdef DEBUG_SPECTROGRAM_REPAINT
999 SVDEBUG << "SpectrogramLayer::setLayerDormant(" << dormant << ")" 994 cerr << "SpectrogramLayer::setLayerDormant(" << dormant << ")"
1000 << endl; 995 << endl;
1001 #endif 996 #endif
1002 997
1003 if (isLayerDormant(v)) { 998 if (isLayerDormant(v)) {
1004 return; 999 return;
1009 invalidateImageCaches(); 1004 invalidateImageCaches();
1010 m_imageCaches.erase(v); 1005 m_imageCaches.erase(v);
1011 1006
1012 if (m_fftModels.find(v) != m_fftModels.end()) { 1007 if (m_fftModels.find(v) != m_fftModels.end()) {
1013 1008
1014 if (m_sliceableModel == m_fftModels[v].first) { 1009 if (m_sliceableModel == m_fftModels[v]) {
1015 bool replaced = false; 1010 bool replaced = false;
1016 for (ViewFFTMap::iterator i = m_fftModels.begin(); 1011 for (ViewFFTMap::iterator i = m_fftModels.begin();
1017 i != m_fftModels.end(); ++i) { 1012 i != m_fftModels.end(); ++i) {
1018 if (i->second.first != m_sliceableModel) { 1013 if (i->second != m_sliceableModel) {
1019 emit sliceableModelReplaced(m_sliceableModel, i->second.first); 1014 emit sliceableModelReplaced(m_sliceableModel, i->second);
1020 replaced = true; 1015 replaced = true;
1021 break; 1016 break;
1022 } 1017 }
1023 } 1018 }
1024 if (!replaced) emit sliceableModelReplaced(m_sliceableModel, 0); 1019 if (!replaced) emit sliceableModelReplaced(m_sliceableModel, 0);
1025 } 1020 }
1026 1021
1027 delete m_fftModels[v].first; 1022 delete m_fftModels[v];
1028 m_fftModels.erase(v); 1023 m_fftModels.erase(v);
1029 1024
1030 delete m_peakCaches[v]; 1025 delete m_peakCaches[v];
1031 m_peakCaches.erase(v); 1026 m_peakCaches.erase(v);
1032 } 1027 }
1039 1034
1040 void 1035 void
1041 SpectrogramLayer::cacheInvalid() 1036 SpectrogramLayer::cacheInvalid()
1042 { 1037 {
1043 #ifdef DEBUG_SPECTROGRAM_REPAINT 1038 #ifdef DEBUG_SPECTROGRAM_REPAINT
1044 SVDEBUG << "SpectrogramLayer::cacheInvalid()" << endl; 1039 cerr << "SpectrogramLayer::cacheInvalid()" << endl;
1045 #endif 1040 #endif
1046 1041
1047 invalidateImageCaches(); 1042 invalidateImageCaches();
1048 invalidateMagnitudes(); 1043 invalidateMagnitudes();
1049 } 1044 }
1050 1045
1051 void 1046 void
1052 SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to) 1047 SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to)
1053 { 1048 {
1054 #ifdef DEBUG_SPECTROGRAM_REPAINT 1049 #ifdef DEBUG_SPECTROGRAM_REPAINT
1055 SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; 1050 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl;
1056 #endif 1051 #endif
1057 1052
1058 invalidateImageCaches(from, to); 1053 invalidateImageCaches(from, to);
1059 invalidateMagnitudes(); 1054 invalidateMagnitudes();
1060 }
1061
1062 void
1063 SpectrogramLayer::fillTimerTimedOut()
1064 {
1065 if (!m_model) return;
1066
1067 bool allDone = true;
1068
1069 #ifdef DEBUG_SPECTROGRAM_REPAINT
1070 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: have " << m_fftModels.size() << " FFT models associated with views" << endl;
1071 #endif
1072
1073 for (ViewFFTMap::iterator i = m_fftModels.begin();
1074 i != m_fftModels.end(); ++i) {
1075
1076 const FFTModel *model = i->second.first;
1077 sv_frame_t lastFill = i->second.second;
1078
1079 if (model) {
1080
1081 sv_frame_t fill = model->getFillExtent();
1082
1083 #ifdef DEBUG_SPECTROGRAM_REPAINT
1084 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl;
1085 #endif
1086
1087 if (fill >= lastFill) {
1088 if (fill >= m_model->getEndFrame() && lastFill > 0) {
1089 #ifdef DEBUG_SPECTROGRAM_REPAINT
1090 cerr << "complete!" << endl;
1091 #endif
1092 invalidateImageCaches();
1093 i->second.second = -1;
1094 emit modelChanged();
1095
1096 } else if (fill > lastFill) {
1097 #ifdef DEBUG_SPECTROGRAM_REPAINT
1098 cerr << "SpectrogramLayer: emitting modelChanged("
1099 << lastFill << "," << fill << ")" << endl;
1100 #endif
1101 invalidateImageCaches(lastFill, fill);
1102 i->second.second = fill;
1103 emit modelChangedWithin(lastFill, fill);
1104 }
1105 } else {
1106 #ifdef DEBUG_SPECTROGRAM_REPAINT
1107 cerr << "SpectrogramLayer: going backwards, emitting modelChanged("
1108 << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << endl;
1109 #endif
1110 invalidateImageCaches();
1111 i->second.second = fill;
1112 emit modelChangedWithin(m_model->getStartFrame(), m_model->getEndFrame());
1113 }
1114
1115 if (i->second.second >= 0) {
1116 allDone = false;
1117 }
1118 }
1119 }
1120
1121 if (allDone) {
1122 #ifdef DEBUG_SPECTROGRAM_REPAINT
1123 cerr << "SpectrogramLayer: all complete!" << endl;
1124 #endif
1125 delete m_updateTimer;
1126 m_updateTimer = 0;
1127 }
1128 } 1055 }
1129 1056
1130 bool 1057 bool
1131 SpectrogramLayer::hasLightBackground() const 1058 SpectrogramLayer::hasLightBackground() const
1132 { 1059 {
1598 if (!m_model) return 0; 1525 if (!m_model) return 0;
1599 1526
1600 int fftSize = getFFTSize(v); 1527 int fftSize = getFFTSize(v);
1601 1528
1602 if (m_fftModels.find(v) != m_fftModels.end()) { 1529 if (m_fftModels.find(v) != m_fftModels.end()) {
1603 if (m_fftModels[v].first == 0) { 1530 if (m_fftModels[v] == 0) {
1604 #ifdef DEBUG_SPECTROGRAM_REPAINT 1531 #ifdef DEBUG_SPECTROGRAM_REPAINT
1605 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; 1532 cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl;
1606 #endif 1533 #endif
1607 return 0; 1534 return 0;
1608 } 1535 }
1609 if (m_fftModels[v].first->getHeight() != fftSize / 2 + 1) { 1536 if (m_fftModels[v]->getHeight() != fftSize / 2 + 1) {
1610 #ifdef DEBUG_SPECTROGRAM_REPAINT 1537 #ifdef DEBUG_SPECTROGRAM_REPAINT
1611 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; 1538 cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v]->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl;
1612 #endif 1539 #endif
1613 delete m_fftModels[v].first; 1540 delete m_fftModels[v];
1614 m_fftModels.erase(v); 1541 m_fftModels.erase(v);
1615 delete m_peakCaches[v]; 1542 delete m_peakCaches[v];
1616 m_peakCaches.erase(v); 1543 m_peakCaches.erase(v);
1617 } else { 1544 } else {
1618 #ifdef DEBUG_SPECTROGRAM_REPAINT 1545 #ifdef DEBUG_SPECTROGRAM_REPAINT
1619 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v].first->getHeight() << endl; 1546 cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v]->getHeight() << endl;
1620 #endif 1547 #endif
1621 return m_fftModels[v].first; 1548 return m_fftModels[v];
1622 } 1549 }
1623 } 1550 }
1624 1551
1625 if (m_fftModels.find(v) == m_fftModels.end()) { 1552 if (m_fftModels.find(v) == m_fftModels.end()) {
1626 1553
1635 QMessageBox::critical 1562 QMessageBox::critical
1636 (0, tr("FFT cache failed"), 1563 (0, tr("FFT cache failed"),
1637 tr("Failed to create the FFT model for this spectrogram.\n" 1564 tr("Failed to create the FFT model for this spectrogram.\n"
1638 "There may be insufficient memory or disc space to continue.")); 1565 "There may be insufficient memory or disc space to continue."));
1639 delete model; 1566 delete model;
1640 m_fftModels[v] = FFTFillPair(0, 0); 1567 m_fftModels[v] = 0;
1641 return 0; 1568 return 0;
1642 } 1569 }
1643 1570
1644 if (!m_sliceableModel) { 1571 if (!m_sliceableModel) {
1645 #ifdef DEBUG_SPECTROGRAM 1572 #ifdef DEBUG_SPECTROGRAM
1647 #endif 1574 #endif
1648 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model); 1575 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model);
1649 m_sliceableModel = model; 1576 m_sliceableModel = model;
1650 } 1577 }
1651 1578
1652 m_fftModels[v] = FFTFillPair(model, 0); 1579 m_fftModels[v] = model;
1653 1580 }
1654 delete m_updateTimer; 1581
1655 m_updateTimer = new QTimer((SpectrogramLayer *)this); 1582 return m_fftModels[v];
1656 connect(m_updateTimer, SIGNAL(timeout()),
1657 this, SLOT(fillTimerTimedOut()));
1658 m_updateTimer->start(200);
1659 }
1660
1661 return m_fftModels[v].first;
1662 } 1583 }
1663 1584
1664 Dense3DModelPeakCache * 1585 Dense3DModelPeakCache *
1665 SpectrogramLayer::getPeakCache(const View *v) const 1586 SpectrogramLayer::getPeakCache(const View *v) const
1666 { 1587 {
1675 const Model * 1596 const Model *
1676 SpectrogramLayer::getSliceableModel() const 1597 SpectrogramLayer::getSliceableModel() const
1677 { 1598 {
1678 if (m_sliceableModel) return m_sliceableModel; 1599 if (m_sliceableModel) return m_sliceableModel;
1679 if (m_fftModels.empty()) return 0; 1600 if (m_fftModels.empty()) return 0;
1680 m_sliceableModel = m_fftModels.begin()->second.first; 1601 m_sliceableModel = m_fftModels.begin()->second;
1681 return m_sliceableModel; 1602 return m_sliceableModel;
1682 } 1603 }
1683 1604
1684 void 1605 void
1685 SpectrogramLayer::invalidateFFTModels() 1606 SpectrogramLayer::invalidateFFTModels()
1686 { 1607 {
1687 for (ViewFFTMap::iterator i = m_fftModels.begin(); 1608 for (ViewFFTMap::iterator i = m_fftModels.begin();
1688 i != m_fftModels.end(); ++i) { 1609 i != m_fftModels.end(); ++i) {
1689 delete i->second.first; 1610 delete i->second;
1690 } 1611 }
1691 for (PeakCacheMap::iterator i = m_peakCaches.begin(); 1612 for (PeakCacheMap::iterator i = m_peakCaches.begin();
1692 i != m_peakCaches.end(); ++i) { 1613 i != m_peakCaches.end(); ++i) {
1693 delete i->second; 1614 delete i->second;
1694 } 1615 }
1743 mag.sample(m_columnMags[s]); 1664 mag.sample(m_columnMags[s]);
1744 } 1665 }
1745 } 1666 }
1746 1667
1747 #ifdef DEBUG_SPECTROGRAM_REPAINT 1668 #ifdef DEBUG_SPECTROGRAM_REPAINT
1748 SVDEBUG << "SpectrogramLayer::updateViewMagnitudes returning from cols " 1669 cerr << "SpectrogramLayer::updateViewMagnitudes returning from cols "
1749 << s0 << " -> " << s1 << " inclusive" << endl; 1670 << s0 << " -> " << s1 << " inclusive" << endl;
1750 #endif 1671 #endif
1751 1672
1752 if (!mag.isSet()) return false; 1673 if (!mag.isSet()) return false;
1753 if (mag == m_viewMags[v]) return false; 1674 if (mag == m_viewMags[v]) return false;
1768 // It's practically FORTRAN 77 in its clarity and linearity. 1689 // It's practically FORTRAN 77 in its clarity and linearity.
1769 1690
1770 Profiler profiler("SpectrogramLayer::paint", false); 1691 Profiler profiler("SpectrogramLayer::paint", false);
1771 1692
1772 #ifdef DEBUG_SPECTROGRAM_REPAINT 1693 #ifdef DEBUG_SPECTROGRAM_REPAINT
1773 SVDEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl; 1694 cerr << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << endl;
1774 1695
1775 cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl; 1696 cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
1776 #endif 1697 #endif
1777 1698
1778 sv_frame_t startFrame = v->getStartFrame(); 1699 sv_frame_t startFrame = v->getStartFrame();
1779 if (startFrame < 0) m_candidateFillStartFrame = 0;
1780 else m_candidateFillStartFrame = startFrame;
1781 1700
1782 if (!m_model || !m_model->isOK() || !m_model->isReady()) { 1701 if (!m_model || !m_model->isOK() || !m_model->isReady()) {
1783 return; 1702 return;
1784 } 1703 }
1785 1704
1803 } 1722 }
1804 */ 1723 */
1805 ImageCache &cache = m_imageCaches[v]; 1724 ImageCache &cache = m_imageCaches[v];
1806 1725
1807 #ifdef DEBUG_SPECTROGRAM_REPAINT 1726 #ifdef DEBUG_SPECTROGRAM_REPAINT
1808 SVDEBUG << "SpectrogramLayer::paint(): image cache valid area " << cache. 1727 cerr << "SpectrogramLayer::paint(): image cache valid area " << cache.
1809 1728
1810 validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl; 1729 validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl;
1811 #endif
1812
1813 #ifdef DEBUG_SPECTROGRAM_REPAINT
1814 bool stillCacheing = (m_updateTimer != 0);
1815 SVDEBUG << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << endl;
1816 #endif 1730 #endif
1817 1731
1818 int zoomLevel = v->getZoomLevel(); 1732 int zoomLevel = v->getZoomLevel();
1819 1733
1820 int x0 = 0; 1734 int x0 = 0;
2167 2081
2168 if (w == 0) { 2082 if (w == 0) {
2169 SVDEBUG << "*** NOTE: w == 0" << endl; 2083 SVDEBUG << "*** NOTE: w == 0" << endl;
2170 } 2084 }
2171 2085
2172 #ifdef DEBUG_SPECTROGRAM_REPAINT
2173 int pixels = 0;
2174 #endif
2175
2176 Profiler outerprof("SpectrogramLayer::paint: all cols"); 2086 Profiler outerprof("SpectrogramLayer::paint: all cols");
2177 2087
2178 // The draw buffer contains a fragment at either our pixel 2088 // The draw buffer contains a fragment at either our pixel
2179 // resolution (if there is more than one time-bin per pixel) or 2089 // resolution (if there is more than one time-bin per pixel) or
2180 // time-bin resolution (if a time-bin spans more than one pixel). 2090 // time-bin resolution (if a time-bin spans more than one pixel).
2321 2231
2322 Profiler profiler2("SpectrogramLayer::paint: draw image"); 2232 Profiler profiler2("SpectrogramLayer::paint: draw image");
2323 2233
2324 if (recreateWholeImageCache) { 2234 if (recreateWholeImageCache) {
2325 #ifdef DEBUG_SPECTROGRAM_REPAINT 2235 #ifdef DEBUG_SPECTROGRAM_REPAINT
2326 SVDEBUG << "Recreating image cache: width = " << v->width() 2236 cerr << "Recreating image cache: width = " << v->width()
2327 << ", height = " << h << endl; 2237 << ", height = " << h << endl;
2328 #endif 2238 #endif
2329 cache.image = QImage(v->width(), h, QImage::Format_ARGB32_Premultiplied); 2239 cache.image = QImage(v->width(), h, QImage::Format_ARGB32_Premultiplied);
2330 } 2240 }
2331 2241
2332 if (w > 0) { 2242 if (w > 0) {
2333 #ifdef DEBUG_SPECTROGRAM_REPAINT 2243 #ifdef DEBUG_SPECTROGRAM_REPAINT
2334 SVDEBUG << "Painting " << w << "x" << h 2244 cerr << "Painting " << w << "x" << h
2335 << " from draw buffer at " << 0 << "," << 0 2245 << " from draw buffer at " << 0 << "," << 0
2336 << " to " << w << "x" << h << " on cache at " 2246 << " to " << w << "x" << h << " on cache at "
2337 << x0 << "," << 0 << endl; 2247 << x0 << "," << 0 << endl;
2338 #endif 2248 #endif
2339 2249
2341 2251
2342 if (bufferBinResolution) { 2252 if (bufferBinResolution) {
2343 int scaledLeft = v->getXForFrame(leftBoundaryFrame); 2253 int scaledLeft = v->getXForFrame(leftBoundaryFrame);
2344 int scaledRight = v->getXForFrame(rightBoundaryFrame); 2254 int scaledRight = v->getXForFrame(rightBoundaryFrame);
2345 #ifdef DEBUG_SPECTROGRAM_REPAINT 2255 #ifdef DEBUG_SPECTROGRAM_REPAINT
2346 SVDEBUG << "Rescaling image from " << bufwid 2256 cerr << "Rescaling image from " << bufwid
2347 << "x" << h << " to " 2257 << "x" << h << " to "
2348 << scaledRight-scaledLeft << "x" << h << endl; 2258 << scaledRight-scaledLeft << "x" << h << endl;
2349 #endif 2259 #endif
2350 Preferences::SpectrogramXSmoothing xsmoothing = 2260 Preferences::SpectrogramXSmoothing xsmoothing =
2351 Preferences::getInstance()->getSpectrogramXSmoothing(); 2261 Preferences::getInstance()->getSpectrogramXSmoothing();
2356 ((xsmoothing == Preferences::SpectrogramXInterpolated) ? 2266 ((xsmoothing == Preferences::SpectrogramXInterpolated) ?
2357 Qt::SmoothTransformation : Qt::FastTransformation)); 2267 Qt::SmoothTransformation : Qt::FastTransformation));
2358 int scaledLeftCrop = v->getXForFrame(leftCropFrame); 2268 int scaledLeftCrop = v->getXForFrame(leftCropFrame);
2359 int scaledRightCrop = v->getXForFrame(rightCropFrame); 2269 int scaledRightCrop = v->getXForFrame(rightCropFrame);
2360 #ifdef DEBUG_SPECTROGRAM_REPAINT 2270 #ifdef DEBUG_SPECTROGRAM_REPAINT
2361 SVDEBUG << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " 2271 cerr << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to "
2362 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; 2272 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl;
2363 #endif 2273 #endif
2364 cachePainter.drawImage 2274 cachePainter.drawImage
2365 (QRect(scaledLeftCrop, 0, 2275 (QRect(scaledLeftCrop, 0,
2366 scaledRightCrop - scaledLeftCrop, h), 2276 scaledRightCrop - scaledLeftCrop, h),
2377 } 2287 }
2378 2288
2379 QRect pr = rect & cache.validArea; 2289 QRect pr = rect & cache.validArea;
2380 2290
2381 #ifdef DEBUG_SPECTROGRAM_REPAINT 2291 #ifdef DEBUG_SPECTROGRAM_REPAINT
2382 SVDEBUG << "Painting " << pr.width() << "x" << pr.height() 2292 cerr << "Painting " << pr.width() << "x" << pr.height()
2383 << " from cache at " << pr.x() << "," << pr.y() 2293 << " from cache at " << pr.x() << "," << pr.y()
2384 << " to window" << endl; 2294 << " to window" << endl;
2385 #endif 2295 #endif
2386 2296
2387 paint.drawImage(pr.x(), pr.y(), cache.image, 2297 paint.drawImage(pr.x(), pr.y(), cache.image,
2397 2307
2398 if (!m_normalizeVisibleArea || !overallMagChanged) { 2308 if (!m_normalizeVisibleArea || !overallMagChanged) {
2399 2309
2400 if (cache.validArea.x() > 0) { 2310 if (cache.validArea.x() > 0) {
2401 #ifdef DEBUG_SPECTROGRAM_REPAINT 2311 #ifdef DEBUG_SPECTROGRAM_REPAINT
2402 SVDEBUG << "SpectrogramLayer::paint() updating left (0, " 2312 cerr << "SpectrogramLayer::paint() updating left (0, "
2403 << cache.validArea.x() << ")" << endl; 2313 << cache.validArea.x() << ")" << endl;
2404 #endif 2314 #endif
2405 v->update(0, 0, cache.validArea.x(), h); 2315 v->update(0, 0, cache.validArea.x(), h);
2406 } 2316 }
2407 2317
2408 if (cache.validArea.x() + cache.validArea.width() < 2318 if (cache.validArea.x() + cache.validArea.width() <
2409 cache.image.width()) { 2319 cache.image.width()) {
2410 #ifdef DEBUG_SPECTROGRAM_REPAINT 2320 #ifdef DEBUG_SPECTROGRAM_REPAINT
2411 SVDEBUG << "SpectrogramLayer::paint() updating right (" 2321 cerr << "SpectrogramLayer::paint() updating right ("
2412 << cache.validArea.x() + cache.validArea.width() 2322 << cache.validArea.x() + cache.validArea.width()
2413 << ", " 2323 << ", "
2414 << cache.image.width() - (cache.validArea.x() + 2324 << cache.image.width() - (cache.validArea.x() +
2415 cache.validArea.width()) 2325 cache.validArea.width())
2416 << ")" << endl; 2326 << ")" << endl;
2430 } 2340 }
2431 2341
2432 illuminateLocalFeatures(v, paint); 2342 illuminateLocalFeatures(v, paint);
2433 2343
2434 #ifdef DEBUG_SPECTROGRAM_REPAINT 2344 #ifdef DEBUG_SPECTROGRAM_REPAINT
2435 SVDEBUG << "SpectrogramLayer::paint() returning" << endl; 2345 cerr << "SpectrogramLayer::paint() returning" << endl;
2436 #endif 2346 #endif
2437 2347
2438 if (!m_synchronous) { 2348 if (!m_synchronous) {
2439 m_lastPaintBlockWidth = paintBlockWidth; 2349 m_lastPaintBlockWidth = paintBlockWidth;
2440 (void)gettimeofday(&tv, 0); 2350 (void)gettimeofday(&tv, 0);
2668 MagnitudeRange mag; 2578 MagnitudeRange mag;
2669 2579
2670 if (sx != psx) { 2580 if (sx != psx) {
2671 if (fft) { 2581 if (fft) {
2672 #ifdef DEBUG_SPECTROGRAM_REPAINT 2582 #ifdef DEBUG_SPECTROGRAM_REPAINT
2673 SVDEBUG << "Retrieving column " << sx << " from fft directly" << endl; 2583 cerr << "Retrieving column " << sx << " from fft directly" << endl;
2674 #endif 2584 #endif
2675 if (m_colourScale == PhaseColourScale) { 2585 if (m_colourScale == PhaseColourScale) {
2676 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2586 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2677 } else if (m_normalizeColumns) { 2587 } else if (m_normalizeColumns) {
2678 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2588 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2687 } else { 2597 } else {
2688 fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); 2598 fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1);
2689 } 2599 }
2690 } else { 2600 } else {
2691 #ifdef DEBUG_SPECTROGRAM_REPAINT 2601 #ifdef DEBUG_SPECTROGRAM_REPAINT
2692 SVDEBUG << "Retrieving column " << sx << " from peaks cache" << endl; 2602 cerr << "Retrieving column " << sx << " from peaks cache" << endl;
2693 #endif 2603 #endif
2694 c = sourceModel->getColumn(sx); 2604 c = sourceModel->getColumn(sx);
2695 if (m_normalizeColumns || m_normalizeHybrid) { 2605 if (m_normalizeColumns || m_normalizeHybrid) {
2696 for (int y = 0; y < h; ++y) { 2606 for (int y = 0; y < h; ++y) {
2697 if (c[y] > columnMax) columnMax = c[y]; 2607 if (c[y] > columnMax) columnMax = c[y];
2869 } 2779 }
2870 2780
2871 int 2781 int
2872 SpectrogramLayer::getCompletion(View *v) const 2782 SpectrogramLayer::getCompletion(View *v) const
2873 { 2783 {
2874 if (m_updateTimer == 0) return 100;
2875 if (m_fftModels.find(v) == m_fftModels.end()) return 100; 2784 if (m_fftModels.find(v) == m_fftModels.end()) return 100;
2876 2785
2877 int completion = m_fftModels[v].first->getCompletion(); 2786 int completion = m_fftModels[v]->getCompletion();
2878 #ifdef DEBUG_SPECTROGRAM_REPAINT 2787 #ifdef DEBUG_SPECTROGRAM_REPAINT
2879 SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; 2788 cerr << "SpectrogramLayer::getCompletion: completion = " << completion << endl;
2880 #endif 2789 #endif
2881 return completion; 2790 return completion;
2882 } 2791 }
2883 2792
2884 QString 2793 QString
2885 SpectrogramLayer::getError(View *v) const 2794 SpectrogramLayer::getError(View *v) const
2886 { 2795 {
2887 if (m_fftModels.find(v) == m_fftModels.end()) return ""; 2796 if (m_fftModels.find(v) == m_fftModels.end()) return "";
2888 return m_fftModels[v].first->getError(); 2797 return m_fftModels[v]->getError();
2889 } 2798 }
2890 2799
2891 bool 2800 bool
2892 SpectrogramLayer::getValueExtents(double &min, double &max, 2801 SpectrogramLayer::getValueExtents(double &min, double &max,
2893 bool &logarithmic, QString &unit) const 2802 bool &logarithmic, QString &unit) const