Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 115:47cb32bb35ab
* Restore progress updates to spectrogram
author | Chris Cannam |
---|---|
date | Wed, 05 Jul 2006 16:15:22 +0000 |
parents | 991de8783cf5 |
children | 782142eaaa84 |
comparison
equal
deleted
inserted
replaced
114:991de8783cf5 | 115:47cb32bb35ab |
---|---|
32 #include <iostream> | 32 #include <iostream> |
33 | 33 |
34 #include <cassert> | 34 #include <cassert> |
35 #include <cmath> | 35 #include <cmath> |
36 | 36 |
37 //#define DEBUG_SPECTROGRAM_REPAINT 1 | 37 #define DEBUG_SPECTROGRAM_REPAINT 1 |
38 | 38 |
39 SpectrogramLayer::SpectrogramLayer(Configuration config) : | 39 SpectrogramLayer::SpectrogramLayer(Configuration config) : |
40 Layer(), | 40 Layer(), |
41 m_model(0), | 41 m_model(0), |
42 m_channel(0), | 42 m_channel(0), |
55 m_frequencyScale(LinearFrequencyScale), | 55 m_frequencyScale(LinearFrequencyScale), |
56 m_binDisplay(AllBins), | 56 m_binDisplay(AllBins), |
57 m_normalizeColumns(false), | 57 m_normalizeColumns(false), |
58 m_updateTimer(0), | 58 m_updateTimer(0), |
59 m_candidateFillStartFrame(0), | 59 m_candidateFillStartFrame(0), |
60 m_lastFillExtent(0), | |
61 m_exiting(false) | 60 m_exiting(false) |
62 { | 61 { |
63 if (config == MelodicRange) { | 62 if (config == MelodicRange) { |
64 setWindowSize(8192); | 63 setWindowSize(8192); |
65 setWindowHopLevel(4); | 64 setWindowHopLevel(4); |
112 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), | 111 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), |
113 this, SLOT(cacheInvalid(size_t, size_t))); | 112 this, SLOT(cacheInvalid(size_t, size_t))); |
114 | 113 |
115 emit modelReplaced(); | 114 emit modelReplaced(); |
116 } | 115 } |
117 /*!!! | 116 |
118 void | |
119 SpectrogramLayer::invalidateFFTAdapters() | |
120 { | |
121 // if (m_fftServer) { | |
122 // FFTDataServer::releaseInstance(m_fftServer); | |
123 // m_fftServer = 0; | |
124 // } | |
125 | |
126 delete m_fftServer; | |
127 m_fftServer = 0; | |
128 | |
129 if (m_model) { | |
130 // m_fftServer = FFTDataServer::getFuzzyInstance(m_model, | |
131 m_fftServer = new FFTFuzzyAdapter(m_model, | |
132 m_channel, | |
133 m_windowType, | |
134 m_windowSize, | |
135 getWindowIncrement(), | |
136 m_fftSize, | |
137 true, | |
138 m_candidateFillStartFrame); | |
139 | |
140 m_lastFillExtent = 0; | |
141 | |
142 delete m_updateTimer; | |
143 m_updateTimer = new QTimer(this); | |
144 connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(fillTimerTimedOut())); | |
145 m_updateTimer->start(200); | |
146 } | |
147 } | |
148 */ | |
149 Layer::PropertyList | 117 Layer::PropertyList |
150 SpectrogramLayer::getProperties() const | 118 SpectrogramLayer::getProperties() const |
151 { | 119 { |
152 PropertyList list; | 120 PropertyList list; |
153 list.push_back("Colour"); | 121 list.push_back("Colour"); |
558 for (ViewPixmapCache::iterator i = m_pixmapCaches.begin(); | 526 for (ViewPixmapCache::iterator i = m_pixmapCaches.begin(); |
559 i != m_pixmapCaches.end(); ++i) { | 527 i != m_pixmapCaches.end(); ++i) { |
560 //!!! when are views removed from the map? on setLayerDormant? | 528 //!!! when are views removed from the map? on setLayerDormant? |
561 const View *v = i->first; | 529 const View *v = i->first; |
562 | 530 |
563 if (startFrame < v->getEndFrame() && endFrame >= v->getStartFrame()) { | 531 if (startFrame < v->getEndFrame() && int(endFrame) >= v->getStartFrame()) { |
564 i->second.validArea = QRect(); | 532 i->second.validArea = QRect(); |
565 } | 533 } |
566 } | 534 } |
567 } | 535 } |
568 | 536 |
859 | 827 |
860 invalidatePixmapCaches(); | 828 invalidatePixmapCaches(); |
861 m_pixmapCaches.erase(v); | 829 m_pixmapCaches.erase(v); |
862 | 830 |
863 if (m_fftAdapters.find(v) != m_fftAdapters.end()) { | 831 if (m_fftAdapters.find(v) != m_fftAdapters.end()) { |
864 delete m_fftAdapters[v]; | 832 delete m_fftAdapters[v].first; |
865 m_fftAdapters.erase(v); | 833 m_fftAdapters.erase(v); |
866 } | 834 } |
867 | 835 |
868 } else { | 836 } else { |
869 | 837 |
885 } | 853 } |
886 | 854 |
887 void | 855 void |
888 SpectrogramLayer::fillTimerTimedOut() | 856 SpectrogramLayer::fillTimerTimedOut() |
889 { | 857 { |
890 /*!!! | 858 if (!m_model) return; |
891 if (m_fftServer && m_model) { | 859 |
892 | 860 bool allDone = true; |
893 size_t fillExtent = m_fftServer->getFillExtent(); | 861 |
862 for (ViewFFTMap::iterator i = m_fftAdapters.begin(); | |
863 i != m_fftAdapters.end(); ++i) { | |
864 | |
865 const View *v = i->first; | |
866 const FFTFuzzyAdapter *adapter = i->second.first; | |
867 size_t lastFill = i->second.second; | |
868 | |
869 if (adapter) { | |
870 | |
871 size_t fill = adapter->getFillExtent(); | |
872 | |
894 #ifdef DEBUG_SPECTROGRAM_REPAINT | 873 #ifdef DEBUG_SPECTROGRAM_REPAINT |
895 std::cerr << "SpectrogramLayer::fillTimerTimedOut: extent " << fillExtent << ", last " << m_lastFillExtent << ", total " << m_model->getEndFrame() << std::endl; | 874 std::cerr << "SpectrogramLayer::fillTimerTimedOut: extent for " << adapter << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << std::endl; |
896 #endif | 875 #endif |
897 if (fillExtent >= m_lastFillExtent) { | 876 |
898 if (fillExtent >= m_model->getEndFrame() && m_lastFillExtent > 0) { | 877 if (fill >= lastFill) { |
878 if (fill >= m_model->getEndFrame() && lastFill > 0) { | |
899 #ifdef DEBUG_SPECTROGRAM_REPAINT | 879 #ifdef DEBUG_SPECTROGRAM_REPAINT |
900 std::cerr << "complete!" << std::endl; | 880 std::cerr << "complete!" << std::endl; |
901 #endif | 881 #endif |
902 invalidatePixmapCaches(); | 882 invalidatePixmapCaches(); |
903 emit modelChanged(); | 883 emit modelChanged(); |
904 delete m_updateTimer; | 884 i->second.second = -1; |
905 m_updateTimer = 0; | 885 |
906 m_lastFillExtent = 0; | 886 } else if (fill > lastFill) { |
907 } else if (fillExtent > m_lastFillExtent) { | |
908 #ifdef DEBUG_SPECTROGRAM_REPAINT | 887 #ifdef DEBUG_SPECTROGRAM_REPAINT |
909 std::cerr << "SpectrogramLayer: emitting modelChanged(" | 888 std::cerr << "SpectrogramLayer: emitting modelChanged(" |
910 << m_lastFillExtent << "," << fillExtent << ")" << std::endl; | 889 << lastFill << "," << fill << ")" << std::endl; |
911 #endif | 890 #endif |
912 invalidatePixmapCaches(m_lastFillExtent, fillExtent); | 891 invalidatePixmapCaches(lastFill, fill); |
913 emit modelChanged(m_lastFillExtent, fillExtent); | 892 emit modelChanged(lastFill, fill); |
914 m_lastFillExtent = fillExtent; | 893 i->second.second = fill; |
915 } | 894 } |
916 } else { | 895 } else { |
917 #ifdef DEBUG_SPECTROGRAM_REPAINT | 896 #ifdef DEBUG_SPECTROGRAM_REPAINT |
918 std::cerr << "SpectrogramLayer: going backwards, emitting modelChanged(" | 897 std::cerr << "SpectrogramLayer: going backwards, emitting modelChanged(" |
919 << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << std::endl; | 898 << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << std::endl; |
920 #endif | 899 #endif |
921 invalidatePixmapCaches(); | 900 invalidatePixmapCaches(); |
922 emit modelChanged(m_model->getStartFrame(), m_model->getEndFrame()); | 901 emit modelChanged(m_model->getStartFrame(), m_model->getEndFrame()); |
923 m_lastFillExtent = fillExtent; | 902 i->second.second = fill; |
924 } | 903 } |
925 } | 904 |
926 */ | 905 if (i->second.second >= 0) { |
906 allDone = false; | |
907 } | |
908 } | |
909 } | |
910 | |
911 if (allDone) { | |
912 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
913 std::cerr << "SpectrogramLayer: all complete!" << std::endl; | |
914 #endif | |
915 delete m_updateTimer; | |
916 m_updateTimer = 0; | |
917 } | |
927 } | 918 } |
928 | 919 |
929 void | 920 void |
930 SpectrogramLayer::setColourmap() | 921 SpectrogramLayer::setColourmap() |
931 { | 922 { |
1431 if (!m_model) return 0; | 1422 if (!m_model) return 0; |
1432 | 1423 |
1433 size_t fftSize = getFFTSize(v); | 1424 size_t fftSize = getFFTSize(v); |
1434 | 1425 |
1435 if (m_fftAdapters.find(v) != m_fftAdapters.end()) { | 1426 if (m_fftAdapters.find(v) != m_fftAdapters.end()) { |
1436 if (m_fftAdapters[v]->getHeight() != fftSize / 2) { | 1427 if (m_fftAdapters[v].first->getHeight() != fftSize / 2) { |
1437 delete m_fftAdapters[v]; | 1428 delete m_fftAdapters[v].first; |
1438 m_fftAdapters.erase(v); | 1429 m_fftAdapters.erase(v); |
1439 } | 1430 } |
1440 } | 1431 } |
1441 | 1432 |
1442 if (m_fftAdapters.find(v) == m_fftAdapters.end()) { | 1433 if (m_fftAdapters.find(v) == m_fftAdapters.end()) { |
1443 m_fftAdapters[v] = new FFTFuzzyAdapter(m_model, | 1434 m_fftAdapters[v] = FFTFillPair |
1444 m_channel, | 1435 (new FFTFuzzyAdapter(m_model, |
1445 m_windowType, | 1436 m_channel, |
1446 m_windowSize, | 1437 m_windowType, |
1447 getWindowIncrement(), | 1438 m_windowSize, |
1448 getFFTSize(v), | 1439 getWindowIncrement(), |
1449 true, | 1440 getFFTSize(v), |
1450 m_candidateFillStartFrame); | 1441 true, |
1451 m_lastFillExtent = 0; | 1442 m_candidateFillStartFrame), |
1443 0); | |
1452 | 1444 |
1453 delete m_updateTimer; | 1445 delete m_updateTimer; |
1454 m_updateTimer = new QTimer((SpectrogramLayer *)this); | 1446 m_updateTimer = new QTimer((SpectrogramLayer *)this); |
1455 connect(m_updateTimer, SIGNAL(timeout()), | 1447 connect(m_updateTimer, SIGNAL(timeout()), |
1456 this, SLOT(fillTimerTimedOut())); | 1448 this, SLOT(fillTimerTimedOut())); |
1457 m_updateTimer->start(200); | 1449 m_updateTimer->start(200); |
1458 } | 1450 } |
1459 | 1451 |
1460 return m_fftAdapters[v]; | 1452 return m_fftAdapters[v].first; |
1461 } | 1453 } |
1462 | 1454 |
1463 void | 1455 void |
1464 SpectrogramLayer::invalidateFFTAdapters() | 1456 SpectrogramLayer::invalidateFFTAdapters() |
1465 { | 1457 { |
1466 for (ViewFFTMap::iterator i = m_fftAdapters.begin(); | 1458 for (ViewFFTMap::iterator i = m_fftAdapters.begin(); |
1467 i != m_fftAdapters.end(); ++i) { | 1459 i != m_fftAdapters.end(); ++i) { |
1468 delete i->second; | 1460 delete i->second.first; |
1469 } | 1461 } |
1470 | 1462 |
1471 m_fftAdapters.clear(); | 1463 m_fftAdapters.clear(); |
1472 } | 1464 } |
1473 | 1465 |
1912 getEffectiveMaxFrequency(), | 1904 getEffectiveMaxFrequency(), |
1913 m_frequencyScale == LogFrequencyScale); | 1905 m_frequencyScale == LogFrequencyScale); |
1914 } | 1906 } |
1915 | 1907 |
1916 int | 1908 int |
1917 SpectrogramLayer::getCompletion() const | 1909 SpectrogramLayer::getCompletion(View *v) const |
1918 { | 1910 { |
1919 /*!!! | 1911 if (m_updateTimer == 0) return 100; |
1920 if (m_updateTimer == 0 || !m_fftServer) return 100; | 1912 if (m_fftAdapters.find(v) == m_fftAdapters.end()) return 100; |
1921 size_t completion = m_fftServer->getFillCompletion(); | 1913 |
1922 // std::cerr << "SpectrogramLayer::getCompletion: completion = " << completion << std::endl; | 1914 size_t completion = m_fftAdapters[v].first->getFillCompletion(); |
1915 std::cerr << "SpectrogramLayer::getCompletion: completion = " << completion << std::endl; | |
1923 return completion; | 1916 return completion; |
1924 */ | |
1925 return 100; | |
1926 } | 1917 } |
1927 | 1918 |
1928 bool | 1919 bool |
1929 SpectrogramLayer::getValueExtents(float &min, float &max, | 1920 SpectrogramLayer::getValueExtents(float &min, float &max, |
1930 bool &logarithmic, QString &unit) const | 1921 bool &logarithmic, QString &unit) const |