comparison view/View.cpp @ 946:36cddc3de023 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:19:52 +0100
parents 4a578a360011
children 59e51842cf39
comparison
equal deleted inserted replaced
897:499b637f2a26 946:36cddc3de023
162 } 162 }
163 163
164 int 164 int
165 View::getPropertyContainerCount() const 165 View::getPropertyContainerCount() const
166 { 166 {
167 return m_fixedOrderLayers.size() + 1; // the 1 is for me 167 return int(m_fixedOrderLayers.size()) + 1; // the 1 is for me
168 } 168 }
169 169
170 const PropertyContainer * 170 const PropertyContainer *
171 View::getPropertyContainer(int i) const 171 View::getPropertyContainer(int i) const
172 { 172 {
180 if (i == 0) return m_propertyContainer; 180 if (i == 0) return m_propertyContainer;
181 return m_fixedOrderLayers[i-1]; 181 return m_fixedOrderLayers[i-1];
182 } 182 }
183 183
184 bool 184 bool
185 View::getValueExtents(QString unit, float &min, float &max, bool &log) const 185 View::getValueExtents(QString unit, double &min, double &max, bool &log) const
186 { 186 {
187 bool have = false; 187 bool have = false;
188 188
189 for (LayerList::const_iterator i = m_layerStack.begin(); 189 for (LayerList::const_iterator i = m_layerStack.begin();
190 i != m_layerStack.end(); ++i) { 190 i != m_layerStack.end(); ++i) {
191 191
192 QString layerUnit; 192 QString layerUnit;
193 float layerMin = 0.0, layerMax = 0.0; 193 double layerMin = 0.0, layerMax = 0.0;
194 float displayMin = 0.0, displayMax = 0.0; 194 double displayMin = 0.0, displayMax = 0.0;
195 bool layerLog = false; 195 bool layerLog = false;
196 196
197 if ((*i)->getValueExtents(layerMin, layerMax, layerLog, layerUnit) && 197 if ((*i)->getValueExtents(layerMin, layerMax, layerLog, layerUnit) &&
198 layerUnit.toLower() == unit.toLower()) { 198 layerUnit.toLower() == unit.toLower()) {
199 199
296 View::zoomWheelsEnabledChanged() 296 View::zoomWheelsEnabledChanged()
297 { 297 {
298 // subclass might override this 298 // subclass might override this
299 } 299 }
300 300
301 int 301 sv_frame_t
302 View::getStartFrame() const 302 View::getStartFrame() const
303 { 303 {
304 return getFrameForX(0); 304 return getFrameForX(0);
305 } 305 }
306 306
307 int 307 sv_frame_t
308 View::getEndFrame() const 308 View::getEndFrame() const
309 { 309 {
310 return getFrameForX(width()) - 1; 310 return getFrameForX(width()) - 1;
311 } 311 }
312 312
313 void 313 void
314 View::setStartFrame(int f) 314 View::setStartFrame(sv_frame_t f)
315 { 315 {
316 setCentreFrame(f + m_zoomLevel * (width() / 2)); 316 setCentreFrame(f + m_zoomLevel * (width() / 2));
317 } 317 }
318 318
319 bool 319 bool
320 View::setCentreFrame(int f, bool e) 320 View::setCentreFrame(sv_frame_t f, bool e)
321 { 321 {
322 bool changeVisible = false; 322 bool changeVisible = false;
323 323
324 if (m_centreFrame != f) { 324 if (m_centreFrame != f) {
325 325
326 int formerPixel = m_centreFrame / m_zoomLevel; 326 int formerPixel = int(m_centreFrame / m_zoomLevel);
327 327
328 m_centreFrame = f; 328 m_centreFrame = f;
329 329
330 int newPixel = m_centreFrame / m_zoomLevel; 330 int newPixel = int(m_centreFrame / m_zoomLevel);
331 331
332 if (newPixel != formerPixel) { 332 if (newPixel != formerPixel) {
333 333
334 #ifdef DEBUG_VIEW_WIDGET_PAINT 334 #ifdef DEBUG_VIEW_WIDGET_PAINT
335 cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << endl; 335 cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << endl;
338 338
339 changeVisible = true; 339 changeVisible = true;
340 } 340 }
341 341
342 if (e) { 342 if (e) {
343 int rf = alignToReference(f); 343 sv_frame_t rf = alignToReference(f);
344 #ifdef DEBUG_VIEW 344 #ifdef DEBUG_VIEW
345 cerr << "View[" << this << "]::setCentreFrame(" << f 345 cerr << "View[" << this << "]::setCentreFrame(" << f
346 << "): emitting centreFrameChanged(" 346 << "): emitting centreFrameChanged("
347 << rf << ")" << endl; 347 << rf << ")" << endl;
348 #endif 348 #endif
352 352
353 return changeVisible; 353 return changeVisible;
354 } 354 }
355 355
356 int 356 int
357 View::getXForFrame(int frame) const 357 View::getXForFrame(sv_frame_t frame) const
358 { 358 {
359 return (frame - getStartFrame()) / m_zoomLevel; 359 return int((frame - getStartFrame()) / m_zoomLevel);
360 } 360 }
361 361
362 int 362 sv_frame_t
363 View::getFrameForX(int x) const 363 View::getFrameForX(int x) const
364 { 364 {
365 int z = m_zoomLevel; 365 int z = m_zoomLevel;
366 int frame = m_centreFrame - (width()/2) * z; 366 sv_frame_t frame = m_centreFrame - (width()/2) * z;
367 367
368 #ifdef DEBUG_VIEW_WIDGET_PAINT 368 #ifdef DEBUG_VIEW_WIDGET_PAINT
369 SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; 369 SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl;
370 #endif 370 #endif
371 371
372 frame = (frame / z) * z; // this is start frame 372 frame = (frame / z) * z; // this is start frame
373 return frame + x * z; 373 return frame + x * z;
374 } 374 }
375 375
376 float 376 double
377 View::getYForFrequency(float frequency, 377 View::getYForFrequency(double frequency,
378 float minf, 378 double minf,
379 float maxf, 379 double maxf,
380 bool logarithmic) const 380 bool logarithmic) const
381 { 381 {
382 Profiler profiler("View::getYForFrequency"); 382 Profiler profiler("View::getYForFrequency");
383 383
384 int h = height(); 384 int h = height();
385 385
386 if (logarithmic) { 386 if (logarithmic) {
387 387
388 static float lastminf = 0.0, lastmaxf = 0.0; 388 static double lastminf = 0.0, lastmaxf = 0.0;
389 static float logminf = 0.0, logmaxf = 0.0; 389 static double logminf = 0.0, logmaxf = 0.0;
390 390
391 if (lastminf != minf) { 391 if (lastminf != minf) {
392 lastminf = (minf == 0.0 ? 1.0 : minf); 392 lastminf = (minf == 0.0 ? 1.0 : minf);
393 logminf = log10f(minf); 393 logminf = log10(minf);
394 } 394 }
395 if (lastmaxf != maxf) { 395 if (lastmaxf != maxf) {
396 lastmaxf = (maxf < lastminf ? lastminf : maxf); 396 lastmaxf = (maxf < lastminf ? lastminf : maxf);
397 logmaxf = log10f(maxf); 397 logmaxf = log10(maxf);
398 } 398 }
399 399
400 if (logminf == logmaxf) return 0; 400 if (logminf == logmaxf) return 0;
401 return h - (h * (log10f(frequency) - logminf)) / (logmaxf - logminf); 401 return h - (h * (log10(frequency) - logminf)) / (logmaxf - logminf);
402 402
403 } else { 403 } else {
404 404
405 if (minf == maxf) return 0; 405 if (minf == maxf) return 0;
406 return h - (h * (frequency - minf)) / (maxf - minf); 406 return h - (h * (frequency - minf)) / (maxf - minf);
407 } 407 }
408 } 408 }
409 409
410 float 410 double
411 View::getFrequencyForY(int y, 411 View::getFrequencyForY(int y,
412 float minf, 412 double minf,
413 float maxf, 413 double maxf,
414 bool logarithmic) const 414 bool logarithmic) const
415 { 415 {
416 int h = height(); 416 int h = height();
417 417
418 if (logarithmic) { 418 if (logarithmic) {
419 419
420 static float lastminf = 0.0, lastmaxf = 0.0; 420 static double lastminf = 0.0, lastmaxf = 0.0;
421 static float logminf = 0.0, logmaxf = 0.0; 421 static double logminf = 0.0, logmaxf = 0.0;
422 422
423 if (lastminf != minf) { 423 if (lastminf != minf) {
424 lastminf = (minf == 0.0 ? 1.0 : minf); 424 lastminf = (minf == 0.0 ? 1.0 : minf);
425 logminf = log10f(minf); 425 logminf = log10(minf);
426 } 426 }
427 if (lastmaxf != maxf) { 427 if (lastmaxf != maxf) {
428 lastmaxf = (maxf < lastminf ? lastminf : maxf); 428 lastmaxf = (maxf < lastminf ? lastminf : maxf);
429 logmaxf = log10f(maxf); 429 logmaxf = log10(maxf);
430 } 430 }
431 431
432 if (logminf == logmaxf) return 0; 432 if (logminf == logmaxf) return 0;
433 return pow(10.f, logminf + ((logmaxf - logminf) * (h - y)) / h); 433 return pow(10.0, logminf + ((logmaxf - logminf) * (h - y)) / h);
434 434
435 } else { 435 } else {
436 436
437 if (minf == maxf) return 0; 437 if (minf == maxf) return 0;
438 return minf + ((h - y) * (maxf - minf)) / h; 438 return minf + ((h - y) * (maxf - minf)) / h;
578 this, SLOT(modelChanged())); 578 this, SLOT(modelChanged()));
579 connect(layer, SIGNAL(modelCompletionChanged()), 579 connect(layer, SIGNAL(modelCompletionChanged()),
580 this, SLOT(modelCompletionChanged())); 580 this, SLOT(modelCompletionChanged()));
581 connect(layer, SIGNAL(modelAlignmentCompletionChanged()), 581 connect(layer, SIGNAL(modelAlignmentCompletionChanged()),
582 this, SLOT(modelAlignmentCompletionChanged())); 582 this, SLOT(modelAlignmentCompletionChanged()));
583 connect(layer, SIGNAL(modelChangedWithin(int, int)), 583 connect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
584 this, SLOT(modelChangedWithin(int, int))); 584 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
585 connect(layer, SIGNAL(modelReplaced()), 585 connect(layer, SIGNAL(modelReplaced()),
586 this, SLOT(modelReplaced())); 586 this, SLOT(modelReplaced()));
587 587
588 update(); 588 update();
589 589
634 this, SLOT(modelChanged())); 634 this, SLOT(modelChanged()));
635 disconnect(layer, SIGNAL(modelCompletionChanged()), 635 disconnect(layer, SIGNAL(modelCompletionChanged()),
636 this, SLOT(modelCompletionChanged())); 636 this, SLOT(modelCompletionChanged()));
637 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()), 637 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()),
638 this, SLOT(modelAlignmentCompletionChanged())); 638 this, SLOT(modelAlignmentCompletionChanged()));
639 disconnect(layer, SIGNAL(modelChangedWithin(int, int)), 639 disconnect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
640 this, SLOT(modelChangedWithin(int, int))); 640 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
641 disconnect(layer, SIGNAL(modelReplaced()), 641 disconnect(layer, SIGNAL(modelReplaced()),
642 this, SLOT(modelReplaced())); 642 this, SLOT(modelReplaced()));
643 643
644 update(); 644 update();
645 645
690 690
691 void 691 void
692 View::setViewManager(ViewManager *manager) 692 View::setViewManager(ViewManager *manager)
693 { 693 {
694 if (m_manager) { 694 if (m_manager) {
695 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(int))); 695 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t)));
696 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, int))); 696 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
697 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(int))); 697 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t)));
698 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool))); 698 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool)));
699 m_manager->disconnect(this, SLOT(toolModeChanged())); 699 m_manager->disconnect(this, SLOT(toolModeChanged()));
700 m_manager->disconnect(this, SLOT(selectionChanged())); 700 m_manager->disconnect(this, SLOT(selectionChanged()));
701 m_manager->disconnect(this, SLOT(overlayModeChanged())); 701 m_manager->disconnect(this, SLOT(overlayModeChanged()));
702 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged())); 702 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged()));
703 disconnect(m_manager, SLOT(viewCentreFrameChanged(int, bool, PlaybackFollowMode))); 703 disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode)));
704 disconnect(m_manager, SLOT(zoomLevelChanged(int, bool))); 704 disconnect(m_manager, SLOT(zoomLevelChanged(int, bool)));
705 } 705 }
706 706
707 m_manager = manager; 707 m_manager = manager;
708 708
709 connect(m_manager, SIGNAL(globalCentreFrameChanged(int)), 709 connect(m_manager, SIGNAL(globalCentreFrameChanged(sv_frame_t)),
710 this, SLOT(globalCentreFrameChanged(int))); 710 this, SLOT(globalCentreFrameChanged(sv_frame_t)));
711 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, int)), 711 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)),
712 this, SLOT(viewCentreFrameChanged(View *, int))); 712 this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
713 connect(m_manager, SIGNAL(playbackFrameChanged(int)), 713 connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)),
714 this, SLOT(viewManagerPlaybackFrameChanged(int))); 714 this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t)));
715 715
716 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)), 716 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)),
717 this, SLOT(viewZoomLevelChanged(View *, int, bool))); 717 this, SLOT(viewZoomLevelChanged(View *, int, bool)));
718 718
719 connect(m_manager, SIGNAL(toolModeChanged()), 719 connect(m_manager, SIGNAL(toolModeChanged()),
727 connect(m_manager, SIGNAL(showCentreLineChanged()), 727 connect(m_manager, SIGNAL(showCentreLineChanged()),
728 this, SLOT(overlayModeChanged())); 728 this, SLOT(overlayModeChanged()));
729 connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()), 729 connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()),
730 this, SLOT(zoomWheelsEnabledChanged())); 730 this, SLOT(zoomWheelsEnabledChanged()));
731 731
732 connect(this, SIGNAL(centreFrameChanged(int, bool, 732 connect(this, SIGNAL(centreFrameChanged(sv_frame_t, bool,
733 PlaybackFollowMode)), 733 PlaybackFollowMode)),
734 m_manager, SLOT(viewCentreFrameChanged(int, bool, 734 m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool,
735 PlaybackFollowMode))); 735 PlaybackFollowMode)));
736 736
737 connect(this, SIGNAL(zoomLevelChanged(int, bool)), 737 connect(this, SIGNAL(zoomLevelChanged(int, bool)),
738 m_manager, SLOT(viewZoomLevelChanged(int, bool))); 738 m_manager, SLOT(viewZoomLevelChanged(int, bool)));
739 739
761 761
762 toolModeChanged(); 762 toolModeChanged();
763 } 763 }
764 764
765 void 765 void
766 View::setViewManager(ViewManager *vm, int initialCentreFrame) 766 View::setViewManager(ViewManager *vm, sv_frame_t initialCentreFrame)
767 { 767 {
768 setViewManager(vm); 768 setViewManager(vm);
769 setCentreFrame(initialCentreFrame, false); 769 setCentreFrame(initialCentreFrame, false);
770 } 770 }
771 771
875 875
876 update(); 876 update();
877 } 877 }
878 878
879 void 879 void
880 View::modelChangedWithin(int startFrame, int endFrame) 880 View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
881 { 881 {
882 QObject *obj = sender(); 882 QObject *obj = sender();
883 883
884 int myStartFrame = getStartFrame(); 884 sv_frame_t myStartFrame = getStartFrame();
885 int myEndFrame = getEndFrame(); 885 sv_frame_t myEndFrame = getEndFrame();
886 886
887 #ifdef DEBUG_VIEW_WIDGET_PAINT 887 #ifdef DEBUG_VIEW_WIDGET_PAINT
888 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl; 888 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl;
889 #endif 889 #endif
890 890
891 if (myStartFrame > 0 && endFrame < int(myStartFrame)) { 891 if (myStartFrame > 0 && endFrame < myStartFrame) {
892 checkProgress(obj); 892 checkProgress(obj);
893 return; 893 return;
894 } 894 }
895 if (startFrame > myEndFrame) { 895 if (startFrame > myEndFrame) {
896 checkProgress(obj); 896 checkProgress(obj);
993 Layer *layer = dynamic_cast<Layer *>(sender()); 993 Layer *layer = dynamic_cast<Layer *>(sender());
994 if (layer) emit propertyContainerNameChanged(layer); 994 if (layer) emit propertyContainerNameChanged(layer);
995 } 995 }
996 996
997 void 997 void
998 View::globalCentreFrameChanged(int rf) 998 View::globalCentreFrameChanged(sv_frame_t rf)
999 { 999 {
1000 if (m_followPan) { 1000 if (m_followPan) {
1001 int f = alignFromReference(rf); 1001 sv_frame_t f = alignFromReference(rf);
1002 #ifdef DEBUG_VIEW 1002 #ifdef DEBUG_VIEW
1003 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf 1003 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf
1004 << "): setting centre frame to " << f << endl; 1004 << "): setting centre frame to " << f << endl;
1005 #endif 1005 #endif
1006 setCentreFrame(f, false); 1006 setCentreFrame(f, false);
1007 } 1007 }
1008 } 1008 }
1009 1009
1010 void 1010 void
1011 View::viewCentreFrameChanged(View *, int ) 1011 View::viewCentreFrameChanged(View *, sv_frame_t )
1012 { 1012 {
1013 // We do nothing with this, but a subclass might 1013 // We do nothing with this, but a subclass might
1014 } 1014 }
1015 1015
1016 void 1016 void
1017 View::viewManagerPlaybackFrameChanged(int f) 1017 View::viewManagerPlaybackFrameChanged(sv_frame_t f)
1018 { 1018 {
1019 if (m_manager) { 1019 if (m_manager) {
1020 if (sender() != m_manager) return; 1020 if (sender() != m_manager) return;
1021 } 1021 }
1022 1022
1032 1032
1033 movePlayPointer(f); 1033 movePlayPointer(f);
1034 } 1034 }
1035 1035
1036 void 1036 void
1037 View::movePlayPointer(int newFrame) 1037 View::movePlayPointer(sv_frame_t newFrame)
1038 { 1038 {
1039 #ifdef DEBUG_VIEW 1039 #ifdef DEBUG_VIEW
1040 cerr << "View(" << this << ")::movePlayPointer(" << newFrame << ")" << endl; 1040 cerr << "View(" << this << ")::movePlayPointer(" << newFrame << ")" << endl;
1041 #endif 1041 #endif
1042 1042
1043 if (m_playPointerFrame == newFrame) return; 1043 if (m_playPointerFrame == newFrame) return;
1044 bool visibleChange = 1044 bool visibleChange =
1045 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame)); 1045 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame));
1046 int oldPlayPointerFrame = m_playPointerFrame; 1046 sv_frame_t oldPlayPointerFrame = m_playPointerFrame;
1047 m_playPointerFrame = newFrame; 1047 m_playPointerFrame = newFrame;
1048 if (!visibleChange) return; 1048 if (!visibleChange) return;
1049 1049
1050 bool somethingGoingOn = 1050 bool somethingGoingOn =
1051 ((QApplication::mouseButtons() != Qt::NoButton) || 1051 ((QApplication::mouseButtons() != Qt::NoButton) ||
1079 } else { 1079 } else {
1080 1080
1081 int xold = getXForFrame(oldPlayPointerFrame); 1081 int xold = getXForFrame(oldPlayPointerFrame);
1082 update(xold - 4, 0, 9, height()); 1082 update(xold - 4, 0, 9, height());
1083 1083
1084 int w = getEndFrame() - getStartFrame(); 1084 sv_frame_t w = getEndFrame() - getStartFrame();
1085 w -= w/5; 1085 w -= w/5;
1086 int sf = (m_playPointerFrame / w) * w - w/8; 1086 sv_frame_t sf = (m_playPointerFrame / w) * w - w/8;
1087 1087
1088 if (m_manager && 1088 if (m_manager &&
1089 m_manager->isPlaying() && 1089 m_manager->isPlaying() &&
1090 m_manager->getPlaySelectionMode()) { 1090 m_manager->getPlaySelectionMode()) {
1091 MultiSelection::SelectionList selections = m_manager->getSelections(); 1091 MultiSelection::SelectionList selections = m_manager->getSelections();
1092 if (!selections.empty()) { 1092 if (!selections.empty()) {
1093 int selectionStart = selections.begin()->getStartFrame(); 1093 sv_frame_t selectionStart = selections.begin()->getStartFrame();
1094 if (sf < selectionStart - w / 10) { 1094 if (sf < selectionStart - w / 10) {
1095 sf = selectionStart - w / 10; 1095 sf = selectionStart - w / 10;
1096 } 1096 }
1097 } 1097 }
1098 } 1098 }
1122 } else if (somethingGoingOn) { 1122 } else if (somethingGoingOn) {
1123 m_followPlayIsDetached = true; 1123 m_followPlayIsDetached = true;
1124 } 1124 }
1125 1125
1126 if (!somethingGoingOn && shouldScroll) { 1126 if (!somethingGoingOn && shouldScroll) {
1127 int offset = getFrameForX(width()/2) - getStartFrame(); 1127 sv_frame_t offset = getFrameForX(width()/2) - getStartFrame();
1128 int newCentre = sf + offset; 1128 sv_frame_t newCentre = sf + offset;
1129 bool changed = setCentreFrame(newCentre, false); 1129 bool changed = setCentreFrame(newCentre, false);
1130 if (changed) { 1130 if (changed) {
1131 xold = getXForFrame(oldPlayPointerFrame); 1131 xold = getXForFrame(oldPlayPointerFrame);
1132 update(xold - 4, 0, 9, height()); 1132 update(xold - 4, 0, 9, height());
1133 } 1133 }
1166 m_selectionCached = false; 1166 m_selectionCached = false;
1167 } 1167 }
1168 update(); 1168 update();
1169 } 1169 }
1170 1170
1171 int 1171 sv_frame_t
1172 View::getFirstVisibleFrame() const 1172 View::getFirstVisibleFrame() const
1173 { 1173 {
1174 int f0 = getStartFrame(); 1174 sv_frame_t f0 = getStartFrame();
1175 int f = getModelsStartFrame(); 1175 sv_frame_t f = getModelsStartFrame();
1176 if (f0 < 0 || f0 < f) return f; 1176 if (f0 < 0 || f0 < f) return f;
1177 return f0; 1177 return f0;
1178 } 1178 }
1179 1179
1180 int 1180 sv_frame_t
1181 View::getLastVisibleFrame() const 1181 View::getLastVisibleFrame() const
1182 { 1182 {
1183 int f0 = getEndFrame(); 1183 sv_frame_t f0 = getEndFrame();
1184 int f = getModelsEndFrame(); 1184 sv_frame_t f = getModelsEndFrame();
1185 if (f0 > f) return f; 1185 if (f0 > f) return f;
1186 return f0; 1186 return f0;
1187 } 1187 }
1188 1188
1189 int 1189 sv_frame_t
1190 View::getModelsStartFrame() const 1190 View::getModelsStartFrame() const
1191 { 1191 {
1192 bool first = true; 1192 bool first = true;
1193 int startFrame = 0; 1193 sv_frame_t startFrame = 0;
1194 1194
1195 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1195 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1196 1196
1197 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1197 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1198 1198
1199 int thisStartFrame = (*i)->getModel()->getStartFrame(); 1199 sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame();
1200 1200
1201 if (first || thisStartFrame < startFrame) { 1201 if (first || thisStartFrame < startFrame) {
1202 startFrame = thisStartFrame; 1202 startFrame = thisStartFrame;
1203 } 1203 }
1204 first = false; 1204 first = false;
1205 } 1205 }
1206 } 1206 }
1207 return startFrame; 1207 return startFrame;
1208 } 1208 }
1209 1209
1210 int 1210 sv_frame_t
1211 View::getModelsEndFrame() const 1211 View::getModelsEndFrame() const
1212 { 1212 {
1213 bool first = true; 1213 bool first = true;
1214 int endFrame = 0; 1214 sv_frame_t endFrame = 0;
1215 1215
1216 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1216 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1217 1217
1218 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1218 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1219 1219
1220 int thisEndFrame = (*i)->getModel()->getEndFrame(); 1220 sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame();
1221 1221
1222 if (first || thisEndFrame > endFrame) { 1222 if (first || thisEndFrame > endFrame) {
1223 endFrame = thisEndFrame; 1223 endFrame = thisEndFrame;
1224 } 1224 }
1225 first = false; 1225 first = false;
1228 1228
1229 if (first) return getModelsStartFrame(); 1229 if (first) return getModelsStartFrame();
1230 return endFrame; 1230 return endFrame;
1231 } 1231 }
1232 1232
1233 int 1233 sv_samplerate_t
1234 View::getModelsSampleRate() const 1234 View::getModelsSampleRate() const
1235 { 1235 {
1236 //!!! Just go for the first, for now. If we were supporting 1236 //!!! Just go for the first, for now. If we were supporting
1237 // multiple samplerates, we'd probably want to do frame/time 1237 // multiple samplerates, we'd probably want to do frame/time
1238 // conversion in the model 1238 // conversion in the model
1307 if (goodModel) return goodModel; 1307 if (goodModel) return goodModel;
1308 else if (alignedModel) return alignedModel; 1308 else if (alignedModel) return alignedModel;
1309 else return anyModel; 1309 else return anyModel;
1310 } 1310 }
1311 1311
1312 int 1312 sv_frame_t
1313 View::alignFromReference(int f) const 1313 View::alignFromReference(sv_frame_t f) const
1314 { 1314 {
1315 if (!m_manager || !m_manager->getAlignMode()) return f; 1315 if (!m_manager || !m_manager->getAlignMode()) return f;
1316 Model *aligningModel = getAligningModel(); 1316 Model *aligningModel = getAligningModel();
1317 if (!aligningModel) return f; 1317 if (!aligningModel) return f;
1318 return aligningModel->alignFromReference(f); 1318 return aligningModel->alignFromReference(f);
1319 } 1319 }
1320 1320
1321 int 1321 sv_frame_t
1322 View::alignToReference(int f) const 1322 View::alignToReference(sv_frame_t f) const
1323 { 1323 {
1324 if (!m_manager->getAlignMode()) return f; 1324 if (!m_manager->getAlignMode()) return f;
1325 Model *aligningModel = getAligningModel(); 1325 Model *aligningModel = getAligningModel();
1326 if (!aligningModel) return f; 1326 if (!aligningModel) return f;
1327 return aligningModel->alignToReference(f); 1327 return aligningModel->alignToReference(f);
1328 } 1328 }
1329 1329
1330 int 1330 sv_frame_t
1331 View::getAlignedPlaybackFrame() const 1331 View::getAlignedPlaybackFrame() const
1332 { 1332 {
1333 if (!m_manager) return 0; 1333 if (!m_manager) return 0;
1334 int pf = m_manager->getPlaybackFrame(); 1334 sv_frame_t pf = m_manager->getPlaybackFrame();
1335 if (!m_manager->getAlignMode()) return pf; 1335 if (!m_manager->getAlignMode()) return pf;
1336 1336
1337 Model *aligningModel = getAligningModel(); 1337 Model *aligningModel = getAligningModel();
1338 if (!aligningModel) return pf; 1338 if (!aligningModel) return pf;
1339 1339
1340 int af = aligningModel->alignFromReference(pf); 1340 sv_frame_t af = aligningModel->alignFromReference(pf);
1341 1341
1342 return af; 1342 return af;
1343 } 1343 }
1344 1344
1345 bool 1345 bool
1490 } 1490 }
1491 1491
1492 void 1492 void
1493 View::scroll(bool right, bool lots, bool e) 1493 View::scroll(bool right, bool lots, bool e)
1494 { 1494 {
1495 int delta; 1495 sv_frame_t delta;
1496 if (lots) { 1496 if (lots) {
1497 delta = (getEndFrame() - getStartFrame()) / 2; 1497 delta = (getEndFrame() - getStartFrame()) / 2;
1498 } else { 1498 } else {
1499 delta = (getEndFrame() - getStartFrame()) / 20; 1499 delta = (getEndFrame() - getStartFrame()) / 20;
1500 } 1500 }
1501 if (right) delta = -delta; 1501 if (right) delta = -delta;
1502 1502
1503 if (int(m_centreFrame) < delta) { 1503 if (m_centreFrame < delta) {
1504 setCentreFrame(0, e); 1504 setCentreFrame(0, e);
1505 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { 1505 } else if (m_centreFrame - delta >= getModelsEndFrame()) {
1506 setCentreFrame(getModelsEndFrame(), e); 1506 setCentreFrame(getModelsEndFrame(), e);
1507 } else { 1507 } else {
1508 setCentreFrame(m_centreFrame - delta, e); 1508 setCentreFrame(m_centreFrame - delta, e);
1509 } 1509 }
1510 } 1510 }
1972 paint.setBrush(QColor(150, 150, 255, 80)); 1972 paint.setBrush(QColor(150, 150, 255, 80));
1973 } else { 1973 } else {
1974 paint.setBrush(Qt::NoBrush); 1974 paint.setBrush(Qt::NoBrush);
1975 } 1975 }
1976 1976
1977 int sampleRate = getModelsSampleRate(); 1977 sv_samplerate_t sampleRate = getModelsSampleRate();
1978 1978
1979 QPoint localPos; 1979 QPoint localPos;
1980 int illuminateFrame = -1; 1980 sv_frame_t illuminateFrame = -1;
1981 bool closeToLeft, closeToRight; 1981 bool closeToLeft, closeToRight;
1982 1982
1983 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) { 1983 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
1984 illuminateFrame = getFrameForX(localPos.x()); 1984 illuminateFrame = getFrameForX(localPos.x());
1985 } 1985 }
2143 } 2143 }
2144 2144
2145 int fontHeight = paint.fontMetrics().height(); 2145 int fontHeight = paint.fontMetrics().height();
2146 int fontAscent = paint.fontMetrics().ascent(); 2146 int fontAscent = paint.fontMetrics().ascent();
2147 2147
2148 float v0, v1; 2148 double v0, v1;
2149 QString u0, u1; 2149 QString u0, u1;
2150 bool b0 = false, b1 = false; 2150 bool b0 = false, b1 = false;
2151 2151
2152 QString axs, ays, bxs, bys, dxs, dys; 2152 QString axs, ays, bxs, bys, dxs, dys;
2153 2153
2215 bw = std::max(bw, paint.fontMetrics().width(bys)); 2215 bw = std::max(bw, paint.fontMetrics().width(bys));
2216 } 2216 }
2217 } 2217 }
2218 2218
2219 bool bd = false; 2219 bool bd = false;
2220 float dy = 0.f; 2220 double dy = 0.f;
2221 QString du; 2221 QString du;
2222 2222
2223 // dimension, height 2223 // dimension, height
2224 2224
2225 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(), 2225 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(),
2226 dy, du)) && 2226 dy, du)) &&
2227 dy != 0) { 2227 dy != 0) {
2228 if (du != "") { 2228 if (du != "") {
2229 if (du == "Hz") { 2229 if (du == "Hz") {
2230 int semis; 2230 int semis;
2231 float cents; 2231 double cents;
2232 semis = Pitch::getPitchForFrequencyDifference(v0, v1, &cents); 2232 semis = Pitch::getPitchForFrequencyDifference(v0, v1, &cents);
2233 dys = QString("[%1 %2 (%3)]") 2233 dys = QString("[%1 %2 (%3)]")
2234 .arg(dy).arg(du) 2234 .arg(dy).arg(du)
2235 .arg(Pitch::getLabelForPitchRange(semis, cents)); 2235 .arg(Pitch::getLabelForPitchRange(semis, cents));
2236 } else { 2236 } else {
2331 2331
2332 paint.restore(); 2332 paint.restore();
2333 } 2333 }
2334 2334
2335 bool 2335 bool
2336 View::render(QPainter &paint, int xorigin, int f0, int f1) 2336 View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
2337 { 2337 {
2338 int x0 = f0 / m_zoomLevel; 2338 int x0 = int(f0 / m_zoomLevel);
2339 int x1 = f1 / m_zoomLevel; 2339 int x1 = int(f1 / m_zoomLevel);
2340 2340
2341 int w = x1 - x0; 2341 int w = x1 - x0;
2342 2342
2343 int origCentreFrame = m_centreFrame; 2343 sv_frame_t origCentreFrame = m_centreFrame;
2344 2344
2345 bool someLayersIncomplete = false; 2345 bool someLayersIncomplete = false;
2346 2346
2347 for (LayerList::iterator i = m_layerStack.begin(); 2347 for (LayerList::iterator i = m_layerStack.begin();
2348 i != m_layerStack.end(); ++i) { 2348 i != m_layerStack.end(); ++i) {
2438 } 2438 }
2439 2439
2440 QImage * 2440 QImage *
2441 View::toNewImage() 2441 View::toNewImage()
2442 { 2442 {
2443 int f0 = getModelsStartFrame(); 2443 sv_frame_t f0 = getModelsStartFrame();
2444 int f1 = getModelsEndFrame(); 2444 sv_frame_t f1 = getModelsEndFrame();
2445 2445
2446 return toNewImage(f0, f1); 2446 return toNewImage(f0, f1);
2447 } 2447 }
2448 2448
2449 QImage * 2449 QImage *
2450 View::toNewImage(int f0, int f1) 2450 View::toNewImage(sv_frame_t f0, sv_frame_t f1)
2451 { 2451 {
2452 int x0 = f0 / getZoomLevel(); 2452 int x0 = int(f0 / getZoomLevel());
2453 int x1 = f1 / getZoomLevel(); 2453 int x1 = int(f1 / getZoomLevel());
2454 2454
2455 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); 2455 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
2456 2456
2457 QPainter *paint = new QPainter(image); 2457 QPainter *paint = new QPainter(image);
2458 if (!render(*paint, 0, f0, f1)) { 2458 if (!render(*paint, 0, f0, f1)) {
2466 } 2466 }
2467 2467
2468 QSize 2468 QSize
2469 View::getImageSize() 2469 View::getImageSize()
2470 { 2470 {
2471 int f0 = getModelsStartFrame(); 2471 sv_frame_t f0 = getModelsStartFrame();
2472 int f1 = getModelsEndFrame(); 2472 sv_frame_t f1 = getModelsEndFrame();
2473 2473
2474 return getImageSize(f0, f1); 2474 return getImageSize(f0, f1);
2475 } 2475 }
2476 2476
2477 QSize 2477 QSize
2478 View::getImageSize(int f0, int f1) 2478 View::getImageSize(sv_frame_t f0, sv_frame_t f1)
2479 { 2479 {
2480 int x0 = f0 / getZoomLevel(); 2480 int x0 = int(f0 / getZoomLevel());
2481 int x1 = f1 / getZoomLevel(); 2481 int x1 = int(f1 / getZoomLevel());
2482 2482
2483 return QSize(x1 - x0, height()); 2483 return QSize(x1 - x0, height());
2484 } 2484 }
2485 2485
2486 void 2486 void