Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 391:4f0f273c8f82
* Provide a proper implementation of
SpectrogramLayer::invalidatePixmapCaches(size_t, size_t) -- if the
region is only part of the cache's current valid area, crop the
valid area instead of resetting it completely. This makes a big
difference when first rendering a spectrogram that is zoomed out a
long way when the underlying calculation has not yet completed -- as
is a common case in Vect for example.
author | Chris Cannam |
---|---|
date | Wed, 21 May 2008 11:09:15 +0000 |
parents | 0384cf63e91c |
children | 4cb5cd9ccac7 |
comparison
equal
deleted
inserted
replaced
390:0384cf63e91c | 391:4f0f273c8f82 |
---|---|
568 i != m_pixmapCaches.end(); ++i) { | 568 i != m_pixmapCaches.end(); ++i) { |
569 | 569 |
570 //!!! when are views removed from the map? on setLayerDormant? | 570 //!!! when are views removed from the map? on setLayerDormant? |
571 const View *v = i->first; | 571 const View *v = i->first; |
572 | 572 |
573 if (startFrame < v->getEndFrame() && int(endFrame) >= v->getStartFrame()) { | 573 #ifdef DEBUG_SPECTROGRAM_REPAINT |
574 i->second.validArea = QRect(); | 574 std::cerr << "SpectrogramLayer::invalidatePixmapCaches(" |
575 << startFrame << ", " << endFrame << "): view range is " | |
576 << v->getStartFrame() << ", " << v->getEndFrame() | |
577 << std::endl; | |
578 | |
579 std::cerr << "Valid area was: " << i->second.validArea.x() << ", " | |
580 << i->second.validArea.y() << " " | |
581 << i->second.validArea.width() << "x" | |
582 << i->second.validArea.height() << std::endl; | |
583 #endif | |
584 | |
585 if (long(startFrame) > v->getStartFrame()) { | |
586 if (startFrame >= v->getEndFrame()) { | |
587 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
588 std::cerr << "Modified start frame is off right of view" << std::endl; | |
589 #endif | |
590 return; | |
591 } | |
592 int x = v->getXForFrame(startFrame); | |
593 std::cerr << "clipping from 0 to " << x-1 << std::endl; | |
594 if (x > 1) { | |
595 i->second.validArea &= | |
596 QRect(0, 0, x-1, v->height()); | |
597 } else { | |
598 i->second.validArea = QRect(); | |
599 } | |
600 } else { | |
601 if (long(endFrame) < v->getStartFrame()) { | |
602 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
603 std::cerr << "Modified end frame is off left of view" << std::endl; | |
604 #endif | |
605 return; | |
606 } | |
607 int x = v->getXForFrame(endFrame); | |
608 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
609 std::cerr << "clipping from " << x+1 << " to " << v->width() | |
610 << std::endl; | |
611 #endif | |
612 if (x < v->width()) { | |
613 i->second.validArea &= | |
614 QRect(x+1, 0, v->width()-(x+1), v->height()); | |
615 } else { | |
616 i->second.validArea = QRect(); | |
617 } | |
575 } | 618 } |
619 | |
620 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
621 std::cerr << "Valid area is now: " << i->second.validArea.x() << ", " | |
622 << i->second.validArea.y() << " " | |
623 << i->second.validArea.width() << "x" | |
624 << i->second.validArea.height() << std::endl; | |
625 #endif | |
576 } | 626 } |
577 } | 627 } |
578 | 628 |
579 void | 629 void |
580 SpectrogramLayer::preferenceChanged(PropertyContainer::PropertyName name) | 630 SpectrogramLayer::preferenceChanged(PropertyContainer::PropertyName name) |
950 } | 1000 } |
951 | 1001 |
952 void | 1002 void |
953 SpectrogramLayer::cacheInvalid() | 1003 SpectrogramLayer::cacheInvalid() |
954 { | 1004 { |
1005 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
1006 std::cerr << "SpectrogramLayer::cacheInvalid()" << std::endl; | |
1007 #endif | |
1008 | |
955 invalidatePixmapCaches(); | 1009 invalidatePixmapCaches(); |
956 invalidateMagnitudes(); | 1010 invalidateMagnitudes(); |
957 } | 1011 } |
958 | 1012 |
959 void | 1013 void |
960 SpectrogramLayer::cacheInvalid(size_t, size_t) | 1014 SpectrogramLayer::cacheInvalid(size_t from, size_t to) |
961 { | 1015 { |
962 // for now (or forever?) | 1016 #ifdef DEBUG_SPECTROGRAM_REPAINT |
963 cacheInvalid(); | 1017 std::cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << std::endl; |
1018 #endif | |
1019 | |
1020 invalidatePixmapCaches(from, to); | |
1021 invalidateMagnitudes(); | |
964 } | 1022 } |
965 | 1023 |
966 void | 1024 void |
967 SpectrogramLayer::fillTimerTimedOut() | 1025 SpectrogramLayer::fillTimerTimedOut() |
968 { | 1026 { |
1838 | 1896 |
1839 } else if (dx != 0) { | 1897 } else if (dx != 0) { |
1840 | 1898 |
1841 // we scrolled too far to be of use | 1899 // we scrolled too far to be of use |
1842 | 1900 |
1901 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
1902 std::cerr << "dx == " << dx << ": scrolled too far for cache to be useful" << std::endl; | |
1903 #endif | |
1904 | |
1843 cache.validArea = QRect(); | 1905 cache.validArea = QRect(); |
1844 recreateWholePixmapCache = true; | 1906 recreateWholePixmapCache = true; |
1845 } | 1907 } |
1846 } | 1908 } |
1847 } else { | 1909 } else { |