Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 517:1c6439ef99d6
* "ffwd-similar"
* stop when ffwding to end
author | Chris Cannam |
---|---|
date | Tue, 03 Mar 2009 21:48:03 +0000 |
parents | ff1dc4f302bd |
children | e60e6fccfe4e |
comparison
equal
deleted
inserted
replaced
516:e4e0ae491a48 | 517:1c6439ef99d6 |
---|---|
603 | 603 |
604 frame = snapped; | 604 frame = snapped; |
605 return found; | 605 return found; |
606 } | 606 } |
607 | 607 |
608 bool | |
609 TimeValueLayer::snapToSimilarFeature(View *v, int &frame, | |
610 size_t &resolution, | |
611 SnapType snap) const | |
612 { | |
613 if (!m_model) { | |
614 return Layer::snapToSimilarFeature(v, frame, resolution, snap); | |
615 } | |
616 | |
617 resolution = m_model->getResolution(); | |
618 | |
619 const SparseTimeValueModel::PointList &points = m_model->getPoints(); | |
620 SparseTimeValueModel::PointList close = m_model->getPoints(frame, frame); | |
621 | |
622 SparseTimeValueModel::PointList::const_iterator i; | |
623 | |
624 int matchframe = frame; | |
625 float matchvalue = 0.f; | |
626 | |
627 for (i = close.begin(); i != close.end(); ++i) { | |
628 if (i->frame > frame) break; | |
629 matchvalue = i->value; | |
630 matchframe = i->frame; | |
631 } | |
632 | |
633 int snapped = frame; | |
634 bool found = false; | |
635 bool distant = false; | |
636 float epsilon = 0.0001; | |
637 | |
638 i = close.begin(); | |
639 | |
640 // Scan through the close points first, then the more distant ones | |
641 // if no suitable close one is found | |
642 | |
643 while (i != points.end()) { | |
644 | |
645 if (i == close.end()) { | |
646 i = points.begin(); | |
647 distant = true; | |
648 } | |
649 | |
650 if (snap == SnapRight) { | |
651 | |
652 if (i->frame > matchframe && | |
653 fabsf(i->value - matchvalue) < epsilon) { | |
654 snapped = i->frame; | |
655 found = true; | |
656 break; | |
657 } | |
658 | |
659 } else if (snap == SnapLeft) { | |
660 | |
661 if (i->frame < matchframe) { | |
662 if (fabsf(i->value - matchvalue) < epsilon) { | |
663 snapped = i->frame; | |
664 found = true; // don't break, as the next may be better | |
665 } | |
666 } else if (found || distant) { | |
667 break; | |
668 } | |
669 | |
670 } else { | |
671 // no other snap types supported | |
672 } | |
673 | |
674 ++i; | |
675 } | |
676 | |
677 frame = snapped; | |
678 return found; | |
679 } | |
680 | |
608 void | 681 void |
609 TimeValueLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const | 682 TimeValueLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const |
610 { | 683 { |
611 min = 0.0; | 684 min = 0.0; |
612 max = 0.0; | 685 max = 0.0; |