Skip to content

Commit

Permalink
Merge pull request #5418 from MarcSabatella/296053-start-note-entry
Browse files Browse the repository at this point in the history
fix #296053: improve algorithm for determing start point for note input
  • Loading branch information
anatoly-os committed Oct 25, 2019
2 parents f4b32f4 + e7e17a7 commit 0c9804d
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 17 deletions.
5 changes: 5 additions & 0 deletions libmscore/spanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ qreal SpannerSegment::mag() const
return staff() ? staff()->mag(spanner()->tick()) : 1.0;
}

Fraction SpannerSegment::tick() const
{
return _spanner ? _spanner->tick() : Fraction(0, 1);
}

//---------------------------------------------------------
// setSystem
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/spanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SpannerSegment : public Element {
virtual SpannerSegment* clone() const = 0;

virtual qreal mag() const override;
virtual Fraction tick() const override;

Spanner* spanner() const { return _spanner; }
Spanner* setSpanner(Spanner* val) { return _spanner = val; }
Expand Down
11 changes: 8 additions & 3 deletions mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,7 @@ void ScoreView::startNoteEntry()
// no selection
// choose page in current view (favor top left quadrant if possible)
// select first (top/left) chordrest of that page in current view
// or, CR at last selected position if that is in view
Page* p = nullptr;
QList<QPointF> points;
points.append(toLogical(QPoint(width() * 0.25, height() * 0.25)));
Expand All @@ -2601,9 +2602,11 @@ void ScoreView::startNoteEntry()
QRectF intersect = viewRect & pageRect;
intersect.translate(-p->x(), -p->y());
QList<Element*> el = p->items(intersect);
ChordRest* lastSelected = score()->selection().currentCR();
for (Element* e : el) {
// loop through visible elements
// looking for the CR in voice 1 with earliest tick and highest staff position
// but stop we find the last selected CR
ElementType et = e->type();
if (et == ElementType::NOTE || et == ElementType::REST) {
if (e->voice())
Expand All @@ -2617,6 +2620,10 @@ void ScoreView::startNoteEntry()
else {
cr = static_cast<ChordRest*>(e);
}
if (cr == lastSelected) {
topLeft = cr;
break;
}
// compare ticks rather than x position
// to make sure we favor earlier rather than later systems
// even though later system might have note farther to left
Expand Down Expand Up @@ -2659,9 +2666,7 @@ void ScoreView::startNoteEntry()
// if no note/rest is selected, start with voice 0
int track = is.track() == -1 ? 0 : (is.track() / VOICES) * VOICES;
// try to find an appropriate measure to start in
while (el && el->type() != ElementType::MEASURE)
el = el->parent();
Fraction tick = el ? static_cast<Measure*>(el)->tick() : Fraction(0,1);
Fraction tick = el ? el->tick() : Fraction(0,1);
el = _score->searchNote(tick, track);
if (!el)
el = _score->searchNote(Fraction(0,1), track);
Expand Down
2 changes: 2 additions & 0 deletions mtest/testscript/scripts/#173381-mmrest-copy.script
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ cmd pad-note-1
cmd note-a
cmd escape
cmd toggle-mmrest
cmd prev-element
cmd prev-chord
cmd note-input
cmd escape
cmd select-next-chord
Expand Down
4 changes: 4 additions & 0 deletions mtest/testscript/scripts/#173381-mmrest-repeat-2.script
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ cmd note-a
cmd note-a
cmd escape
cmd toggle-mmrest
cmd prev-element
cmd prev-chord
cmd prev-chord
cmd prev-chord
cmd note-input
cmd escape
cmd select-next-chord
Expand Down
Loading

0 comments on commit 0c9804d

Please sign in to comment.