comparison layer/SpectrogramLayer.cpp @ 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 ee01a4062747
comparison
equal deleted inserted replaced
1064:77564d4fff43 1065:85e49aa7fe77
2291 pixelPeakColumn[i] = std::max(pixelPeakColumn[i], 2291 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
2292 preparedColumn[i]); 2292 preparedColumn[i]);
2293 } 2293 }
2294 } 2294 }
2295 } 2295 }
2296
2297 if (!pixelPeakColumn.empty()) {
2298 for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin();
2299 pi != peakfreqs.end(); ++pi) {
2300
2301 int bin = pi->first;
2302 double freq = pi->second;
2303
2304 if (bin < minbin) continue;
2305 if (bin > maxbin) break;
2306
2307 double value = pixelPeakColumn[bin - minbin];
2308
2309 double y = v->getYForFrequency
2310 (freq, displayMinFreq, displayMaxFreq, logarithmic);
2311
2312 int iy = int(y + 0.5);
2313 if (iy < 0 || iy >= h) continue;
2314
2315 m_drawBuffer.setPixel(x, iy, getDisplayValue(v, value));
2316 }
2317 }
2296 2318
2297 for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin();
2298 pi != peakfreqs.end(); ++pi) {
2299
2300 int bin = pi->first;
2301 double freq = pi->second;
2302
2303 if (bin < minbin) continue;
2304 if (bin > maxbin) break;
2305
2306 double value = pixelPeakColumn[bin - minbin];
2307
2308 double y = v->getYForFrequency
2309 (freq, displayMinFreq, displayMaxFreq, logarithmic);
2310
2311 int iy = int(y + 0.5);
2312 if (iy < 0 || iy >= h) continue;
2313
2314 m_drawBuffer.setPixel(x, iy, getDisplayValue(v, value));
2315 }
2316
2317 if (haveTimeLimits) { 2319 if (haveTimeLimits) {
2318 if (columnCount >= minColumns) { 2320 if (columnCount >= minColumns) {
2319 auto t = chrono::steady_clock::now(); 2321 auto t = chrono::steady_clock::now();
2320 double diff = chrono::duration<double>(t - startTime).count(); 2322 double diff = chrono::duration<double>(t - startTime).count();
2321 if (diff > hardTimeLimit) { 2323 if (diff > hardTimeLimit) {
2558 preparedColumn[i]); 2560 preparedColumn[i]);
2559 } 2561 }
2560 } 2562 }
2561 } 2563 }
2562 2564
2563 for (int y = 0; y < h; ++y) { 2565 if (!pixelPeakColumn.empty()) {
2564 m_drawBuffer.setPixel(x, 2566 for (int y = 0; y < h; ++y) {
2565 h-y-1, 2567 m_drawBuffer.setPixel(x,
2566 getDisplayValue(v, pixelPeakColumn[y])); 2568 h-y-1,
2569 getDisplayValue(v, pixelPeakColumn[y]));
2570 }
2567 } 2571 }
2568 2572
2569 if (haveTimeLimits) { 2573 if (haveTimeLimits) {
2570 if (columnCount >= minColumns) { 2574 if (columnCount >= minColumns) {
2571 auto t = chrono::steady_clock::now(); 2575 auto t = chrono::steady_clock::now();