Skip to content

Commit be6e7ff

Browse files
committed
suggested changes
1 parent fa614ef commit be6e7ff

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/engraving/dom/cmd.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3346,13 +3346,13 @@ void Score::cmdIncDecDuration(int nSteps, bool stepDotted)
33463346

33473347
void Score::cmdExtendToNextNote()
33483348
{
3349-
Fraction startTick = selection().tickStart();
3349+
const Fraction startTick = selection().tickStart();
33503350
Fraction endTick = selection().tickEnd();
3351-
staff_idx_t startStaff = selection().staffStart();
3352-
staff_idx_t endStaff = selection().staffEnd();
3351+
const staff_idx_t startStaff = selection().staffStart();
3352+
const staff_idx_t endStaff = selection().staffEnd();
33533353

33543354
std::vector<ChordRest*> crList;
3355-
std::string selType = m_selection.isList() ? "list" : "range";
3355+
const bool wasRangeSelection = selection().isRange();
33563356

33573357
for (EngravingItem* el : selection().elements()) {
33583358
if (!el->isNote()) {
@@ -3363,17 +3363,19 @@ void Score::cmdExtendToNextNote()
33633363
Fraction crts = cr->ticks();
33643364
crList.push_back(cr);
33653365

3366-
while ((nextChordRest(cr) && nextChordRest(cr)->isRest()) || (nextChordRest(cr) && nextChordRest(cr)->tick() > (cr->tick() + cr->ticks()))) {
3367-
ChordRest* ncr = nextChordRest(cr);
3368-
Rest* r = toRest(ncr);
3366+
if (!nextChordRest(cr)) {
3367+
continue;
3368+
}
3369+
ChordRest* ncr = nextChordRest(cr);
33693370

3370-
if (cr->tuplet() || r->tuplet()) {
3371+
while (ncr->isRest() || (ncr->tick() > cr->endTick())) { //second condition checks for empty measure between cr and ncr for voices 2,3,4.
3372+
if (cr->tuplet() || ncr->tuplet()) {
33713373
m_is.setSegment(ncr->segment());
33723374
m_is.setLastSegment(m_is.segment());
3373-
m_is.setDuration(r->durationType());
3375+
m_is.setDuration(ncr->durationType());
33743376

33753377
Note* nn = nullptr;
3376-
for (uint i = 0; i < toChord(cr)->notes().size(); i++) {
3378+
for (size_t i = 0; i < toChord(cr)->notes().size(); i++) {
33773379
Note* note = toChord(cr)->notes()[i];
33783380
NoteVal nval(note->noteVal());
33793381
nn = addPitch(nval, i != 0);
@@ -3389,14 +3391,19 @@ void Score::cmdExtendToNextNote()
33893391
cr = toChordRest(nn->chord());
33903392
crList.push_back(cr);
33913393
} else {
3392-
changeCRlen(cr, cr->ticks() + r->ticks());
3394+
changeCRlen(cr, cr->ticks() + ncr->ticks());
33933395
if (cr->ticks() == crts) {
33943396
cr = nextChordRest(cr);
33953397
crList.push_back(cr);
33963398
}
33973399
}
33983400
crts = cr->ticks();
3399-
endTick = cr->tick() + cr->ticks() >= endTick ? cr->tick() + cr->ticks() : endTick;
3401+
endTick = cr->endTick() >= endTick ? cr->endTick() : endTick;
3402+
3403+
if (!nextChordRest(cr)) { //endMeasure
3404+
break;
3405+
}
3406+
ncr = nextChordRest(cr);
34003407
}
34013408
while ((!nextChordRest(cr) && cr->voice() > 0 && cr->measure() != score()->lastMeasure())) {
34023409
changeCRlen(cr, cr->ticks() + cr->measure()->ticks());
@@ -3406,7 +3413,7 @@ void Score::cmdExtendToNextNote()
34063413
}
34073414
}
34083415

3409-
if (selType == "range") {
3416+
if (wasRangeSelection) {
34103417
selection().setRangeTicks(startTick, endTick, startStaff, endStaff);
34113418
selection().updateSelectedElements();
34123419
} else {

0 commit comments

Comments
 (0)