comparison layer/SpectrogramLayer.cpp @ 20:1deb5f87a18c

* Add getXForFrame / getFrameForX in preference to using the zoom level everywhere
author Chris Cannam
date Mon, 30 Jan 2006 13:19:42 +0000
parents 01849cd277e6
children 3a506d25d95a
comparison
equal deleted inserted replaced
19:46d8f5add6f0 20:1deb5f87a18c
1099 1099
1100 return true; 1100 return true;
1101 } 1101 }
1102 1102
1103 bool 1103 bool
1104 SpectrogramLayer::getXBinRange(int x, float &s0, float &s1, LayerRange *range) const 1104 SpectrogramLayer::getXBinRange(int x, float &s0, float &s1) const
1105 { 1105 {
1106 long startFrame; 1106 // long startFrame;
1107 int zoomLevel; 1107 // int zoomLevel;
1108 size_t modelStart; 1108 size_t modelStart;
1109 size_t modelEnd; 1109 size_t modelEnd;
1110 1110
1111 if (range) { 1111 // startFrame = m_view->getStartFrame();
1112 startFrame = range->startFrame; 1112 // zoomLevel = m_view->getZoomLevel();
1113 zoomLevel = range->zoomLevel; 1113 modelStart = m_model->getStartFrame();
1114 modelStart = range->modelStart; 1114 modelEnd = m_model->getEndFrame();
1115 modelEnd = range->modelEnd;
1116 } else {
1117 startFrame = m_view->getStartFrame();
1118 zoomLevel = m_view->getZoomLevel();
1119 modelStart = m_model->getStartFrame();
1120 modelEnd = m_model->getEndFrame();
1121 }
1122 1115
1123 // Each pixel column covers an exact range of sample frames: 1116 // Each pixel column covers an exact range of sample frames:
1117 int f0 = getFrameForX(x) - modelStart;
1118 int f1 = getFrameForX(x + 1) - modelStart - 1;
1119
1120 /*
1124 int f0 = startFrame + x * zoomLevel - modelStart; 1121 int f0 = startFrame + x * zoomLevel - modelStart;
1125 int f1 = f0 + zoomLevel - 1; 1122 int f1 = f0 + zoomLevel - 1;
1126 1123 */
1127 if (f1 < int(modelStart) || f0 > int(modelEnd)) return false; 1124 if (f1 < int(modelStart) || f0 > int(modelEnd)) return false;
1128 1125
1129 // And that range may be drawn from a possibly non-integral 1126 // And that range may be drawn from a possibly non-integral
1130 // range of spectrogram windows: 1127 // range of spectrogram windows:
1131 1128
1132 size_t windowIncrement = getWindowIncrement(); 1129 size_t windowIncrement = getWindowIncrement();
1133 1130
1288 1285
1289 if (int(m_pixmapCacheZoomLevel) == zoomLevel && 1286 if (int(m_pixmapCacheZoomLevel) == zoomLevel &&
1290 m_pixmapCache->width() == m_view->width() && 1287 m_pixmapCache->width() == m_view->width() &&
1291 m_pixmapCache->height() == m_view->height()) { 1288 m_pixmapCache->height() == m_view->height()) {
1292 1289
1293 if (m_pixmapCacheStartFrame / zoomLevel == 1290 if (getXForFrame(m_pixmapCacheStartFrame) ==
1294 startFrame / zoomLevel) { 1291 getXForFrame(startFrame)) {
1295 1292
1296 #ifdef DEBUG_SPECTROGRAM_REPAINT 1293 #ifdef DEBUG_SPECTROGRAM_REPAINT
1297 std::cerr << "SpectrogramLayer: pixmap cache good" << std::endl; 1294 std::cerr << "SpectrogramLayer: pixmap cache good" << std::endl;
1298 #endif 1295 #endif
1299 1296
1307 std::cerr << "SpectrogramLayer: pixmap cache partially OK" << std::endl; 1304 std::cerr << "SpectrogramLayer: pixmap cache partially OK" << std::endl;
1308 #endif 1305 #endif
1309 1306
1310 recreateWholePixmapCache = false; 1307 recreateWholePixmapCache = false;
1311 1308
1312 int dx = (m_pixmapCacheStartFrame - startFrame) / zoomLevel; 1309 int dx = getXForFrame(m_pixmapCacheStartFrame) -
1310 getXForFrame(startFrame);
1313 1311
1314 #ifdef DEBUG_SPECTROGRAM_REPAINT 1312 #ifdef DEBUG_SPECTROGRAM_REPAINT
1315 std::cerr << "SpectrogramLayer: dx = " << dx << " (pixmap cache " << m_pixmapCache->width() << "x" << m_pixmapCache->height() << ")" << std::endl; 1313 std::cerr << "SpectrogramLayer: dx = " << dx << " (pixmap cache " << m_pixmapCache->width() << "x" << m_pixmapCache->height() << ")" << std::endl;
1316 #endif 1314 #endif
1317 1315
1375 1373
1376 // std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl; 1374 // std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl;
1377 1375
1378 QImage scaled(w, h, QImage::Format_RGB32); 1376 QImage scaled(w, h, QImage::Format_RGB32);
1379 1377
1380 LayerRange range = { m_view->getStartFrame(), m_view->getZoomLevel(),
1381 m_model->getStartFrame(), m_model->getEndFrame() };
1382
1383 m_mutex.unlock(); 1378 m_mutex.unlock();
1384 1379
1385 for (int y = 0; y < h; ++y) { 1380 for (int y = 0; y < h; ++y) {
1386 1381
1387 m_mutex.lock(); 1382 m_mutex.lock();
1409 1404
1410 for (int x = 0; x < w; ++x) { 1405 for (int x = 0; x < w; ++x) {
1411 1406
1412 float s0 = 0, s1 = 0; 1407 float s0 = 0, s1 = 0;
1413 1408
1414 if (!getXBinRange(x0 + x, s0, s1, &range)) { 1409 if (!getXBinRange(x0 + x, s0, s1)) {
1415 assert(x <= scaled.width()); 1410 assert(x <= scaled.width());
1416 scaled.setPixel(x, y, qRgb(0, 0, 0)); 1411 scaled.setPixel(x, y, qRgb(0, 0, 0));
1417 continue; 1412 continue;
1418 } 1413 }
1419 1414