Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 587:4806715f7a19
Seems to be a bad idea to use plain DEBUG symbol on OS/X (system wants it)
| author | Chris Cannam | 
|---|---|
| date | Tue, 14 Jun 2011 15:27:05 +0100 | 
| parents | f4960f8ce798 | 
| children | 7ebd5a21d74f 5b72899d692b | 
   comparison
  equal
  deleted
  inserted
  replaced
| 586:1ae54a29e59e | 587:4806715f7a19 | 
|---|---|
| 576 | 576 | 
| 577 //!!! when are views removed from the map? on setLayerDormant? | 577 //!!! when are views removed from the map? on setLayerDormant? | 
| 578 const View *v = i->first; | 578 const View *v = i->first; | 
| 579 | 579 | 
| 580 #ifdef DEBUG_SPECTROGRAM_REPAINT | 580 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 581 DEBUG << "SpectrogramLayer::invalidateImageCaches(" | 581 SVDEBUG << "SpectrogramLayer::invalidateImageCaches(" | 
| 582 << startFrame << ", " << endFrame << "): view range is " | 582 << startFrame << ", " << endFrame << "): view range is " | 
| 583 << v->getStartFrame() << ", " << v->getEndFrame() | 583 << v->getStartFrame() << ", " << v->getEndFrame() | 
| 584 << endl; | 584 << endl; | 
| 585 | 585 | 
| 586 std::cerr << "Valid area was: " << i->second.validArea.x() << ", " | 586 std::cerr << "Valid area was: " << i->second.validArea.x() << ", " | 
| 596 #endif | 596 #endif | 
| 597 return; | 597 return; | 
| 598 } | 598 } | 
| 599 int x = v->getXForFrame(startFrame); | 599 int x = v->getXForFrame(startFrame); | 
| 600 #ifdef DEBUG_SPECTROGRAM_REPAINT | 600 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 601 DEBUG << "clipping from 0 to " << x-1 << endl; | 601 SVDEBUG << "clipping from 0 to " << x-1 << endl; | 
| 602 #endif | 602 #endif | 
| 603 if (x > 1) { | 603 if (x > 1) { | 
| 604 i->second.validArea &= | 604 i->second.validArea &= | 
| 605 QRect(0, 0, x-1, v->height()); | 605 QRect(0, 0, x-1, v->height()); | 
| 606 } else { | 606 } else { | 
| 613 #endif | 613 #endif | 
| 614 return; | 614 return; | 
| 615 } | 615 } | 
| 616 int x = v->getXForFrame(endFrame); | 616 int x = v->getXForFrame(endFrame); | 
| 617 #ifdef DEBUG_SPECTROGRAM_REPAINT | 617 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 618 DEBUG << "clipping from " << x+1 << " to " << v->width() | 618 SVDEBUG << "clipping from " << x+1 << " to " << v->width() | 
| 619 << endl; | 619 << endl; | 
| 620 #endif | 620 #endif | 
| 621 if (x < v->width()) { | 621 if (x < v->width()) { | 
| 622 i->second.validArea &= | 622 i->second.validArea &= | 
| 623 QRect(x+1, 0, v->width()-(x+1), v->height()); | 623 QRect(x+1, 0, v->width()-(x+1), v->height()); | 
| 636 } | 636 } | 
| 637 | 637 | 
| 638 void | 638 void | 
| 639 SpectrogramLayer::preferenceChanged(PropertyContainer::PropertyName name) | 639 SpectrogramLayer::preferenceChanged(PropertyContainer::PropertyName name) | 
| 640 { | 640 { | 
| 641 DEBUG << "SpectrogramLayer::preferenceChanged(" << name << ")" << endl; | 641 SVDEBUG << "SpectrogramLayer::preferenceChanged(" << name << ")" << endl; | 
| 642 | 642 | 
| 643 if (name == "Window Type") { | 643 if (name == "Window Type") { | 
| 644 setWindowType(Preferences::getInstance()->getWindowType()); | 644 setWindowType(Preferences::getInstance()->getWindowType()); | 
| 645 return; | 645 return; | 
| 646 } | 646 } | 
| 762 } | 762 } | 
| 763 | 763 | 
| 764 void | 764 void | 
| 765 SpectrogramLayer::setGain(float gain) | 765 SpectrogramLayer::setGain(float gain) | 
| 766 { | 766 { | 
| 767 // DEBUG << "SpectrogramLayer::setGain(" << gain << ") (my gain is now " | 767 // SVDEBUG << "SpectrogramLayer::setGain(" << gain << ") (my gain is now " | 
| 768 // << m_gain << ")" << endl; | 768 // << m_gain << ")" << endl; | 
| 769 | 769 | 
| 770 if (m_gain == gain) return; | 770 if (m_gain == gain) return; | 
| 771 | 771 | 
| 772 invalidateImageCaches(); | 772 invalidateImageCaches(); | 
| 803 void | 803 void | 
| 804 SpectrogramLayer::setMinFrequency(size_t mf) | 804 SpectrogramLayer::setMinFrequency(size_t mf) | 
| 805 { | 805 { | 
| 806 if (m_minFrequency == mf) return; | 806 if (m_minFrequency == mf) return; | 
| 807 | 807 | 
| 808 // DEBUG << "SpectrogramLayer::setMinFrequency: " << mf << endl; | 808 // SVDEBUG << "SpectrogramLayer::setMinFrequency: " << mf << endl; | 
| 809 | 809 | 
| 810 invalidateImageCaches(); | 810 invalidateImageCaches(); | 
| 811 invalidateMagnitudes(); | 811 invalidateMagnitudes(); | 
| 812 | 812 | 
| 813 m_minFrequency = mf; | 813 m_minFrequency = mf; | 
| 824 void | 824 void | 
| 825 SpectrogramLayer::setMaxFrequency(size_t mf) | 825 SpectrogramLayer::setMaxFrequency(size_t mf) | 
| 826 { | 826 { | 
| 827 if (m_maxFrequency == mf) return; | 827 if (m_maxFrequency == mf) return; | 
| 828 | 828 | 
| 829 // DEBUG << "SpectrogramLayer::setMaxFrequency: " << mf << endl; | 829 // SVDEBUG << "SpectrogramLayer::setMaxFrequency: " << mf << endl; | 
| 830 | 830 | 
| 831 invalidateImageCaches(); | 831 invalidateImageCaches(); | 
| 832 invalidateMagnitudes(); | 832 invalidateMagnitudes(); | 
| 833 | 833 | 
| 834 m_maxFrequency = mf; | 834 m_maxFrequency = mf; | 
| 949 } | 949 } | 
| 950 | 950 | 
| 951 void | 951 void | 
| 952 SpectrogramLayer::setNormalizeVisibleArea(bool n) | 952 SpectrogramLayer::setNormalizeVisibleArea(bool n) | 
| 953 { | 953 { | 
| 954 DEBUG << "SpectrogramLayer::setNormalizeVisibleArea(" << n | 954 SVDEBUG << "SpectrogramLayer::setNormalizeVisibleArea(" << n | 
| 955 << ") (from " << m_normalizeVisibleArea << ")" << endl; | 955 << ") (from " << m_normalizeVisibleArea << ")" << endl; | 
| 956 | 956 | 
| 957 if (m_normalizeVisibleArea == n) return; | 957 if (m_normalizeVisibleArea == n) return; | 
| 958 | 958 | 
| 959 invalidateImageCaches(); | 959 invalidateImageCaches(); | 
| 973 SpectrogramLayer::setLayerDormant(const View *v, bool dormant) | 973 SpectrogramLayer::setLayerDormant(const View *v, bool dormant) | 
| 974 { | 974 { | 
| 975 if (dormant) { | 975 if (dormant) { | 
| 976 | 976 | 
| 977 #ifdef DEBUG_SPECTROGRAM_REPAINT | 977 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 978 DEBUG << "SpectrogramLayer::setLayerDormant(" << dormant << ")" | 978 SVDEBUG << "SpectrogramLayer::setLayerDormant(" << dormant << ")" | 
| 979 << endl; | 979 << endl; | 
| 980 #endif | 980 #endif | 
| 981 | 981 | 
| 982 if (isLayerDormant(v)) { | 982 if (isLayerDormant(v)) { | 
| 983 return; | 983 return; | 
| 1018 | 1018 | 
| 1019 void | 1019 void | 
| 1020 SpectrogramLayer::cacheInvalid() | 1020 SpectrogramLayer::cacheInvalid() | 
| 1021 { | 1021 { | 
| 1022 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1022 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1023 DEBUG << "SpectrogramLayer::cacheInvalid()" << endl; | 1023 SVDEBUG << "SpectrogramLayer::cacheInvalid()" << endl; | 
| 1024 #endif | 1024 #endif | 
| 1025 | 1025 | 
| 1026 invalidateImageCaches(); | 1026 invalidateImageCaches(); | 
| 1027 invalidateMagnitudes(); | 1027 invalidateMagnitudes(); | 
| 1028 } | 1028 } | 
| 1029 | 1029 | 
| 1030 void | 1030 void | 
| 1031 SpectrogramLayer::cacheInvalid(size_t from, size_t to) | 1031 SpectrogramLayer::cacheInvalid(size_t from, size_t to) | 
| 1032 { | 1032 { | 
| 1033 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1033 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1034 DEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; | 1034 SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; | 
| 1035 #endif | 1035 #endif | 
| 1036 | 1036 | 
| 1037 invalidateImageCaches(from, to); | 1037 invalidateImageCaches(from, to); | 
| 1038 invalidateMagnitudes(); | 1038 invalidateMagnitudes(); | 
| 1039 } | 1039 } | 
| 1044 if (!m_model) return; | 1044 if (!m_model) return; | 
| 1045 | 1045 | 
| 1046 bool allDone = true; | 1046 bool allDone = true; | 
| 1047 | 1047 | 
| 1048 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1048 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1049 DEBUG << "SpectrogramLayer::fillTimerTimedOut: have " << m_fftModels.size() << " FFT models associated with views" << endl; | 1049 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: have " << m_fftModels.size() << " FFT models associated with views" << endl; | 
| 1050 #endif | 1050 #endif | 
| 1051 | 1051 | 
| 1052 for (ViewFFTMap::iterator i = m_fftModels.begin(); | 1052 for (ViewFFTMap::iterator i = m_fftModels.begin(); | 
| 1053 i != m_fftModels.end(); ++i) { | 1053 i != m_fftModels.end(); ++i) { | 
| 1054 | 1054 | 
| 1058 if (model) { | 1058 if (model) { | 
| 1059 | 1059 | 
| 1060 size_t fill = model->getFillExtent(); | 1060 size_t fill = model->getFillExtent(); | 
| 1061 | 1061 | 
| 1062 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1062 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1063 DEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl; | 1063 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl; | 
| 1064 #endif | 1064 #endif | 
| 1065 | 1065 | 
| 1066 if (fill >= lastFill) { | 1066 if (fill >= lastFill) { | 
| 1067 if (fill >= m_model->getEndFrame() && lastFill > 0) { | 1067 if (fill >= m_model->getEndFrame() && lastFill > 0) { | 
| 1068 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1068 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1627 size_t fftSize = getFFTSize(v); | 1627 size_t fftSize = getFFTSize(v); | 
| 1628 | 1628 | 
| 1629 if (m_fftModels.find(v) != m_fftModels.end()) { | 1629 if (m_fftModels.find(v) != m_fftModels.end()) { | 
| 1630 if (m_fftModels[v].first == 0) { | 1630 if (m_fftModels[v].first == 0) { | 
| 1631 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1631 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1632 DEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; | 1632 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; | 
| 1633 #endif | 1633 #endif | 
| 1634 return 0; | 1634 return 0; | 
| 1635 } | 1635 } | 
| 1636 if (m_fftModels[v].first->getHeight() != fftSize / 2 + 1) { | 1636 if (m_fftModels[v].first->getHeight() != fftSize / 2 + 1) { | 
| 1637 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1637 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1638 DEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; | 1638 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; | 
| 1639 #endif | 1639 #endif | 
| 1640 delete m_fftModels[v].first; | 1640 delete m_fftModels[v].first; | 
| 1641 m_fftModels.erase(v); | 1641 m_fftModels.erase(v); | 
| 1642 delete m_peakCaches[v]; | 1642 delete m_peakCaches[v]; | 
| 1643 m_peakCaches.erase(v); | 1643 m_peakCaches.erase(v); | 
| 1644 } else { | 1644 } else { | 
| 1645 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1645 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1646 DEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v].first->getHeight() << endl; | 1646 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v].first->getHeight() << endl; | 
| 1647 #endif | 1647 #endif | 
| 1648 return m_fftModels[v].first; | 1648 return m_fftModels[v].first; | 
| 1649 } | 1649 } | 
| 1650 } | 1650 } | 
| 1651 | 1651 | 
| 1762 } | 1762 } | 
| 1763 | 1763 | 
| 1764 int s0 = int(std::min(s00, s10) + 0.0001); | 1764 int s0 = int(std::min(s00, s10) + 0.0001); | 
| 1765 int s1 = int(std::max(s01, s11) + 0.0001); | 1765 int s1 = int(std::max(s01, s11) + 0.0001); | 
| 1766 | 1766 | 
| 1767 // DEBUG << "SpectrogramLayer::updateViewMagnitudes: x0 = " << x0 << ", x1 = " << x1 << ", s00 = " << s00 << ", s11 = " << s11 << " s0 = " << s0 << ", s1 = " << s1 << endl; | 1767 // SVDEBUG << "SpectrogramLayer::updateViewMagnitudes: x0 = " << x0 << ", x1 = " << x1 << ", s00 = " << s00 << ", s11 = " << s11 << " s0 = " << s0 << ", s1 = " << s1 << endl; | 
| 1768 | 1768 | 
| 1769 if (int(m_columnMags.size()) <= s1) { | 1769 if (int(m_columnMags.size()) <= s1) { | 
| 1770 m_columnMags.resize(s1 + 1); | 1770 m_columnMags.resize(s1 + 1); | 
| 1771 } | 1771 } | 
| 1772 | 1772 | 
| 1775 mag.sample(m_columnMags[s]); | 1775 mag.sample(m_columnMags[s]); | 
| 1776 } | 1776 } | 
| 1777 } | 1777 } | 
| 1778 | 1778 | 
| 1779 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1779 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1780 DEBUG << "SpectrogramLayer::updateViewMagnitudes returning from cols " | 1780 SVDEBUG << "SpectrogramLayer::updateViewMagnitudes returning from cols " | 
| 1781 << s0 << " -> " << s1 << " inclusive" << endl; | 1781 << s0 << " -> " << s1 << " inclusive" << endl; | 
| 1782 #endif | 1782 #endif | 
| 1783 | 1783 | 
| 1784 if (!mag.isSet()) return false; | 1784 if (!mag.isSet()) return false; | 
| 1785 if (mag == m_viewMags[v]) return false; | 1785 if (mag == m_viewMags[v]) return false; | 
| 1800 // It's practically FORTRAN 77 in its clarity and linearity. | 1800 // It's practically FORTRAN 77 in its clarity and linearity. | 
| 1801 | 1801 | 
| 1802 Profiler profiler("SpectrogramLayer::paint", false); | 1802 Profiler profiler("SpectrogramLayer::paint", false); | 
| 1803 | 1803 | 
| 1804 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1804 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1805 DEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl; | 1805 SVDEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl; | 
| 1806 | 1806 | 
| 1807 std::cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << std::endl; | 1807 std::cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << std::endl; | 
| 1808 #endif | 1808 #endif | 
| 1809 | 1809 | 
| 1810 long startFrame = v->getStartFrame(); | 1810 long startFrame = v->getStartFrame(); | 
| 1814 if (!m_model || !m_model->isOK() || !m_model->isReady()) { | 1814 if (!m_model || !m_model->isOK() || !m_model->isReady()) { | 
| 1815 return; | 1815 return; | 
| 1816 } | 1816 } | 
| 1817 | 1817 | 
| 1818 if (isLayerDormant(v)) { | 1818 if (isLayerDormant(v)) { | 
| 1819 DEBUG << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << endl; | 1819 SVDEBUG << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << endl; | 
| 1820 } | 1820 } | 
| 1821 | 1821 | 
| 1822 // Need to do this even if !isLayerDormant, as that could mean v | 1822 // Need to do this even if !isLayerDormant, as that could mean v | 
| 1823 // is not in the dormancy map at all -- we need it to be present | 1823 // is not in the dormancy map at all -- we need it to be present | 
| 1824 // and accountable for when determining whether we need the cache | 1824 // and accountable for when determining whether we need the cache | 
| 1835 } | 1835 } | 
| 1836 */ | 1836 */ | 
| 1837 ImageCache &cache = m_imageCaches[v]; | 1837 ImageCache &cache = m_imageCaches[v]; | 
| 1838 | 1838 | 
| 1839 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1839 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1840 DEBUG << "SpectrogramLayer::paint(): image cache valid area " << cache. | 1840 SVDEBUG << "SpectrogramLayer::paint(): image cache valid area " << cache. | 
| 1841 | 1841 | 
| 1842 validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl; | 1842 validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl; | 
| 1843 #endif | 1843 #endif | 
| 1844 | 1844 | 
| 1845 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1845 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 1846 bool stillCacheing = (m_updateTimer != 0); | 1846 bool stillCacheing = (m_updateTimer != 0); | 
| 1847 DEBUG << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << endl; | 1847 SVDEBUG << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << endl; | 
| 1848 #endif | 1848 #endif | 
| 1849 | 1849 | 
| 1850 int zoomLevel = v->getZoomLevel(); | 1850 int zoomLevel = v->getZoomLevel(); | 
| 1851 | 1851 | 
| 1852 int x0 = 0; | 1852 int x0 = 0; | 
| 2200 #endif | 2200 #endif | 
| 2201 | 2201 | 
| 2202 bool runOutOfData = false; | 2202 bool runOutOfData = false; | 
| 2203 | 2203 | 
| 2204 if (w == 0) { | 2204 if (w == 0) { | 
| 2205 DEBUG << "*** NOTE: w == 0" << endl; | 2205 SVDEBUG << "*** NOTE: w == 0" << endl; | 
| 2206 } | 2206 } | 
| 2207 | 2207 | 
| 2208 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2208 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2209 size_t pixels = 0; | 2209 size_t pixels = 0; | 
| 2210 #endif | 2210 #endif | 
| 2361 | 2361 | 
| 2362 Profiler profiler2("SpectrogramLayer::paint: draw image"); | 2362 Profiler profiler2("SpectrogramLayer::paint: draw image"); | 
| 2363 | 2363 | 
| 2364 if (recreateWholeImageCache) { | 2364 if (recreateWholeImageCache) { | 
| 2365 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2365 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2366 DEBUG << "Recreating image cache: width = " << v->width() | 2366 SVDEBUG << "Recreating image cache: width = " << v->width() | 
| 2367 << ", height = " << h << endl; | 2367 << ", height = " << h << endl; | 
| 2368 #endif | 2368 #endif | 
| 2369 cache.image = QImage(v->width(), h, QImage::Format_ARGB32_Premultiplied); | 2369 cache.image = QImage(v->width(), h, QImage::Format_ARGB32_Premultiplied); | 
| 2370 } | 2370 } | 
| 2371 | 2371 | 
| 2372 if (w > 0) { | 2372 if (w > 0) { | 
| 2373 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2373 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2374 DEBUG << "Painting " << w << "x" << h | 2374 SVDEBUG << "Painting " << w << "x" << h | 
| 2375 << " from draw buffer at " << 0 << "," << 0 | 2375 << " from draw buffer at " << 0 << "," << 0 | 
| 2376 << " to " << w << "x" << h << " on cache at " | 2376 << " to " << w << "x" << h << " on cache at " | 
| 2377 << x0 << "," << 0 << endl; | 2377 << x0 << "," << 0 << endl; | 
| 2378 #endif | 2378 #endif | 
| 2379 | 2379 | 
| 2381 | 2381 | 
| 2382 if (bufferBinResolution) { | 2382 if (bufferBinResolution) { | 
| 2383 int scaledLeft = v->getXForFrame(leftBoundaryFrame); | 2383 int scaledLeft = v->getXForFrame(leftBoundaryFrame); | 
| 2384 int scaledRight = v->getXForFrame(rightBoundaryFrame); | 2384 int scaledRight = v->getXForFrame(rightBoundaryFrame); | 
| 2385 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2385 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2386 DEBUG << "Rescaling image from " << bufwid | 2386 SVDEBUG << "Rescaling image from " << bufwid | 
| 2387 << "x" << h << " to " | 2387 << "x" << h << " to " | 
| 2388 << scaledRight-scaledLeft << "x" << h << endl; | 2388 << scaledRight-scaledLeft << "x" << h << endl; | 
| 2389 #endif | 2389 #endif | 
| 2390 Preferences::SpectrogramXSmoothing xsmoothing = | 2390 Preferences::SpectrogramXSmoothing xsmoothing = | 
| 2391 Preferences::getInstance()->getSpectrogramXSmoothing(); | 2391 Preferences::getInstance()->getSpectrogramXSmoothing(); | 
| 2392 // DEBUG << "xsmoothing == " << xsmoothing << endl; | 2392 // SVDEBUG << "xsmoothing == " << xsmoothing << endl; | 
| 2393 QImage scaled = m_drawBuffer.scaled | 2393 QImage scaled = m_drawBuffer.scaled | 
| 2394 (scaledRight - scaledLeft, h, | 2394 (scaledRight - scaledLeft, h, | 
| 2395 Qt::IgnoreAspectRatio, | 2395 Qt::IgnoreAspectRatio, | 
| 2396 ((xsmoothing == Preferences::SpectrogramXInterpolated) ? | 2396 ((xsmoothing == Preferences::SpectrogramXInterpolated) ? | 
| 2397 Qt::SmoothTransformation : Qt::FastTransformation)); | 2397 Qt::SmoothTransformation : Qt::FastTransformation)); | 
| 2398 int scaledLeftCrop = v->getXForFrame(leftCropFrame); | 2398 int scaledLeftCrop = v->getXForFrame(leftCropFrame); | 
| 2399 int scaledRightCrop = v->getXForFrame(rightCropFrame); | 2399 int scaledRightCrop = v->getXForFrame(rightCropFrame); | 
| 2400 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2400 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2401 DEBUG << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " | 2401 SVDEBUG << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " | 
| 2402 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; | 2402 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; | 
| 2403 #endif | 2403 #endif | 
| 2404 cachePainter.drawImage | 2404 cachePainter.drawImage | 
| 2405 (QRect(scaledLeftCrop, 0, | 2405 (QRect(scaledLeftCrop, 0, | 
| 2406 scaledRightCrop - scaledLeftCrop, h), | 2406 scaledRightCrop - scaledLeftCrop, h), | 
| 2417 } | 2417 } | 
| 2418 | 2418 | 
| 2419 QRect pr = rect & cache.validArea; | 2419 QRect pr = rect & cache.validArea; | 
| 2420 | 2420 | 
| 2421 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2421 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2422 DEBUG << "Painting " << pr.width() << "x" << pr.height() | 2422 SVDEBUG << "Painting " << pr.width() << "x" << pr.height() | 
| 2423 << " from cache at " << pr.x() << "," << pr.y() | 2423 << " from cache at " << pr.x() << "," << pr.y() | 
| 2424 << " to window" << endl; | 2424 << " to window" << endl; | 
| 2425 #endif | 2425 #endif | 
| 2426 | 2426 | 
| 2427 paint.drawImage(pr.x(), pr.y(), cache.image, | 2427 paint.drawImage(pr.x(), pr.y(), cache.image, | 
| 2437 | 2437 | 
| 2438 if (!m_normalizeVisibleArea || !overallMagChanged) { | 2438 if (!m_normalizeVisibleArea || !overallMagChanged) { | 
| 2439 | 2439 | 
| 2440 if (cache.validArea.x() > 0) { | 2440 if (cache.validArea.x() > 0) { | 
| 2441 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2441 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2442 DEBUG << "SpectrogramLayer::paint() updating left (0, " | 2442 SVDEBUG << "SpectrogramLayer::paint() updating left (0, " | 
| 2443 << cache.validArea.x() << ")" << endl; | 2443 << cache.validArea.x() << ")" << endl; | 
| 2444 #endif | 2444 #endif | 
| 2445 v->update(0, 0, cache.validArea.x(), h); | 2445 v->update(0, 0, cache.validArea.x(), h); | 
| 2446 } | 2446 } | 
| 2447 | 2447 | 
| 2448 if (cache.validArea.x() + cache.validArea.width() < | 2448 if (cache.validArea.x() + cache.validArea.width() < | 
| 2449 cache.image.width()) { | 2449 cache.image.width()) { | 
| 2450 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2450 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2451 DEBUG << "SpectrogramLayer::paint() updating right (" | 2451 SVDEBUG << "SpectrogramLayer::paint() updating right (" | 
| 2452 << cache.validArea.x() + cache.validArea.width() | 2452 << cache.validArea.x() + cache.validArea.width() | 
| 2453 << ", " | 2453 << ", " | 
| 2454 << cache.image.width() - (cache.validArea.x() + | 2454 << cache.image.width() - (cache.validArea.x() + | 
| 2455 cache.validArea.width()) | 2455 cache.validArea.width()) | 
| 2456 << ")" << endl; | 2456 << ")" << endl; | 
| 2470 } | 2470 } | 
| 2471 | 2471 | 
| 2472 illuminateLocalFeatures(v, paint); | 2472 illuminateLocalFeatures(v, paint); | 
| 2473 | 2473 | 
| 2474 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2474 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2475 DEBUG << "SpectrogramLayer::paint() returning" << endl; | 2475 SVDEBUG << "SpectrogramLayer::paint() returning" << endl; | 
| 2476 #endif | 2476 #endif | 
| 2477 | 2477 | 
| 2478 if (!m_synchronous) { | 2478 if (!m_synchronous) { | 
| 2479 m_lastPaintBlockWidth = paintBlockWidth; | 2479 m_lastPaintBlockWidth = paintBlockWidth; | 
| 2480 (void)gettimeofday(&tv, 0); | 2480 (void)gettimeofday(&tv, 0); | 
| 2705 MagnitudeRange mag; | 2705 MagnitudeRange mag; | 
| 2706 | 2706 | 
| 2707 if (sx != psx) { | 2707 if (sx != psx) { | 
| 2708 if (fft) { | 2708 if (fft) { | 
| 2709 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2709 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2710 DEBUG << "Retrieving column " << sx << " from fft directly" << endl; | 2710 SVDEBUG << "Retrieving column " << sx << " from fft directly" << endl; | 
| 2711 #endif | 2711 #endif | 
| 2712 if (m_colourScale == PhaseColourScale) { | 2712 if (m_colourScale == PhaseColourScale) { | 
| 2713 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 2713 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 
| 2714 } else if (m_normalizeColumns) { | 2714 } else if (m_normalizeColumns) { | 
| 2715 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 2715 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 
| 2716 } else { | 2716 } else { | 
| 2717 fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 2717 fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 
| 2718 } | 2718 } | 
| 2719 } else { | 2719 } else { | 
| 2720 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2720 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2721 DEBUG << "Retrieving column " << sx << " from peaks cache" << endl; | 2721 SVDEBUG << "Retrieving column " << sx << " from peaks cache" << endl; | 
| 2722 #endif | 2722 #endif | 
| 2723 c = sourceModel->getColumn(sx); | 2723 c = sourceModel->getColumn(sx); | 
| 2724 if (m_normalizeColumns) { | 2724 if (m_normalizeColumns) { | 
| 2725 for (int y = 0; y < h; ++y) { | 2725 for (int y = 0; y < h; ++y) { | 
| 2726 if (c[y] > columnMax) columnMax = c[y]; | 2726 if (c[y] > columnMax) columnMax = c[y]; | 
| 2898 if (m_updateTimer == 0) return 100; | 2898 if (m_updateTimer == 0) return 100; | 
| 2899 if (m_fftModels.find(v) == m_fftModels.end()) return 100; | 2899 if (m_fftModels.find(v) == m_fftModels.end()) return 100; | 
| 2900 | 2900 | 
| 2901 size_t completion = m_fftModels[v].first->getCompletion(); | 2901 size_t completion = m_fftModels[v].first->getCompletion(); | 
| 2902 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2902 #ifdef DEBUG_SPECTROGRAM_REPAINT | 
| 2903 DEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; | 2903 SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; | 
| 2904 #endif | 2904 #endif | 
| 2905 return completion; | 2905 return completion; | 
| 2906 } | 2906 } | 
| 2907 | 2907 | 
| 2908 QString | 2908 QString | 
| 2931 SpectrogramLayer::getDisplayExtents(float &min, float &max) const | 2931 SpectrogramLayer::getDisplayExtents(float &min, float &max) const | 
| 2932 { | 2932 { | 
| 2933 min = getEffectiveMinFrequency(); | 2933 min = getEffectiveMinFrequency(); | 
| 2934 max = getEffectiveMaxFrequency(); | 2934 max = getEffectiveMaxFrequency(); | 
| 2935 | 2935 | 
| 2936 // DEBUG << "SpectrogramLayer::getDisplayExtents: " << min << "->" << max << endl; | 2936 // SVDEBUG << "SpectrogramLayer::getDisplayExtents: " << min << "->" << max << endl; | 
| 2937 return true; | 2937 return true; | 
| 2938 } | 2938 } | 
| 2939 | 2939 | 
| 2940 bool | 2940 bool | 
| 2941 SpectrogramLayer::setDisplayExtents(float min, float max) | 2941 SpectrogramLayer::setDisplayExtents(float min, float max) | 
| 2942 { | 2942 { | 
| 2943 if (!m_model) return false; | 2943 if (!m_model) return false; | 
| 2944 | 2944 | 
| 2945 // DEBUG << "SpectrogramLayer::setDisplayExtents: " << min << "->" << max << endl; | 2945 // SVDEBUG << "SpectrogramLayer::setDisplayExtents: " << min << "->" << max << endl; | 
| 2946 | 2946 | 
| 2947 if (min < 0) min = 0; | 2947 if (min < 0) min = 0; | 
| 2948 if (max > m_model->getSampleRate()/2) max = m_model->getSampleRate()/2; | 2948 if (max > m_model->getSampleRate()/2) max = m_model->getSampleRate()/2; | 
| 2949 | 2949 | 
| 2950 size_t minf = lrintf(min); | 2950 size_t minf = lrintf(min); | 
| 3549 size_t initialMax = m_initialMaxFrequency; | 3549 size_t initialMax = m_initialMaxFrequency; | 
| 3550 if (initialMax == 0) initialMax = sr / 2; | 3550 if (initialMax == 0) initialMax = sr / 2; | 
| 3551 | 3551 | 
| 3552 defaultStep = mapper.getPositionForValue(initialMax) - minStep; | 3552 defaultStep = mapper.getPositionForValue(initialMax) - minStep; | 
| 3553 | 3553 | 
| 3554 // DEBUG << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << initialMax << ")" << endl; | 3554 // SVDEBUG << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << initialMax << ")" << endl; | 
| 3555 | 3555 | 
| 3556 return maxStep - minStep; | 3556 return maxStep - minStep; | 
| 3557 } | 3557 } | 
| 3558 | 3558 | 
| 3559 int | 3559 int | 
| 3564 float dmin, dmax; | 3564 float dmin, dmax; | 
| 3565 getDisplayExtents(dmin, dmax); | 3565 getDisplayExtents(dmin, dmax); | 
| 3566 | 3566 | 
| 3567 SpectrogramRangeMapper mapper(m_model->getSampleRate(), m_fftSize); | 3567 SpectrogramRangeMapper mapper(m_model->getSampleRate(), m_fftSize); | 
| 3568 int n = mapper.getPositionForValue(dmax - dmin); | 3568 int n = mapper.getPositionForValue(dmax - dmin); | 
| 3569 // DEBUG << "SpectrogramLayer::getCurrentVerticalZoomStep: " << n << endl; | 3569 // SVDEBUG << "SpectrogramLayer::getCurrentVerticalZoomStep: " << n << endl; | 
| 3570 return n; | 3570 return n; | 
| 3571 } | 3571 } | 
| 3572 | 3572 | 
| 3573 void | 3573 void | 
| 3574 SpectrogramLayer::setVerticalZoomStep(int step) | 3574 SpectrogramLayer::setVerticalZoomStep(int step) | 
| 3630 } | 3630 } | 
| 3631 if (newmax > mmax) { | 3631 if (newmax > mmax) { | 
| 3632 newmax = mmax; | 3632 newmax = mmax; | 
| 3633 } | 3633 } | 
| 3634 | 3634 | 
| 3635 // DEBUG << "SpectrogramLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; | 3635 // SVDEBUG << "SpectrogramLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; | 
| 3636 | 3636 | 
| 3637 setMinFrequency(lrintf(newmin)); | 3637 setMinFrequency(lrintf(newmin)); | 
| 3638 setMaxFrequency(lrintf(newmax)); | 3638 setMaxFrequency(lrintf(newmax)); | 
| 3639 } | 3639 } | 
| 3640 | 3640 | 
| 3652 if (r.startY > 0.0) y0 = getYForFrequency(v, r.startY); | 3652 if (r.startY > 0.0) y0 = getYForFrequency(v, r.startY); | 
| 3653 | 3653 | 
| 3654 int y1 = y0; | 3654 int y1 = y0; | 
| 3655 if (r.endY > 0.0) y1 = getYForFrequency(v, r.endY); | 3655 if (r.endY > 0.0) y1 = getYForFrequency(v, r.endY); | 
| 3656 | 3656 | 
| 3657 // DEBUG << "SpectrogramLayer::updateMeasureRectYCoords: start " << r.startY << " -> " << y0 << ", end " << r.endY << " -> " << y1 << endl; | 3657 // SVDEBUG << "SpectrogramLayer::updateMeasureRectYCoords: start " << r.startY << " -> " << y0 << ", end " << r.endY << " -> " << y1 << endl; | 
| 3658 | 3658 | 
| 3659 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); | 3659 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); | 
| 3660 } | 3660 } | 
| 3661 | 3661 | 
| 3662 void | 3662 void | 
| 3666 r.startY = getFrequencyForY(v, y); | 3666 r.startY = getFrequencyForY(v, y); | 
| 3667 r.endY = r.startY; | 3667 r.endY = r.startY; | 
| 3668 } else { | 3668 } else { | 
| 3669 r.endY = getFrequencyForY(v, y); | 3669 r.endY = getFrequencyForY(v, y); | 
| 3670 } | 3670 } | 
| 3671 // DEBUG << "SpectrogramLayer::setMeasureRectYCoord: start " << r.startY << " <- " << y << ", end " << r.endY << " <- " << y << endl; | 3671 // SVDEBUG << "SpectrogramLayer::setMeasureRectYCoord: start " << r.startY << " <- " << y << ", end " << r.endY << " <- " << y << endl; | 
| 3672 | 3672 | 
| 3673 } | 3673 } | 
| 3674 | 3674 | 
| 3675 void | 3675 void | 
| 3676 SpectrogramLayer::toXml(QTextStream &stream, | 3676 SpectrogramLayer::toXml(QTextStream &stream, | 
| 3742 float threshold = attributes.value("threshold").toFloat(&ok); | 3742 float threshold = attributes.value("threshold").toFloat(&ok); | 
| 3743 if (ok) setThreshold(threshold); | 3743 if (ok) setThreshold(threshold); | 
| 3744 | 3744 | 
| 3745 size_t minFrequency = attributes.value("minFrequency").toUInt(&ok); | 3745 size_t minFrequency = attributes.value("minFrequency").toUInt(&ok); | 
| 3746 if (ok) { | 3746 if (ok) { | 
| 3747 DEBUG << "SpectrogramLayer::setProperties: setting min freq to " << minFrequency << endl; | 3747 SVDEBUG << "SpectrogramLayer::setProperties: setting min freq to " << minFrequency << endl; | 
| 3748 setMinFrequency(minFrequency); | 3748 setMinFrequency(minFrequency); | 
| 3749 } | 3749 } | 
| 3750 | 3750 | 
| 3751 size_t maxFrequency = attributes.value("maxFrequency").toUInt(&ok); | 3751 size_t maxFrequency = attributes.value("maxFrequency").toUInt(&ok); | 
| 3752 if (ok) { | 3752 if (ok) { | 
| 3753 DEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl; | 3753 SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl; | 
| 3754 setMaxFrequency(maxFrequency); | 3754 setMaxFrequency(maxFrequency); | 
| 3755 } | 3755 } | 
| 3756 | 3756 | 
| 3757 ColourScale colourScale = (ColourScale) | 3757 ColourScale colourScale = (ColourScale) | 
| 3758 attributes.value("colourScale").toInt(&ok); | 3758 attributes.value("colourScale").toInt(&ok); | 
