comparison view/View.cpp @ 325:90e10a236c44 further_alignment_faffing

...
author Chris Cannam
date Thu, 08 Nov 2007 16:18:36 +0000
parents 973a0272b712
children
comparison
equal deleted inserted replaced
324:1f67b110c1a3 325:90e10a236c44
286 } 286 }
287 287
288 long 288 long
289 View::getStartFrame() const 289 View::getStartFrame() const
290 { 290 {
291 return getFrameForX(0); 291 long frame = getFrameForX(0);
292 std::cerr << "View::getStartFrame: " << frame << std::endl;
293 return frame;
292 } 294 }
293 295
294 size_t 296 size_t
295 View::getEndFrame() const 297 View::getEndFrame() const
296 { 298 {
297 return getFrameForX(width()) - 1; 299 long frame = getFrameForX(width()) - 1;
300 std::cerr << "View::getEndFrame: " << frame << std::endl;
301 return frame;
298 } 302 }
299 303
300 void 304 void
301 View::setStartFrame(long f) 305 View::setStartFrame(long f)
302 { 306 {
334 } 338 }
335 339
336 int 340 int
337 View::getXForFrame(long frame) const 341 View::getXForFrame(long frame) const
338 { 342 {
339 return (frame - getStartFrame()) / m_zoomLevel; 343 if (frame >= 0) {
344 frame = alignToReference(frame);
345 }
346 long z = (long)m_zoomLevel;
347 frame = frame - m_centreFrame;
348 frame /= z;
349 return frame + (width()/2);
350
351 //!!! no
352 // return (frame - getStartFrame()) / m_zoomLevel;
340 } 353 }
341 354
342 long 355 long
343 View::getFrameForX(int x) const 356 View::getFrameForX(int x) const
344 { 357 {
358 // if we're aligned ->
359 // ask the reference view for the frame that corresponds to x ->
360 // map that back
361 // BUT! we don't have a reference view, only a reference model.
362
363 // hang on -- the reference view would always just use the zoom
364 // level -- that's what we'd do by default anyway
365
366 // so we use the zoom level to work it out and then map that back
367 // from the reference model
368
345 long z = (long)m_zoomLevel; 369 long z = (long)m_zoomLevel;
346 long frame = m_centreFrame - (width()/2) * z; 370 long frame = m_centreFrame - (width()/2) * z;
347 frame = (frame / z) * z; // this is start frame 371 frame = (frame / z) * z; // this is start frame
348 return frame + x * z; 372 frame = frame + x * z;
373 if (frame < 0) return frame;
374 else return alignFromReference(frame);
349 } 375 }
350 376
351 float 377 float
352 View::getYForFrequency(float frequency, 378 View::getYForFrequency(float frequency,
353 float minf, 379 float minf,
1125 } 1151 }
1126 1152
1127 size_t 1153 size_t
1128 View::alignFromReference(size_t f) const 1154 View::alignFromReference(size_t f) const
1129 { 1155 {
1130 if (!m_manager->getAlignMode()) return f; 1156 if (!m_manager || !m_manager->getAlignMode()) return f;
1131 Model *aligningModel = getAligningModel(); 1157 Model *aligningModel = getAligningModel();
1132 if (!aligningModel) return f; 1158 if (!aligningModel) return f;
1133 return aligningModel->alignFromReference(f); 1159 return aligningModel->alignFromReference(f);
1134 } 1160 }
1135 1161