Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1090:c8c747783110 spectrogram-minor-refactor
Cut over to using the renderer (though it's very incomplete) and fix some cache problems and pointer lifetime misunderstandings
author | Chris Cannam |
---|---|
date | Tue, 05 Jul 2016 17:48:26 +0100 |
parents | c8683d94442a |
children | ac10a087e045 |
comparison
equal
deleted
inserted
replaced
1089:c8683d94442a | 1090:c8c747783110 |
---|---|
50 | 50 |
51 #ifndef __GNUC__ | 51 #ifndef __GNUC__ |
52 #include <alloca.h> | 52 #include <alloca.h> |
53 #endif | 53 #endif |
54 | 54 |
55 #define DEBUG_SPECTROGRAM 1 | |
55 #define DEBUG_SPECTROGRAM_REPAINT 1 | 56 #define DEBUG_SPECTROGRAM_REPAINT 1 |
56 | 57 |
57 using namespace std; | 58 using namespace std; |
58 | 59 |
59 SpectrogramLayer::SpectrogramLayer(Configuration config) : | 60 SpectrogramLayer::SpectrogramLayer(Configuration config) : |
1156 | 1157 |
1157 return true; | 1158 return true; |
1158 } | 1159 } |
1159 | 1160 |
1160 double | 1161 double |
1161 SpectrogramLayer::getYForBin(LayerGeometryProvider *, double bin) const { | 1162 SpectrogramLayer::getYForBin(LayerGeometryProvider *, double) const { |
1162 //!!! not implemented | 1163 //!!! not implemented |
1163 throw std::logic_error("not implemented"); | 1164 throw std::logic_error("not implemented"); |
1164 } | 1165 } |
1165 | 1166 |
1166 double | 1167 double |
1523 | 1524 |
1524 ScrollableImageCache & | 1525 ScrollableImageCache & |
1525 SpectrogramLayer::getImageCacheReference(const LayerGeometryProvider *view) const | 1526 SpectrogramLayer::getImageCacheReference(const LayerGeometryProvider *view) const |
1526 { | 1527 { |
1527 if (m_imageCaches.find(view->getId()) == m_imageCaches.end()) { | 1528 if (m_imageCaches.find(view->getId()) == m_imageCaches.end()) { |
1528 m_imageCaches[view->getId()] = ScrollableImageCache(view); | 1529 m_imageCaches[view->getId()] = ScrollableImageCache(); |
1529 } | 1530 } |
1530 return m_imageCaches.at(view->getId()); | 1531 return m_imageCaches.at(view->getId()); |
1531 } | 1532 } |
1532 | 1533 |
1533 void | 1534 void |
1534 SpectrogramLayer::paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const | 1535 SpectrogramLayer::paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
1535 { | 1536 { |
1536 Colour3DPlotRenderer *renderer = getRenderer(v); | 1537 Colour3DPlotRenderer *renderer = getRenderer(v); |
1537 | 1538 |
1538 | 1539 //!!! not time-constrained for now |
1540 Colour3DPlotRenderer::RenderResult result = renderer->render(v, paint, rect); | |
1541 | |
1542 //!!! do | |
1543 (void)result; | |
1539 } | 1544 } |
1540 | 1545 |
1541 Colour3DPlotRenderer * | 1546 Colour3DPlotRenderer * |
1542 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const | 1547 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const |
1543 { | 1548 { |
1544 if (m_renderers.find(v->getId()) == m_renderers.end()) { | 1549 if (m_renderers.find(v->getId()) == m_renderers.end()) { |
1545 | 1550 |
1546 Colour3DPlotRenderer::Sources sources; | 1551 Colour3DPlotRenderer::Sources sources; |
1547 sources.geometryProvider = v; | |
1548 sources.verticalBinLayer = this; | 1552 sources.verticalBinLayer = this; |
1549 sources.source = m_fftModel; | 1553 sources.fft = getFFTModel(); |
1550 sources.peaks = m_peakCache; | 1554 sources.source = sources.fft; |
1551 sources.fft = m_fftModel; | 1555 sources.peaks = getPeakCache(); |
1552 | 1556 |
1553 ::ColourScale::Parameters cparams; | 1557 ::ColourScale::Parameters cparams; |
1554 //!!! todo | 1558 //!!! todo |
1555 | 1559 |
1556 Colour3DPlotRenderer::Parameters params; | 1560 Colour3DPlotRenderer::Parameters params; |
1586 | 1590 |
1587 if (isLayerDormant(v)) { | 1591 if (isLayerDormant(v)) { |
1588 SVDEBUG << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << endl; | 1592 SVDEBUG << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << endl; |
1589 } | 1593 } |
1590 | 1594 |
1591 // paintAlternative(v, paint, rect); | 1595 paintAlternative(v, paint, rect); |
1592 // return; | 1596 return; |
1593 | 1597 |
1594 //!!! | 1598 //!!! |
1595 | 1599 |
1596 // Need to do this even if !isLayerDormant, as that could mean v | 1600 // Need to do this even if !isLayerDormant, as that could mean v |
1597 // is not in the dormancy map at all -- we need it to be present | 1601 // is not in the dormancy map at all -- we need it to be present |
1669 | 1673 |
1670 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1674 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1671 cerr << "SpectrogramLayer: scrolling the image cache if applicable" << endl; | 1675 cerr << "SpectrogramLayer: scrolling the image cache if applicable" << endl; |
1672 #endif | 1676 #endif |
1673 | 1677 |
1674 cache.scrollTo(startFrame); | 1678 cache.scrollTo(v, startFrame); |
1675 | 1679 |
1676 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1680 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1677 cerr << "SpectrogramLayer: after scrolling, cache valid from " | 1681 cerr << "SpectrogramLayer: after scrolling, cache valid from " |
1678 << cache.getValidLeft() << " width " << cache.getValidWidth() | 1682 << cache.getValidLeft() << " width " << cache.getValidWidth() |
1679 << endl; | 1683 << endl; |
2593 getEffectiveMaxFrequency(), | 2597 getEffectiveMaxFrequency(), |
2594 m_frequencyScale == LogFrequencyScale); | 2598 m_frequencyScale == LogFrequencyScale); |
2595 } | 2599 } |
2596 | 2600 |
2597 int | 2601 int |
2598 SpectrogramLayer::getCompletion(LayerGeometryProvider *v) const | 2602 SpectrogramLayer::getCompletion(LayerGeometryProvider *) const |
2599 { | 2603 { |
2600 if (!m_fftModel) return 100; | 2604 if (!m_fftModel) return 100; |
2601 int completion = m_fftModel->getCompletion(); | 2605 int completion = m_fftModel->getCompletion(); |
2602 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2606 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2603 cerr << "SpectrogramLayer::getCompletion: completion = " << completion << endl; | 2607 cerr << "SpectrogramLayer::getCompletion: completion = " << completion << endl; |
2604 #endif | 2608 #endif |
2605 return completion; | 2609 return completion; |
2606 } | 2610 } |
2607 | 2611 |
2608 QString | 2612 QString |
2609 SpectrogramLayer::getError(LayerGeometryProvider *v) const | 2613 SpectrogramLayer::getError(LayerGeometryProvider *) const |
2610 { | 2614 { |
2611 const View *view = v->getView(); | |
2612 if (!m_fftModel) return ""; | 2615 if (!m_fftModel) return ""; |
2613 return m_fftModel->getError(); | 2616 return m_fftModel->getError(); |
2614 } | 2617 } |
2615 | 2618 |
2616 bool | 2619 bool |