Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 389:2ed4e572d0d4
* Attempt fix for #1914752 export image has holes (1.0 and 1.2)
author | Chris Cannam |
---|---|
date | Tue, 20 May 2008 10:40:20 +0000 |
parents | b35184d0dfe5 |
children | 0384cf63e91c |
comparison
equal
deleted
inserted
replaced
388:881470f9ca48 | 389:2ed4e572d0d4 |
---|---|
66 m_frequencyScale(LinearFrequencyScale), | 66 m_frequencyScale(LinearFrequencyScale), |
67 m_binDisplay(AllBins), | 67 m_binDisplay(AllBins), |
68 m_normalizeColumns(false), | 68 m_normalizeColumns(false), |
69 m_normalizeVisibleArea(false), | 69 m_normalizeVisibleArea(false), |
70 m_lastEmittedZoomStep(-1), | 70 m_lastEmittedZoomStep(-1), |
71 m_synchronous(true), //!!! | |
71 m_lastPaintBlockWidth(0), | 72 m_lastPaintBlockWidth(0), |
72 m_updateTimer(0), | 73 m_updateTimer(0), |
73 m_candidateFillStartFrame(0), | 74 m_candidateFillStartFrame(0), |
74 m_exiting(false), | 75 m_exiting(false), |
75 m_sliceableModel(0) | 76 m_sliceableModel(0) |
1670 m_viewMags[v] = mag; | 1671 m_viewMags[v] = mag; |
1671 return true; | 1672 return true; |
1672 } | 1673 } |
1673 | 1674 |
1674 void | 1675 void |
1676 SpectrogramLayer::setSynchronousPainting(bool synchronous) | |
1677 { | |
1678 m_synchronous = synchronous; | |
1679 } | |
1680 | |
1681 void | |
1675 SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const | 1682 SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const |
1676 { | 1683 { |
1677 // What a lovely, old-fashioned function this is. | 1684 // What a lovely, old-fashioned function this is. |
1678 // It's practically FORTRAN 77 in its clarity and linearity. | 1685 // It's practically FORTRAN 77 in its clarity and linearity. |
1679 | 1686 |
1881 (void)gettimeofday(&tv, 0); | 1888 (void)gettimeofday(&tv, 0); |
1882 RealTime mainPaintStart = RealTime::fromTimeval(tv); | 1889 RealTime mainPaintStart = RealTime::fromTimeval(tv); |
1883 | 1890 |
1884 int paintBlockWidth = m_lastPaintBlockWidth; | 1891 int paintBlockWidth = m_lastPaintBlockWidth; |
1885 | 1892 |
1886 if (paintBlockWidth == 0) { | 1893 if (m_synchronous) { |
1887 paintBlockWidth = (300000 / zoomLevel); | 1894 if (paintBlockWidth < x1 - x0) { |
1895 // always paint full width | |
1896 paintBlockWidth = x1 - x0; | |
1897 } | |
1888 } else { | 1898 } else { |
1889 RealTime lastTime = m_lastPaintTime; | 1899 if (paintBlockWidth == 0) { |
1890 while (lastTime > RealTime::fromMilliseconds(200) && | 1900 paintBlockWidth = (300000 / zoomLevel); |
1891 paintBlockWidth > 50) { | 1901 } else { |
1892 paintBlockWidth /= 2; | 1902 RealTime lastTime = m_lastPaintTime; |
1893 lastTime = lastTime / 2; | 1903 while (lastTime > RealTime::fromMilliseconds(200) && |
1904 paintBlockWidth > 50) { | |
1905 paintBlockWidth /= 2; | |
1906 lastTime = lastTime / 2; | |
1907 } | |
1908 while (lastTime < RealTime::fromMilliseconds(90) && | |
1909 paintBlockWidth < 1500) { | |
1910 paintBlockWidth *= 2; | |
1911 lastTime = lastTime * 2; | |
1912 } | |
1894 } | 1913 } |
1895 while (lastTime < RealTime::fromMilliseconds(90) && | 1914 |
1896 paintBlockWidth < 1500) { | 1915 if (paintBlockWidth < 20) paintBlockWidth = 20; |
1897 paintBlockWidth *= 2; | 1916 } |
1898 lastTime = lastTime * 2; | |
1899 } | |
1900 } | |
1901 | |
1902 if (paintBlockWidth < 20) paintBlockWidth = 20; | |
1903 | 1917 |
1904 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1918 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1905 std::cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << std::endl; | 1919 std::cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << std::endl; |
1906 #endif | 1920 #endif |
1907 | 1921 |
2126 } | 2140 } |
2127 } | 2141 } |
2128 | 2142 |
2129 for (int s = s0i; s <= s1i; ++s) { | 2143 for (int s = s0i; s <= s1i; ++s) { |
2130 | 2144 |
2131 if (!fft->isColumnAvailable(s)) { | 2145 if (!m_synchronous) { |
2132 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2146 if (!fft->isColumnAvailable(s)) { |
2133 std::cerr << "Met unavailable column at col " << s << std::endl; | 2147 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2134 #endif | 2148 std::cerr << "Met unavailable column at col " << s << std::endl; |
2135 // continue; | 2149 #endif |
2136 runOutOfData = true; | 2150 runOutOfData = true; |
2137 break; | 2151 break; |
2152 } | |
2138 } | 2153 } |
2139 | 2154 |
2140 if (!fftSuspended) { | 2155 if (!fftSuspended) { |
2141 fft->suspendWrites(); | 2156 fft->suspendWrites(); |
2142 fftSuspended = true; | 2157 fftSuspended = true; |
2377 pr.x(), pr.y(), pr.width(), pr.height()); | 2392 pr.x(), pr.y(), pr.width(), pr.height()); |
2378 | 2393 |
2379 cache.startFrame = startFrame; | 2394 cache.startFrame = startFrame; |
2380 cache.zoomLevel = zoomLevel; | 2395 cache.zoomLevel = zoomLevel; |
2381 | 2396 |
2382 if (!m_normalizeVisibleArea || !overallMagChanged) { | 2397 if (!m_synchronous) { |
2383 | 2398 |
2384 if (cache.validArea.x() > 0) { | 2399 if (!m_normalizeVisibleArea || !overallMagChanged) { |
2385 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2400 |
2386 std::cerr << "SpectrogramLayer::paint() updating left (0, " | 2401 if (cache.validArea.x() > 0) { |
2387 << cache.validArea.x() << ")" << std::endl; | 2402 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2388 #endif | 2403 std::cerr << "SpectrogramLayer::paint() updating left (0, " |
2389 v->update(0, 0, cache.validArea.x(), h); | 2404 << cache.validArea.x() << ")" << std::endl; |
2405 #endif | |
2406 v->update(0, 0, cache.validArea.x(), h); | |
2407 } | |
2408 | |
2409 if (cache.validArea.x() + cache.validArea.width() < | |
2410 cache.pixmap.width()) { | |
2411 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2412 std::cerr << "SpectrogramLayer::paint() updating right (" | |
2413 << cache.validArea.x() + cache.validArea.width() | |
2414 << ", " | |
2415 << cache.pixmap.width() - (cache.validArea.x() + | |
2416 cache.validArea.width()) | |
2417 << ")" << std::endl; | |
2418 #endif | |
2419 v->update(cache.validArea.x() + cache.validArea.width(), | |
2420 0, | |
2421 cache.pixmap.width() - (cache.validArea.x() + | |
2422 cache.validArea.width()), | |
2423 h); | |
2424 } | |
2425 } else { | |
2426 // overallMagChanged | |
2427 std::cerr << "\noverallMagChanged - updating all\n" << std::endl; | |
2428 cache.validArea = QRect(); | |
2429 v->update(); | |
2390 } | 2430 } |
2391 | |
2392 if (cache.validArea.x() + cache.validArea.width() < | |
2393 cache.pixmap.width()) { | |
2394 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2395 std::cerr << "SpectrogramLayer::paint() updating right (" | |
2396 << cache.validArea.x() + cache.validArea.width() | |
2397 << ", " | |
2398 << cache.pixmap.width() - (cache.validArea.x() + | |
2399 cache.validArea.width()) | |
2400 << ")" << std::endl; | |
2401 #endif | |
2402 v->update(cache.validArea.x() + cache.validArea.width(), | |
2403 0, | |
2404 cache.pixmap.width() - (cache.validArea.x() + | |
2405 cache.validArea.width()), | |
2406 h); | |
2407 } | |
2408 } else { | |
2409 // overallMagChanged | |
2410 std::cerr << "\noverallMagChanged - updating all\n" << std::endl; | |
2411 cache.validArea = QRect(); | |
2412 v->update(); | |
2413 } | 2431 } |
2414 | 2432 |
2415 illuminateLocalFeatures(v, paint); | 2433 illuminateLocalFeatures(v, paint); |
2416 | 2434 |
2417 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2435 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2418 std::cerr << "SpectrogramLayer::paint() returning" << std::endl; | 2436 std::cerr << "SpectrogramLayer::paint() returning" << std::endl; |
2419 #endif | 2437 #endif |
2420 | 2438 |
2421 m_lastPaintBlockWidth = paintBlockWidth; | 2439 if (!m_synchronous) { |
2422 (void)gettimeofday(&tv, 0); | 2440 m_lastPaintBlockWidth = paintBlockWidth; |
2423 m_lastPaintTime = RealTime::fromTimeval(tv) - mainPaintStart; | 2441 (void)gettimeofday(&tv, 0); |
2442 m_lastPaintTime = RealTime::fromTimeval(tv) - mainPaintStart; | |
2443 } | |
2424 | 2444 |
2425 if (fftSuspended) fft->resume(); | 2445 if (fftSuspended) fft->resume(); |
2426 } | 2446 } |
2427 | 2447 |
2428 void | 2448 void |