Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 130:10eec0da9efe last-cc-copyright
* Move the current DenseThreeDimensionalModel to EditableDenseThreeDimensionalModel
(wow!), and make DTDM an abstract base
* Move FFTFuzzyAdapter to FFTModel as a new subclass of DTDM
author | Chris Cannam |
---|---|
date | Mon, 31 Jul 2006 17:05:18 +0000 |
parents | 33929e0c3c6b |
children | eaae73b6bd28 |
comparison
equal
deleted
inserted
replaced
129:26d9d65e4941 | 130:10eec0da9efe |
---|---|
90 SpectrogramLayer::~SpectrogramLayer() | 90 SpectrogramLayer::~SpectrogramLayer() |
91 { | 91 { |
92 delete m_updateTimer; | 92 delete m_updateTimer; |
93 m_updateTimer = 0; | 93 m_updateTimer = 0; |
94 | 94 |
95 invalidateFFTAdapters(); | 95 invalidateFFTModels(); |
96 } | 96 } |
97 | 97 |
98 void | 98 void |
99 SpectrogramLayer::setModel(const DenseTimeValueModel *model) | 99 SpectrogramLayer::setModel(const DenseTimeValueModel *model) |
100 { | 100 { |
101 // std::cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << std::endl; | 101 // std::cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << std::endl; |
102 | 102 |
103 if (model == m_model) return; | 103 if (model == m_model) return; |
104 | 104 |
105 m_model = model; | 105 m_model = model; |
106 invalidateFFTAdapters(); | 106 invalidateFFTModels(); |
107 | 107 |
108 if (!m_model || !m_model->isOK()) return; | 108 if (!m_model || !m_model->isOK()) return; |
109 | 109 |
110 connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); | 110 connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); |
111 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), | 111 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), |
577 { | 577 { |
578 if (m_channel == ch) return; | 578 if (m_channel == ch) return; |
579 | 579 |
580 invalidatePixmapCaches(); | 580 invalidatePixmapCaches(); |
581 m_channel = ch; | 581 m_channel = ch; |
582 invalidateFFTAdapters(); | 582 invalidateFFTModels(); |
583 | 583 |
584 emit layerParametersChanged(); | 584 emit layerParametersChanged(); |
585 } | 585 } |
586 | 586 |
587 int | 587 int |
598 invalidatePixmapCaches(); | 598 invalidatePixmapCaches(); |
599 | 599 |
600 m_windowSize = ws; | 600 m_windowSize = ws; |
601 m_fftSize = ws * (m_zeroPadLevel + 1); | 601 m_fftSize = ws * (m_zeroPadLevel + 1); |
602 | 602 |
603 invalidateFFTAdapters(); | 603 invalidateFFTModels(); |
604 | 604 |
605 emit layerParametersChanged(); | 605 emit layerParametersChanged(); |
606 } | 606 } |
607 | 607 |
608 size_t | 608 size_t |
618 | 618 |
619 invalidatePixmapCaches(); | 619 invalidatePixmapCaches(); |
620 | 620 |
621 m_windowHopLevel = v; | 621 m_windowHopLevel = v; |
622 | 622 |
623 invalidateFFTAdapters(); | 623 invalidateFFTModels(); |
624 | 624 |
625 emit layerParametersChanged(); | 625 emit layerParametersChanged(); |
626 | 626 |
627 // fillCache(); | 627 // fillCache(); |
628 } | 628 } |
641 invalidatePixmapCaches(); | 641 invalidatePixmapCaches(); |
642 | 642 |
643 m_zeroPadLevel = v; | 643 m_zeroPadLevel = v; |
644 m_fftSize = m_windowSize * (v + 1); | 644 m_fftSize = m_windowSize * (v + 1); |
645 | 645 |
646 invalidateFFTAdapters(); | 646 invalidateFFTModels(); |
647 | 647 |
648 emit layerParametersChanged(); | 648 emit layerParametersChanged(); |
649 } | 649 } |
650 | 650 |
651 size_t | 651 size_t |
661 | 661 |
662 invalidatePixmapCaches(); | 662 invalidatePixmapCaches(); |
663 | 663 |
664 m_windowType = w; | 664 m_windowType = w; |
665 | 665 |
666 invalidateFFTAdapters(); | 666 invalidateFFTModels(); |
667 | 667 |
668 emit layerParametersChanged(); | 668 emit layerParametersChanged(); |
669 } | 669 } |
670 | 670 |
671 WindowType | 671 WindowType |
885 m_dormancy[v] = true; | 885 m_dormancy[v] = true; |
886 | 886 |
887 invalidatePixmapCaches(); | 887 invalidatePixmapCaches(); |
888 m_pixmapCaches.erase(v); | 888 m_pixmapCaches.erase(v); |
889 | 889 |
890 if (m_fftAdapters.find(v) != m_fftAdapters.end()) { | 890 if (m_fftModels.find(v) != m_fftModels.end()) { |
891 delete m_fftAdapters[v].first; | 891 delete m_fftModels[v].first; |
892 m_fftAdapters.erase(v); | 892 m_fftModels.erase(v); |
893 } | 893 } |
894 | 894 |
895 } else { | 895 } else { |
896 | 896 |
897 m_dormancy[v] = false; | 897 m_dormancy[v] = false; |
917 { | 917 { |
918 if (!m_model) return; | 918 if (!m_model) return; |
919 | 919 |
920 bool allDone = true; | 920 bool allDone = true; |
921 | 921 |
922 for (ViewFFTMap::iterator i = m_fftAdapters.begin(); | 922 for (ViewFFTMap::iterator i = m_fftModels.begin(); |
923 i != m_fftAdapters.end(); ++i) { | 923 i != m_fftModels.end(); ++i) { |
924 | 924 |
925 const View *v = i->first; | 925 const View *v = i->first; |
926 const FFTFuzzyAdapter *adapter = i->second.first; | 926 const FFTModel *model = i->second.first; |
927 size_t lastFill = i->second.second; | 927 size_t lastFill = i->second.second; |
928 | 928 |
929 if (adapter) { | 929 if (model) { |
930 | 930 |
931 size_t fill = adapter->getFillExtent(); | 931 size_t fill = model->getFillExtent(); |
932 | 932 |
933 #ifdef DEBUG_SPECTROGRAM_REPAINT | 933 #ifdef DEBUG_SPECTROGRAM_REPAINT |
934 std::cerr << "SpectrogramLayer::fillTimerTimedOut: extent for " << adapter << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << std::endl; | 934 std::cerr << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << std::endl; |
935 #endif | 935 #endif |
936 | 936 |
937 if (fill >= lastFill) { | 937 if (fill >= lastFill) { |
938 if (fill >= m_model->getEndFrame() && lastFill > 0) { | 938 if (fill >= m_model->getEndFrame() && lastFill > 0) { |
939 #ifdef DEBUG_SPECTROGRAM_REPAINT | 939 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1283 float minf = getEffectiveMinFrequency(); | 1283 float minf = getEffectiveMinFrequency(); |
1284 float maxf = getEffectiveMaxFrequency(); | 1284 float maxf = getEffectiveMaxFrequency(); |
1285 | 1285 |
1286 bool logarithmic = (m_frequencyScale == LogFrequencyScale); | 1286 bool logarithmic = (m_frequencyScale == LogFrequencyScale); |
1287 | 1287 |
1288 //!!! wrong for smoothing -- wrong fft size for fft adapter | 1288 //!!! wrong for smoothing -- wrong fft size for fft model |
1289 | 1289 |
1290 q0 = v->getFrequencyForY(y, minf, maxf, logarithmic); | 1290 q0 = v->getFrequencyForY(y, minf, maxf, logarithmic); |
1291 q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic); | 1291 q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic); |
1292 | 1292 |
1293 // Now map these on to actual bins | 1293 // Now map these on to actual bins |
1371 SpectrogramLayer::getAdjustedYBinSourceRange(View *v, int x, int y, | 1371 SpectrogramLayer::getAdjustedYBinSourceRange(View *v, int x, int y, |
1372 float &freqMin, float &freqMax, | 1372 float &freqMin, float &freqMax, |
1373 float &adjFreqMin, float &adjFreqMax) | 1373 float &adjFreqMin, float &adjFreqMax) |
1374 const | 1374 const |
1375 { | 1375 { |
1376 FFTFuzzyAdapter *fft = getFFTAdapter(v); | 1376 FFTModel *fft = getFFTModel(v); |
1377 if (!fft) return false; | 1377 if (!fft) return false; |
1378 | 1378 |
1379 float s0 = 0, s1 = 0; | 1379 float s0 = 0, s1 = 0; |
1380 if (!getXBinRange(v, x, s0, s1)) return false; | 1380 if (!getXBinRange(v, x, s0, s1)) return false; |
1381 | 1381 |
1461 | 1461 |
1462 size_t zp = getZeroPadLevel(v); | 1462 size_t zp = getZeroPadLevel(v); |
1463 q0i *= zp + 1; | 1463 q0i *= zp + 1; |
1464 q1i *= zp + 1; | 1464 q1i *= zp + 1; |
1465 | 1465 |
1466 FFTFuzzyAdapter *fft = getFFTAdapter(v); | 1466 FFTModel *fft = getFFTModel(v); |
1467 | 1467 |
1468 if (fft) { | 1468 if (fft) { |
1469 | 1469 |
1470 int cw = fft->getWidth(); | 1470 int cw = fft->getWidth(); |
1471 int ch = fft->getHeight(); | 1471 int ch = fft->getHeight(); |
1546 SpectrogramLayer::getFFTSize(const View *v) const | 1546 SpectrogramLayer::getFFTSize(const View *v) const |
1547 { | 1547 { |
1548 return m_fftSize * (getZeroPadLevel(v) + 1); | 1548 return m_fftSize * (getZeroPadLevel(v) + 1); |
1549 } | 1549 } |
1550 | 1550 |
1551 FFTFuzzyAdapter * | 1551 FFTModel * |
1552 SpectrogramLayer::getFFTAdapter(const View *v) const | 1552 SpectrogramLayer::getFFTModel(const View *v) const |
1553 { | 1553 { |
1554 if (!m_model) return 0; | 1554 if (!m_model) return 0; |
1555 | 1555 |
1556 size_t fftSize = getFFTSize(v); | 1556 size_t fftSize = getFFTSize(v); |
1557 | 1557 |
1558 if (m_fftAdapters.find(v) != m_fftAdapters.end()) { | 1558 if (m_fftModels.find(v) != m_fftModels.end()) { |
1559 if (m_fftAdapters[v].first->getHeight() != fftSize / 2) { | 1559 if (m_fftModels[v].first->getHeight() != fftSize / 2) { |
1560 delete m_fftAdapters[v].first; | 1560 delete m_fftModels[v].first; |
1561 m_fftAdapters.erase(v); | 1561 m_fftModels.erase(v); |
1562 } | 1562 } |
1563 } | 1563 } |
1564 | 1564 |
1565 if (m_fftAdapters.find(v) == m_fftAdapters.end()) { | 1565 if (m_fftModels.find(v) == m_fftModels.end()) { |
1566 m_fftAdapters[v] = FFTFillPair | 1566 m_fftModels[v] = FFTFillPair |
1567 (new FFTFuzzyAdapter(m_model, | 1567 (new FFTModel(m_model, |
1568 m_channel, | 1568 m_channel, |
1569 m_windowType, | 1569 m_windowType, |
1570 m_windowSize, | 1570 m_windowSize, |
1571 getWindowIncrement(), | 1571 getWindowIncrement(), |
1572 fftSize, | 1572 fftSize, |
1579 connect(m_updateTimer, SIGNAL(timeout()), | 1579 connect(m_updateTimer, SIGNAL(timeout()), |
1580 this, SLOT(fillTimerTimedOut())); | 1580 this, SLOT(fillTimerTimedOut())); |
1581 m_updateTimer->start(200); | 1581 m_updateTimer->start(200); |
1582 } | 1582 } |
1583 | 1583 |
1584 return m_fftAdapters[v].first; | 1584 return m_fftModels[v].first; |
1585 } | 1585 } |
1586 | 1586 |
1587 void | 1587 void |
1588 SpectrogramLayer::invalidateFFTAdapters() | 1588 SpectrogramLayer::invalidateFFTModels() |
1589 { | 1589 { |
1590 for (ViewFFTMap::iterator i = m_fftAdapters.begin(); | 1590 for (ViewFFTMap::iterator i = m_fftModels.begin(); |
1591 i != m_fftAdapters.end(); ++i) { | 1591 i != m_fftModels.end(); ++i) { |
1592 delete i->second.first; | 1592 delete i->second.first; |
1593 } | 1593 } |
1594 | 1594 |
1595 m_fftAdapters.clear(); | 1595 m_fftModels.clear(); |
1596 } | 1596 } |
1597 | 1597 |
1598 void | 1598 void |
1599 SpectrogramLayer::invalidateMagnitudes() | 1599 SpectrogramLayer::invalidateMagnitudes() |
1600 { | 1600 { |
1671 // and accountable for when determining whether we need the cache | 1671 // and accountable for when determining whether we need the cache |
1672 // in the cache-fill thread above. | 1672 // in the cache-fill thread above. |
1673 m_dormancy[v] = false; | 1673 m_dormancy[v] = false; |
1674 | 1674 |
1675 size_t fftSize = getFFTSize(v); | 1675 size_t fftSize = getFFTSize(v); |
1676 FFTFuzzyAdapter *fft = getFFTAdapter(v); | 1676 FFTModel *fft = getFFTModel(v); |
1677 if (!fft) { | 1677 if (!fft) { |
1678 std::cerr << "ERROR: SpectrogramLayer::paint(): No FFT adapter, returning" << std::endl; | 1678 std::cerr << "ERROR: SpectrogramLayer::paint(): No FFT model, returning" << std::endl; |
1679 return; | 1679 return; |
1680 } | 1680 } |
1681 | 1681 |
1682 PixmapCache &cache = m_pixmapCaches[v]; | 1682 PixmapCache &cache = m_pixmapCaches[v]; |
1683 | 1683 |
2172 | 2172 |
2173 int | 2173 int |
2174 SpectrogramLayer::getCompletion(View *v) const | 2174 SpectrogramLayer::getCompletion(View *v) const |
2175 { | 2175 { |
2176 if (m_updateTimer == 0) return 100; | 2176 if (m_updateTimer == 0) return 100; |
2177 if (m_fftAdapters.find(v) == m_fftAdapters.end()) return 100; | 2177 if (m_fftModels.find(v) == m_fftModels.end()) return 100; |
2178 | 2178 |
2179 size_t completion = m_fftAdapters[v].first->getFillCompletion(); | 2179 size_t completion = m_fftModels[v].first->getCompletion(); |
2180 std::cerr << "SpectrogramLayer::getCompletion: completion = " << completion << std::endl; | 2180 std::cerr << "SpectrogramLayer::getCompletion: completion = " << completion << std::endl; |
2181 return completion; | 2181 return completion; |
2182 } | 2182 } |
2183 | 2183 |
2184 bool | 2184 bool |