Skip to content

Commit 9dcbfac

Browse files
committed
Percussion panel - fix bug when switching voices while entering notes
1 parent 68e434e commit 9dcbfac

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/engraving/dom/noteentry.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag, InputState* externalInputStat
211211
}
212212

213213
if (!is.cr()) {
214-
return 0;
214+
handleOverlappingChordRest(is);
215215
}
216+
216217
Measure* measure = is.segment()->measure();
217218
if (measure->isMeasureRepeatGroup(track2staff(track))) {
218219
MeasureRepeat* mr = measure->measureRepeatElement(track2staff(track));
@@ -456,29 +457,7 @@ Ret Score::putNote(const Position& p, bool replace)
456457

457458
// If there's an overlapping ChordRest at the current input position, shorten it...
458459
if (!cr) {
459-
MasterScore* ms = masterScore();
460-
ChordRest* prevCr = m_is.segment()->nextChordRest(m_is.track(), /*backwards*/ true, /*stopAtMeasureBoundary*/ true);
461-
if (prevCr && prevCr->endTick() > m_is.tick()) {
462-
const Fraction overlapDuration = prevCr->endTick() - m_is.tick();
463-
const Fraction desiredDuration = prevCr->ticks() - overlapDuration;
464-
465-
const InputState inputStateToRestore = m_is; // because changeCRlen will alter the input state
466-
ms->changeCRlen(prevCr, desiredDuration, /*fillWithRest*/ false);
467-
468-
// Fill the difference with tied notes if necessary...
469-
const Fraction difference = desiredDuration - prevCr->ticks();
470-
if (prevCr->isChord() && difference.isNotZero()) {
471-
Fraction startTick = prevCr->endTick();
472-
Chord* prevChord = toChord(prevCr);
473-
const std::vector<TDuration> durationList = toDurationList(difference, true);
474-
for (const TDuration& dur : durationList) {
475-
prevChord = ms->addChord(startTick, dur, prevChord, /*genTie*/ bool(prevChord), prevChord->tuplet());
476-
startTick += dur.fraction();
477-
}
478-
}
479-
480-
m_is = inputStateToRestore;
481-
}
460+
handleOverlappingChordRest(m_is);
482461
}
483462

484463
auto checkTied = [&](){
@@ -587,6 +566,33 @@ Ret Score::putNote(const Position& p, bool replace)
587566
return ret;
588567
}
589568

569+
void Score::handleOverlappingChordRest(InputState& inputState)
570+
{
571+
MasterScore* ms = masterScore();
572+
ChordRest* prevCr = inputState.segment()->nextChordRest(inputState.track(), /*backwards*/ true, /*stopAtMeasureBoundary*/ true);
573+
if (prevCr && prevCr->endTick() > inputState.tick()) {
574+
const Fraction overlapDuration = prevCr->endTick() - inputState.tick();
575+
const Fraction desiredDuration = prevCr->ticks() - overlapDuration;
576+
577+
const InputState inputStateToRestore = inputState; // because changeCRlen will alter the input state
578+
ms->changeCRlen(prevCr, desiredDuration, /*fillWithRest*/ true);
579+
580+
// Fill the difference with tied notes if necessary...
581+
const Fraction difference = desiredDuration - prevCr->ticks();
582+
if (prevCr->isChord() && difference.isNotZero()) {
583+
Fraction startTick = prevCr->endTick();
584+
Chord* prevChord = toChord(prevCr);
585+
const std::vector<TDuration> durationList = toDurationList(difference, true);
586+
for (const TDuration& dur : durationList) {
587+
prevChord = ms->addChord(startTick, dur, prevChord, /*genTie*/ bool(prevChord), prevChord->tuplet());
588+
startTick += dur.fraction();
589+
}
590+
}
591+
592+
inputState = inputStateToRestore;
593+
}
594+
}
595+
590596
//---------------------------------------------------------
591597
// repitchNote
592598
//---------------------------------------------------------

src/engraving/dom/score.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ class Score : public EngravingObject, public muse::Injectable
10741074
void selectRange(EngravingItem* e, staff_idx_t staffIdx);
10751075

10761076
muse::Ret putNote(const Position&, bool replace);
1077+
void handleOverlappingChordRest(InputState& inputState);
10771078

10781079
void resetTempo();
10791080
void resetTempoRange(const Fraction& tick1, const Fraction& tick2);

0 commit comments

Comments
 (0)