comparison layer/TimeValueLayer.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
186 SparseTimeValueModel::PointList 186 SparseTimeValueModel::PointList
187 TimeValueLayer::getLocalPoints(int x) const 187 TimeValueLayer::getLocalPoints(int x) const
188 { 188 {
189 if (!m_model) return SparseTimeValueModel::PointList(); 189 if (!m_model) return SparseTimeValueModel::PointList();
190 190
191 long startFrame = m_view->getStartFrame(); 191 long frame = getFrameForX(x);
192 long endFrame = m_view->getEndFrame();
193 int zoomLevel = m_view->getZoomLevel();
194 long frame = startFrame + x * zoomLevel;
195 192
196 SparseTimeValueModel::PointList onPoints = 193 SparseTimeValueModel::PointList onPoints =
197 m_model->getPoints(frame); 194 m_model->getPoints(frame);
198 195
199 if (!onPoints.empty()) { 196 if (!onPoints.empty()) {
207 204
208 SparseTimeValueModel::PointList usePoints = prevPoints; 205 SparseTimeValueModel::PointList usePoints = prevPoints;
209 206
210 if (prevPoints.empty()) { 207 if (prevPoints.empty()) {
211 usePoints = nextPoints; 208 usePoints = nextPoints;
212 } else if (prevPoints.begin()->frame < startFrame && 209 } else if (prevPoints.begin()->frame < m_view->getStartFrame() &&
213 !(nextPoints.begin()->frame > endFrame)) { 210 !(nextPoints.begin()->frame > m_view->getEndFrame())) {
214 usePoints = nextPoints; 211 usePoints = nextPoints;
215 } else if (nextPoints.begin()->frame - frame < 212 } else if (nextPoints.begin()->frame - frame <
216 frame - prevPoints.begin()->frame) { 213 frame - prevPoints.begin()->frame) {
217 usePoints = nextPoints; 214 usePoints = nextPoints;
218 } 215 }
308 int sampleRate = m_model->getSampleRate(); 305 int sampleRate = m_model->getSampleRate();
309 if (!sampleRate) return; 306 if (!sampleRate) return;
310 307
311 // Profiler profiler("TimeValueLayer::paint", true); 308 // Profiler profiler("TimeValueLayer::paint", true);
312 309
313 long startFrame = m_view->getStartFrame();
314 int zoomLevel = m_view->getZoomLevel();
315
316 int x0 = rect.left(), x1 = rect.right(); 310 int x0 = rect.left(), x1 = rect.right();
317 long frame0 = startFrame + x0 * zoomLevel; 311 long frame0 = getFrameForX(x0);
318 long frame1 = startFrame + x1 * zoomLevel; 312 long frame1 = getFrameForX(x1);
319 313
320 SparseTimeValueModel::PointList points(m_model->getPoints 314 SparseTimeValueModel::PointList points(m_model->getPoints
321 (frame0, frame1)); 315 (frame0, frame1));
322 if (points.empty()) return; 316 if (points.empty()) return;
323 317
344 SparseTimeValueModel::PointList localPoints = 338 SparseTimeValueModel::PointList localPoints =
345 getLocalPoints(localPos.x()); 339 getLocalPoints(localPos.x());
346 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; 340 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
347 } 341 }
348 342
349 int w = m_model->getResolution() / zoomLevel; 343 int w =
344 getXForFrame(frame0 + m_model->getResolution()) -
345 getXForFrame(frame0);
350 346
351 paint.save(); 347 paint.save();
352 348
353 if (w > 1 && 349 if (w > 1 &&
354 (m_plotStyle == PlotLines || 350 (m_plotStyle == PlotLines ||
360 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); 356 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
361 i != points.end(); ++i) { 357 i != points.end(); ++i) {
362 358
363 const SparseTimeValueModel::Point &p(*i); 359 const SparseTimeValueModel::Point &p(*i);
364 360
365 int x = (p.frame - startFrame) / zoomLevel; 361 int x = getXForFrame(p.frame);
366 int y = int(nearbyint(m_view->height() - 362 int y = int(nearbyint(m_view->height() -
367 ((p.value - min) * m_view->height()) / 363 ((p.value - min) * m_view->height()) /
368 (max - min))); 364 (max - min)));
369 365
370 if (w < 1) w = 1; 366 if (w < 1) w = 1;
417 ++j; 413 ++j;
418 414
419 if (j != points.end()) { 415 if (j != points.end()) {
420 416
421 const SparseTimeValueModel::Point &q(*j); 417 const SparseTimeValueModel::Point &q(*j);
422 int nx = (q.frame - startFrame) / zoomLevel; 418 int nx = getXForFrame(q.frame);
423 int ny = int(nearbyint(m_view->height() - 419 int ny = int(nearbyint(m_view->height() -
424 ((q.value - min) * m_view->height()) / 420 ((q.value - min) * m_view->height()) /
425 (max - min))); 421 (max - min)));
426 422
427 if (m_plotStyle == PlotConnectedPoints) { 423 if (m_plotStyle == PlotConnectedPoints) {