comparison layer/SpectrogramLayer.cpp @ 1093:cd22f74dc159 spectrogram-minor-refactor

Use enums from origin classes
author Chris Cannam
date Thu, 07 Jul 2016 19:18:01 +0100
parents 9b826dd23c84
children 6288f1b5f49b
comparison
equal deleted inserted replaced
1092:9b826dd23c84 1093:cd22f74dc159
72 m_minFrequency(10), 72 m_minFrequency(10),
73 m_maxFrequency(8000), 73 m_maxFrequency(8000),
74 m_initialMaxFrequency(8000), 74 m_initialMaxFrequency(8000),
75 m_colourScale(ColourScale::LogColourScale), 75 m_colourScale(ColourScale::LogColourScale),
76 m_colourMap(0), 76 m_colourMap(0),
77 m_frequencyScale(LinearFrequencyScale), 77 m_binScale(Colour3DPlotRenderer::LinearBinScale),
78 m_binDisplay(AllBins), 78 m_binDisplay(Colour3DPlotRenderer::AllBins),
79 m_normalization(ColumnOp::NoNormalization), 79 m_normalization(ColumnOp::NoNormalization),
80 m_lastEmittedZoomStep(-1), 80 m_lastEmittedZoomStep(-1),
81 m_synchronous(false), 81 m_synchronous(false),
82 m_haveDetailedScale(false), 82 m_haveDetailedScale(false),
83 m_exiting(false), 83 m_exiting(false),
97 m_initialMaxFrequency = 1500; 97 m_initialMaxFrequency = 1500;
98 setMaxFrequency(1500); 98 setMaxFrequency(1500);
99 setMinFrequency(40); 99 setMinFrequency(40);
100 setColourScale(ColourScale::LinearColourScale); 100 setColourScale(ColourScale::LinearColourScale);
101 setColourMap(ColourMapper::Sunset); 101 setColourMap(ColourMapper::Sunset);
102 setFrequencyScale(LogFrequencyScale); 102 setBinScale(Colour3DPlotRenderer::LogBinScale);
103 colourConfigName = "spectrogram-melodic-colour"; 103 colourConfigName = "spectrogram-melodic-colour";
104 colourConfigDefault = int(ColourMapper::Sunset); 104 colourConfigDefault = int(ColourMapper::Sunset);
105 // setGain(20); 105 // setGain(20);
106 } else if (config == MelodicPeaks) { 106 } else if (config == MelodicPeaks) {
107 setWindowSize(4096); 107 setWindowSize(4096);
108 setWindowHopLevel(5); 108 setWindowHopLevel(5);
109 m_initialMaxFrequency = 2000; 109 m_initialMaxFrequency = 2000;
110 setMaxFrequency(2000); 110 setMaxFrequency(2000);
111 setMinFrequency(40); 111 setMinFrequency(40);
112 setFrequencyScale(LogFrequencyScale); 112 setBinScale(Colour3DPlotRenderer::LogBinScale);
113 setColourScale(ColourScale::LinearColourScale); 113 setColourScale(ColourScale::LinearColourScale);
114 setBinDisplay(PeakFrequencies); 114 setBinDisplay(Colour3DPlotRenderer::PeakFrequencies);
115 setNormalization(ColumnOp::NormalizeColumns); 115 setNormalization(ColumnOp::NormalizeColumns);
116 colourConfigName = "spectrogram-melodic-colour"; 116 colourConfigName = "spectrogram-melodic-colour";
117 colourConfigDefault = int(ColourMapper::Sunset); 117 colourConfigDefault = int(ColourMapper::Sunset);
118 } 118 }
119 119
343 343
344 } else if (name == "Frequency Scale") { 344 } else if (name == "Frequency Scale") {
345 345
346 *min = 0; 346 *min = 0;
347 *max = 1; 347 *max = 1;
348 *deflt = int(LinearFrequencyScale); 348 *deflt = int(Colour3DPlotRenderer::LinearBinScale);
349 val = (int)m_frequencyScale; 349 val = (int)m_binScale;
350 350
351 } else if (name == "Bin Display") { 351 } else if (name == "Bin Display") {
352 352
353 *min = 0; 353 *min = 0;
354 *max = 2; 354 *max = 2;
355 *deflt = int(AllBins); 355 *deflt = int(Colour3DPlotRenderer::AllBins);
356 val = (int)m_binDisplay; 356 val = (int)m_binDisplay;
357 357
358 } else if (name == "Normalization") { 358 } else if (name == "Normalization") {
359 359
360 *min = 0; 360 *min = 0;
543 case 4: setColourScale(ColourScale::PhaseColourScale); break; 543 case 4: setColourScale(ColourScale::PhaseColourScale); break;
544 } 544 }
545 } else if (name == "Frequency Scale") { 545 } else if (name == "Frequency Scale") {
546 switch (value) { 546 switch (value) {
547 default: 547 default:
548 case 0: setFrequencyScale(LinearFrequencyScale); break; 548 case 0: setBinScale(Colour3DPlotRenderer::LinearBinScale); break;
549 case 1: setFrequencyScale(LogFrequencyScale); break; 549 case 1: setBinScale(Colour3DPlotRenderer::LogBinScale); break;
550 } 550 }
551 } else if (name == "Bin Display") { 551 } else if (name == "Bin Display") {
552 switch (value) { 552 switch (value) {
553 default: 553 default:
554 case 0: setBinDisplay(AllBins); break; 554 case 0: setBinDisplay(Colour3DPlotRenderer::AllBins); break;
555 case 1: setBinDisplay(PeakBins); break; 555 case 1: setBinDisplay(Colour3DPlotRenderer::PeakBins); break;
556 case 2: setBinDisplay(PeakFrequencies); break; 556 case 2: setBinDisplay(Colour3DPlotRenderer::PeakFrequencies); break;
557 } 557 }
558 } else if (name == "Normalization") { 558 } else if (name == "Normalization") {
559 switch (value) { 559 switch (value) {
560 default: 560 default:
561 case 0: setNormalization(ColumnOp::NoNormalization); break; 561 case 0: setNormalization(ColumnOp::NoNormalization); break;
629 } 629 }
630 630
631 int 631 int
632 SpectrogramLayer::getFFTOversampling() const 632 SpectrogramLayer::getFFTOversampling() const
633 { 633 {
634 if (m_binDisplay != AllBins) { 634 if (m_binDisplay != Colour3DPlotRenderer::AllBins) {
635 return 1; 635 return 1;
636 } 636 }
637 637
638 Preferences::SpectrogramSmoothing smoothing = 638 Preferences::SpectrogramSmoothing smoothing =
639 Preferences::getInstance()->getSpectrogramSmoothing(); 639 Preferences::getInstance()->getSpectrogramSmoothing();
848 { 848 {
849 return m_colourMap; 849 return m_colourMap;
850 } 850 }
851 851
852 void 852 void
853 SpectrogramLayer::setFrequencyScale(FrequencyScale frequencyScale) 853 SpectrogramLayer::setBinScale(Colour3DPlotRenderer::BinScale binScale)
854 { 854 {
855 if (m_frequencyScale == frequencyScale) return; 855 if (m_binScale == binScale) return;
856 856
857 invalidateImageCaches(); 857 invalidateImageCaches();
858 m_frequencyScale = frequencyScale; 858 m_binScale = binScale;
859 859
860 emit layerParametersChanged(); 860 emit layerParametersChanged();
861 } 861 }
862 862
863 SpectrogramLayer::FrequencyScale 863 Colour3DPlotRenderer::BinScale
864 SpectrogramLayer::getFrequencyScale() const 864 SpectrogramLayer::getBinScale() const
865 { 865 {
866 return m_frequencyScale; 866 return m_binScale;
867 } 867 }
868 868
869 void 869 void
870 SpectrogramLayer::setBinDisplay(BinDisplay binDisplay) 870 SpectrogramLayer::setBinDisplay(Colour3DPlotRenderer::BinDisplay binDisplay)
871 { 871 {
872 if (m_binDisplay == binDisplay) return; 872 if (m_binDisplay == binDisplay) return;
873 873
874 invalidateImageCaches(); 874 invalidateImageCaches();
875 m_binDisplay = binDisplay; 875 m_binDisplay = binDisplay;
876 876
877 emit layerParametersChanged(); 877 emit layerParametersChanged();
878 } 878 }
879 879
880 SpectrogramLayer::BinDisplay 880 Colour3DPlotRenderer::BinDisplay
881 SpectrogramLayer::getBinDisplay() const 881 SpectrogramLayer::getBinDisplay() const
882 { 882 {
883 return m_binDisplay; 883 return m_binDisplay;
884 } 884 }
885 885
1148 1148
1149 sv_samplerate_t sr = m_model->getSampleRate(); 1149 sv_samplerate_t sr = m_model->getSampleRate();
1150 double minf = getEffectiveMinFrequency(); 1150 double minf = getEffectiveMinFrequency();
1151 double maxf = getEffectiveMaxFrequency(); 1151 double maxf = getEffectiveMaxFrequency();
1152 1152
1153 bool logarithmic = (m_frequencyScale == LogFrequencyScale); 1153 bool logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
1154 1154
1155 q0 = v->getFrequencyForY(y, minf, maxf, logarithmic); 1155 q0 = v->getFrequencyForY(y, minf, maxf, logarithmic);
1156 q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic); 1156 q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic);
1157 1157
1158 // Now map these on to ("proportions of") actual bins 1158 // Now map these on to ("proportions of") actual bins
1180 1180
1181 sv_samplerate_t sr = m_model->getSampleRate(); 1181 sv_samplerate_t sr = m_model->getSampleRate();
1182 double minf = getEffectiveMinFrequency(); 1182 double minf = getEffectiveMinFrequency();
1183 double maxf = getEffectiveMaxFrequency(); 1183 double maxf = getEffectiveMaxFrequency();
1184 1184
1185 bool logarithmic = (m_frequencyScale == LogFrequencyScale); 1185 bool logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
1186 1186
1187 double q = v->getFrequencyForY(y, minf, maxf, logarithmic); 1187 double q = v->getFrequencyForY(y, minf, maxf, logarithmic);
1188 1188
1189 // Now map on to ("proportions of") actual bins 1189 // Now map on to ("proportions of") actual bins
1190 1190
1282 1282
1283 sv_samplerate_t sr = m_model->getSampleRate(); 1283 sv_samplerate_t sr = m_model->getSampleRate();
1284 1284
1285 bool haveAdj = false; 1285 bool haveAdj = false;
1286 1286
1287 bool peaksOnly = (m_binDisplay == PeakBins || 1287 bool peaksOnly = (m_binDisplay == Colour3DPlotRenderer::PeakBins ||
1288 m_binDisplay == PeakFrequencies); 1288 m_binDisplay == Colour3DPlotRenderer::PeakFrequencies);
1289 1289
1290 for (int q = q0i; q <= q1i; ++q) { 1290 for (int q = q0i; q <= q1i; ++q) {
1291 1291
1292 for (int s = s0i; s <= s1i; ++s) { 1292 for (int s = s0i; s <= s1i; ++s) {
1293 1293
1537 } 1537 }
1538 1538
1539 void 1539 void
1540 SpectrogramLayer::paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const 1540 SpectrogramLayer::paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
1541 { 1541 {
1542 static int depth = 0;
1543
1542 Colour3DPlotRenderer *renderer = getRenderer(v); 1544 Colour3DPlotRenderer *renderer = getRenderer(v);
1543 1545
1544 if (m_synchronous) { 1546 if (m_synchronous) {
1545 (void)renderer->render(v, paint, rect); 1547 (void)renderer->render(v, paint, rect);
1546 return; 1548 return;
1547 } 1549 }
1550
1551 ++depth;
1552 cerr << "paint depth " << depth << endl;
1548 1553
1549 Colour3DPlotRenderer::RenderResult result = 1554 Colour3DPlotRenderer::RenderResult result =
1550 renderer->renderTimeConstrained(v, paint, rect); 1555 renderer->renderTimeConstrained(v, paint, rect);
1551 1556
1552 //!!! + mag range 1557 //!!! + mag range
1553 1558
1554 QRect rendered = result.rendered; 1559 QRect rendered = result.rendered;
1555 if (rendered == rect) return; 1560 if (rendered == rect) {
1561 cerr << "exiting paint depth " << depth << endl;
1562 --depth;
1563 return;
1564 }
1556 1565
1557 int rLeft = rendered.x(); 1566 int rLeft = rendered.x();
1558 int rRight = rendered.x() + rendered.width(); 1567 int rRight = rendered.x() + rendered.width();
1559 1568
1560 if (rLeft < rect.x()) { 1569 if (rLeft < rect.x()) {
1570 QRect areaRight(rRight, rect.y(), 1579 QRect areaRight(rRight, rect.y(),
1571 rect.x() + rect.width() - rRight, rect.height()); 1580 rect.x() + rect.width() - rRight, rect.height());
1572 1581
1573 bool updateLeft = (areaLeft.width() > 0); 1582 bool updateLeft = (areaLeft.width() > 0);
1574 bool updateRight = (areaRight.width() > 0); 1583 bool updateRight = (areaRight.width() > 0);
1575 1584
1576 if (updateLeft) { 1585 if (updateLeft) {
1577 if (updateRight) { 1586 if (updateRight) {
1578 if (areaLeft.width() > areaRight.width()) { 1587 if (areaLeft.width() > areaRight.width()) {
1588 cerr << "update left then right, widths "
1589 << areaLeft.width() << " and "
1590 << areaRight.width() << endl;
1579 v->updatePaintRect(areaLeft); 1591 v->updatePaintRect(areaLeft);
1580 v->updatePaintRect(areaRight); 1592 v->updatePaintRect(areaRight);
1581 } else { 1593 } else {
1594 cerr << "update right then left, widths "
1595 << areaLeft.width() << " and "
1596 << areaRight.width() << endl;
1582 v->updatePaintRect(areaRight); 1597 v->updatePaintRect(areaRight);
1583 v->updatePaintRect(areaLeft); 1598 v->updatePaintRect(areaLeft);
1584 } 1599 }
1585 } else { 1600 } else {
1601 cerr << "update left, width " << areaLeft.width() << endl;
1586 v->updatePaintRect(areaLeft); 1602 v->updatePaintRect(areaLeft);
1587 } 1603 }
1588 } else { 1604 } else {
1605 cerr << "update right, width " << areaRight.width() << endl;
1589 v->updatePaintRect(areaRight); 1606 v->updatePaintRect(areaRight);
1590 } 1607 }
1608
1609 cerr << "exiting paint depth " << depth << endl;
1610 --depth;
1591 } 1611 }
1592 1612
1593 Colour3DPlotRenderer * 1613 Colour3DPlotRenderer *
1594 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const 1614 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const
1595 { 1615 {
1602 sources.peaks = getPeakCache(); 1622 sources.peaks = getPeakCache();
1603 1623
1604 ColourScale::Parameters cparams; 1624 ColourScale::Parameters cparams;
1605 cparams.colourMap = m_colourMap; 1625 cparams.colourMap = m_colourMap;
1606 cparams.scale = m_colourScale; 1626 cparams.scale = m_colourScale;
1627 cparams.threshold = m_threshold;
1628 cparams.gain = m_gain;
1629
1630 if (m_colourScale != ColourScale::PhaseColourScale &&
1631 m_normalization == ColumnOp::NoNormalization) {
1632 cparams.gain *= 2.f / float(getFFTSize());
1633 }
1607 1634
1608 Colour3DPlotRenderer::Parameters params; 1635 Colour3DPlotRenderer::Parameters params;
1609 params.colourScale = ColourScale(cparams); 1636 params.colourScale = ColourScale(cparams);
1610 params.normalization = m_normalization; 1637 params.normalization = m_normalization;
1611 //!!! map properly: 1638 params.binDisplay = m_binDisplay;
1612 params.binDisplay = (Colour3DPlotRenderer::BinDisplay)(int)m_binDisplay; 1639 params.binScale = m_binScale;
1613 params.binScale = (Colour3DPlotRenderer::BinScale)(int)m_frequencyScale; 1640 params.alwaysOpaque = true;
1614 //!!! and the rest 1641 params.invertVertical = false;
1642
1643 Preferences::SpectrogramSmoothing smoothing =
1644 Preferences::getInstance()->getSpectrogramSmoothing();
1645 params.interpolate =
1646 (smoothing == Preferences::SpectrogramInterpolated ||
1647 smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated);
1615 1648
1616 m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params); 1649 m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params);
1617 } 1650 }
1618 1651
1619 return m_renderers[v->getId()]; 1652 return m_renderers[v->getId()];
1826 1859
1827 // cerr << "(giving actual minFreq " << minFreq << " and display minFreq " << displayMinFreq << ")" << endl; 1860 // cerr << "(giving actual minFreq " << minFreq << " and display minFreq " << displayMinFreq << ")" << endl;
1828 1861
1829 int increment = getWindowIncrement(); 1862 int increment = getWindowIncrement();
1830 1863
1831 bool logarithmic = (m_frequencyScale == LogFrequencyScale); 1864 bool logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
1832 1865
1833 MagnitudeRange overallMag = m_viewMags[v->getId()]; 1866 MagnitudeRange overallMag = m_viewMags[v->getId()];
1834 bool overallMagChanged = false; 1867 bool overallMagChanged = false;
1835 1868
1836 #ifdef DEBUG_SPECTROGRAM_REPAINT 1869 #ifdef DEBUG_SPECTROGRAM_REPAINT
1949 1982
1950 } else { 1983 } else {
1951 1984
1952 // neither limitation applies, so use a short soft limit 1985 // neither limitation applies, so use a short soft limit
1953 1986
1954 if (m_binDisplay == PeakFrequencies) { 1987 if (m_binDisplay == Colour3DPlotRenderer::PeakFrequencies) {
1955 softTimeLimit = 0.15; 1988 softTimeLimit = 0.15;
1956 } else { 1989 } else {
1957 softTimeLimit = 0.1; 1990 softTimeLimit = 0.1;
1958 } 1991 }
1959 } 1992 }
1960 1993
1961 if (m_binDisplay != PeakFrequencies) { 1994 if (m_binDisplay != Colour3DPlotRenderer::PeakFrequencies) {
1962 1995
1963 for (int y = 0; y < h; ++y) { 1996 for (int y = 0; y < h; ++y) {
1964 double q0 = 0, q1 = 0; 1997 double q0 = 0, q1 = 0;
1965 if (!getYBinRange(v, h-y-1, q0, q1)) { 1998 if (!getYBinRange(v, h-y-1, q0, q1)) {
1966 binfory[y] = -1; 1999 binfory[y] = -1;
2433 bool interpolate = false; 2466 bool interpolate = false;
2434 Preferences::SpectrogramSmoothing smoothing = 2467 Preferences::SpectrogramSmoothing smoothing =
2435 Preferences::getInstance()->getSpectrogramSmoothing(); 2468 Preferences::getInstance()->getSpectrogramSmoothing();
2436 if (smoothing == Preferences::SpectrogramInterpolated || 2469 if (smoothing == Preferences::SpectrogramInterpolated ||
2437 smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated) { 2470 smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated) {
2438 if (m_binDisplay != PeakBins && 2471 if (m_binDisplay != Colour3DPlotRenderer::PeakBins &&
2439 m_binDisplay != PeakFrequencies) { 2472 m_binDisplay != Colour3DPlotRenderer::PeakFrequencies) {
2440 interpolate = true; 2473 interpolate = true;
2441 } 2474 }
2442 } 2475 }
2443 2476
2444 int psx = -1; 2477 int psx = -1;
2523 2556
2524 if (m_colourScale != ColourScale::PhaseColourScale) { 2557 if (m_colourScale != ColourScale::PhaseColourScale) {
2525 column = ColumnOp::normalize(column, m_normalization); 2558 column = ColumnOp::normalize(column, m_normalization);
2526 } 2559 }
2527 2560
2528 if (m_binDisplay == PeakBins) { 2561 if (m_binDisplay == Colour3DPlotRenderer::PeakBins) {
2529 column = ColumnOp::peakPick(column); 2562 column = ColumnOp::peakPick(column);
2530 } 2563 }
2531 2564
2532 preparedColumn = 2565 preparedColumn =
2533 ColumnOp::distribute(ColumnOp::applyGain(column, m_gain), 2566 ColumnOp::distribute(ColumnOp::applyGain(column, m_gain),
2632 SpectrogramLayer::getYForFrequency(const LayerGeometryProvider *v, double frequency) const 2665 SpectrogramLayer::getYForFrequency(const LayerGeometryProvider *v, double frequency) const
2633 { 2666 {
2634 return v->getYForFrequency(frequency, 2667 return v->getYForFrequency(frequency,
2635 getEffectiveMinFrequency(), 2668 getEffectiveMinFrequency(),
2636 getEffectiveMaxFrequency(), 2669 getEffectiveMaxFrequency(),
2637 m_frequencyScale == LogFrequencyScale); 2670 m_binScale == Colour3DPlotRenderer::LogBinScale);
2638 } 2671 }
2639 2672
2640 double 2673 double
2641 SpectrogramLayer::getFrequencyForY(const LayerGeometryProvider *v, int y) const 2674 SpectrogramLayer::getFrequencyForY(const LayerGeometryProvider *v, int y) const
2642 { 2675 {
2643 return v->getFrequencyForY(y, 2676 return v->getFrequencyForY(y,
2644 getEffectiveMinFrequency(), 2677 getEffectiveMinFrequency(),
2645 getEffectiveMaxFrequency(), 2678 getEffectiveMaxFrequency(),
2646 m_frequencyScale == LogFrequencyScale); 2679 m_binScale == Colour3DPlotRenderer::LogBinScale);
2647 } 2680 }
2648 2681
2649 int 2682 int
2650 SpectrogramLayer::getCompletion(LayerGeometryProvider *) const 2683 SpectrogramLayer::getCompletion(LayerGeometryProvider *) const
2651 { 2684 {
2672 2705
2673 sv_samplerate_t sr = m_model->getSampleRate(); 2706 sv_samplerate_t sr = m_model->getSampleRate();
2674 min = double(sr) / getFFTSize(); 2707 min = double(sr) / getFFTSize();
2675 max = double(sr) / 2; 2708 max = double(sr) / 2;
2676 2709
2677 logarithmic = (m_frequencyScale == LogFrequencyScale); 2710 logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
2678 unit = "Hz"; 2711 unit = "Hz";
2679 return true; 2712 return true;
2680 } 2713 }
2681 2714
2682 bool 2715 bool
2915 haveValues = true; 2948 haveValues = true;
2916 } 2949 }
2917 2950
2918 QString adjFreqText = "", adjPitchText = ""; 2951 QString adjFreqText = "", adjPitchText = "";
2919 2952
2920 if (m_binDisplay == PeakFrequencies) { 2953 if (m_binDisplay == Colour3DPlotRenderer::PeakFrequencies) {
2921 2954
2922 if (!getAdjustedYBinSourceRange(v, x, y, freqMin, freqMax, 2955 if (!getAdjustedYBinSourceRange(v, x, y, freqMin, freqMax,
2923 adjFreqMin, adjFreqMax)) { 2956 adjFreqMin, adjFreqMax)) {
2924 return ""; 2957 return "";
2925 } 2958 }
3027 m_model->getSampleRate() / 2)); 3060 m_model->getSampleRate() / 2));
3028 3061
3029 int fw = paint.fontMetrics().width(tr("43Hz")); 3062 int fw = paint.fontMetrics().width(tr("43Hz"));
3030 if (tw < fw) tw = fw; 3063 if (tw < fw) tw = fw;
3031 3064
3032 int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); 3065 int tickw = (m_binScale == Colour3DPlotRenderer::LogBinScale ? 10 : 4);
3033 3066
3034 return cw + tickw + tw + 13; 3067 return cw + tickw + tw + 13;
3035 } 3068 }
3036 3069
3037 void 3070 void
3045 3078
3046 //!!! cache this? 3079 //!!! cache this?
3047 3080
3048 int h = rect.height(), w = rect.width(); 3081 int h = rect.height(), w = rect.width();
3049 3082
3050 int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); 3083 int tickw = (m_binScale == Colour3DPlotRenderer::LogBinScale ? 10 : 4);
3051 int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); 3084 int pkw = (m_binScale == Colour3DPlotRenderer::LogBinScale ? 10 : 0);
3052 3085
3053 int bins = getFFTSize() / 2; 3086 int bins = getFFTSize() / 2;
3054 sv_samplerate_t sr = m_model->getSampleRate(); 3087 sv_samplerate_t sr = m_model->getSampleRate();
3055 3088
3056 if (m_maxFrequency > 0) { 3089 if (m_maxFrequency > 0) {
3170 } 3203 }
3171 3204
3172 int freq = int((sr * bin) / getFFTSize()); 3205 int freq = int((sr * bin) / getFFTSize());
3173 3206
3174 if (py >= 0 && (vy - py) < textHeight - 1) { 3207 if (py >= 0 && (vy - py) < textHeight - 1) {
3175 if (m_frequencyScale == LinearFrequencyScale) { 3208 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) {
3176 paint.drawLine(w - tickw, h - vy, w, h - vy); 3209 paint.drawLine(w - tickw, h - vy, w, h - vy);
3177 } 3210 }
3178 continue; 3211 continue;
3179 } 3212 }
3180 3213
3188 } 3221 }
3189 3222
3190 py = vy; 3223 py = vy;
3191 } 3224 }
3192 3225
3193 if (m_frequencyScale == LogFrequencyScale) { 3226 if (m_binScale == Colour3DPlotRenderer::LogBinScale) {
3194 3227
3195 // piano keyboard 3228 // piano keyboard
3196 3229
3197 PianoScale().paintPianoVertical 3230 PianoScale().paintPianoVertical
3198 (v, paint, QRect(w - pkw - 1, 0, pkw, h), 3231 (v, paint, QRect(w - pkw - 1, 0, pkw, h),
3310 SpectrogramRangeMapper mapper(sr, getFFTSize()); 3343 SpectrogramRangeMapper mapper(sr, getFFTSize());
3311 double newdist = mapper.getValueForPosition(step); 3344 double newdist = mapper.getValueForPosition(step);
3312 3345
3313 double newmin, newmax; 3346 double newmin, newmax;
3314 3347
3315 if (m_frequencyScale == LogFrequencyScale) { 3348 if (m_binScale == Colour3DPlotRenderer::LogBinScale) {
3316 3349
3317 // need to pick newmin and newmax such that 3350 // need to pick newmin and newmax such that
3318 // 3351 //
3319 // (log(newmin) + log(newmax)) / 2 == logmid 3352 // (log(newmin) + log(newmax)) / 2 == logmid
3320 // and 3353 // and
3452 .arg(m_minFrequency) 3485 .arg(m_minFrequency)
3453 .arg(m_maxFrequency) 3486 .arg(m_maxFrequency)
3454 .arg(convertOutColourScale(m_colourScale)) 3487 .arg(convertOutColourScale(m_colourScale))
3455 .arg(m_colourMap) 3488 .arg(m_colourMap)
3456 .arg(m_colourRotation) 3489 .arg(m_colourRotation)
3457 .arg(m_frequencyScale) 3490 .arg(m_binScale)
3458 .arg(m_binDisplay); 3491 .arg(m_binDisplay);
3459 3492
3460 // New-style normalization attributes, allowing for more types of 3493 // New-style normalization attributes, allowing for more types of
3461 // normalization in future: write out the column normalization 3494 // normalization in future: write out the column normalization
3462 // type separately, and then whether we are normalizing visible 3495 // type separately, and then whether we are normalizing visible
3534 if (ok) setColourMap(colourMap); 3567 if (ok) setColourMap(colourMap);
3535 3568
3536 int colourRotation = attributes.value("colourRotation").toInt(&ok); 3569 int colourRotation = attributes.value("colourRotation").toInt(&ok);
3537 if (ok) setColourRotation(colourRotation); 3570 if (ok) setColourRotation(colourRotation);
3538 3571
3539 FrequencyScale frequencyScale = (FrequencyScale) 3572 Colour3DPlotRenderer::BinScale binScale = (Colour3DPlotRenderer::BinScale)
3540 attributes.value("frequencyScale").toInt(&ok); 3573 attributes.value("frequencyScale").toInt(&ok);
3541 if (ok) setFrequencyScale(frequencyScale); 3574 if (ok) setBinScale(binScale);
3542 3575
3543 BinDisplay binDisplay = (BinDisplay) 3576 Colour3DPlotRenderer::BinDisplay binDisplay = (Colour3DPlotRenderer::BinDisplay)
3544 attributes.value("binDisplay").toInt(&ok); 3577 attributes.value("binDisplay").toInt(&ok);
3545 if (ok) setBinDisplay(binDisplay); 3578 if (ok) setBinDisplay(binDisplay);
3546 3579
3547 bool haveNewStyleNormalization = false; 3580 bool haveNewStyleNormalization = false;
3548 3581