Mercurial > hg > svgui
changeset 1065:85e49aa7fe77 spectrogram-minor-refactor
Fix possible crash when scrolling to end
author | Chris Cannam |
---|---|
date | Thu, 23 Jun 2016 08:46:20 +0100 |
parents | 77564d4fff43 |
children | c98a1fe7c7f5 |
files | layer/SpectrogramLayer.cpp |
diffstat | 1 files changed, 28 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Mon Jun 20 12:00:32 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Thu Jun 23 08:46:20 2016 +0100 @@ -2293,27 +2293,29 @@ } } } + + if (!pixelPeakColumn.empty()) { + for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin(); + pi != peakfreqs.end(); ++pi) { + + int bin = pi->first; + double freq = pi->second; + + if (bin < minbin) continue; + if (bin > maxbin) break; + + double value = pixelPeakColumn[bin - minbin]; + + double y = v->getYForFrequency + (freq, displayMinFreq, displayMaxFreq, logarithmic); + + int iy = int(y + 0.5); + if (iy < 0 || iy >= h) continue; + + m_drawBuffer.setPixel(x, iy, getDisplayValue(v, value)); + } + } - for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin(); - pi != peakfreqs.end(); ++pi) { - - int bin = pi->first; - double freq = pi->second; - - if (bin < minbin) continue; - if (bin > maxbin) break; - - double value = pixelPeakColumn[bin - minbin]; - - double y = v->getYForFrequency - (freq, displayMinFreq, displayMaxFreq, logarithmic); - - int iy = int(y + 0.5); - if (iy < 0 || iy >= h) continue; - - m_drawBuffer.setPixel(x, iy, getDisplayValue(v, value)); - } - if (haveTimeLimits) { if (columnCount >= minColumns) { auto t = chrono::steady_clock::now(); @@ -2560,10 +2562,12 @@ } } - for (int y = 0; y < h; ++y) { - m_drawBuffer.setPixel(x, - h-y-1, - getDisplayValue(v, pixelPeakColumn[y])); + if (!pixelPeakColumn.empty()) { + for (int y = 0; y < h; ++y) { + m_drawBuffer.setPixel(x, + h-y-1, + getDisplayValue(v, pixelPeakColumn[y])); + } } if (haveTimeLimits) {