diff --git a/src/engraving/dom/noteentry.cpp b/src/engraving/dom/noteentry.cpp index a9ffc30c38bdf..62b81a6ccad27 100644 --- a/src/engraving/dom/noteentry.cpp +++ b/src/engraving/dom/noteentry.cpp @@ -747,13 +747,7 @@ std::pair Score::repitchReplaceNote(Chord* chord, const NoteVal& n // recreate tie forward if there is a note to tie to // one-sided ties will not be recreated if (firstTiedNote) { - Tie* tie = Factory::createTie(note); - tie->setStartNote(note); - tie->setEndNote(firstTiedNote); - tie->setTick(tie->startNote()->tick()); - tie->setTick2(tie->endNote()->tick()); - tie->setTrack(note->track()); - undoAddElement(tie); + tieNotesTogether(note, firstTiedNote); } select(lastTiedNote); diff --git a/src/engraving/dom/score.cpp b/src/engraving/dom/score.cpp index ab37055eea470..288098537ba59 100644 --- a/src/engraving/dom/score.cpp +++ b/src/engraving/dom/score.cpp @@ -5938,6 +5938,20 @@ bool Score::autoLayoutEnabled() const return isOpen(); } +Tie* Score::tieNotesTogether(Note* n1, Note* n2) +{ + Tie* tie = Factory::createTie(this->dummy()); + tie->setStartNote(n1); + tie->setEndNote(n2); + tie->setTick(tie->startNote()->tick()); + tie->setTick2(tie->endNote()->tick()); + tie->setTrack(n1->track()); + n1->setTieFor(tie); + n2->setTieBack(tie); + undoAddElement(tie); + return tie; +} + //--------------------------------------------------------- // doLayout // do a complete (re-) layout diff --git a/src/engraving/dom/score.h b/src/engraving/dom/score.h index 83b1b7ca444a1..8f2d0d8080efc 100644 --- a/src/engraving/dom/score.h +++ b/src/engraving/dom/score.h @@ -866,6 +866,7 @@ class Score : public EngravingObject, public muse::Contextable Segment* lastSegment() const; Segment* lastSegmentMM() const; + Tie* tieNotesTogether(Note* n1, Note* n2); void connectTies(bool silent = false); void undoRemoveStaleTieJumpPoints(bool undo = true); diff --git a/src/engraving/editing/cmd.cpp b/src/engraving/editing/cmd.cpp index 2da495f26f229..19849294ea378 100644 --- a/src/engraving/editing/cmd.cpp +++ b/src/engraving/editing/cmd.cpp @@ -1066,15 +1066,7 @@ void Score::createCRSequence(const Fraction& f, ChordRest* cr, const Fraction& t for (unsigned int i = 0; i < oc->notes().size(); ++i) { Note* on = oc->notes()[i]; Note* nn = nc->notes()[i]; - Tie* tie = Factory::createTie(this->dummy()); - tie->setStartNote(on); - tie->setEndNote(nn); - tie->setTick(tie->startNote()->tick()); - tie->setTick2(tie->endNote()->tick()); - tie->setTrack(cr->track()); - on->setTieFor(tie); - nn->setTieBack(tie); - undoAddElement(tie); + tieNotesTogether(on, nn); } } @@ -1777,6 +1769,7 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest) ChordRest* cr1 = cr; Chord* oc = 0; Segment* s = cr->segment(); + Fraction endTickBefore = cr->isChord() ? toChord(cr)->endTickIncludingTied() : cr->endTick(); bool first = true; for (const Fraction& f2 : flist) { @@ -1864,6 +1857,22 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest) s = m1->first(SegmentType::ChordRest); cr1 = toChordRest(s->element(track)); } + + Fraction endTickAfter = cr->isChord() ? toChord(cr)->endTickIncludingTied() : cr->endTick(); + while (endTickAfter < endTickBefore) { // making a chord *longer* shouldn't _shorten_ its total duration + if (!oc){ // everything up to oc should already be tied together + oc = toChord(cr1); + } + + for (Note* n: oc->notes()){ + if (Note* nn = searchTieNote(n)){ + tieNotesTogether(n, nn); + } + } + oc = oc->next(); + endTickAfter = cr->isChord() ? toChord(cr)->endTickIncludingTied() : cr->endTick(); + } + connectTies(); if (elementToSelect) { @@ -4214,13 +4223,7 @@ bool Score::cmdImplode() for (Note* tn : tied->notes()) { if (nn->pitch() == tn->pitch() && nn->tpc() == tn->tpc() && !tn->tieFor()) { // found note to tie - Tie* tie = Factory::createTie(this->dummy()); - tie->setStartNote(tn); - tie->setEndNote(nn); - tie->setTick(tie->startNote()->tick()); - tie->setTick2(tie->endNote()->tick()); - tie->setTrack(tn->track()); - undoAddElement(tie); + tieNotesTogether(tn, nn); } } } diff --git a/src/engraving/editing/edit.cpp b/src/engraving/editing/edit.cpp index 3cb9d0c687676..f1dfad096841b 100644 --- a/src/engraving/editing/edit.cpp +++ b/src/engraving/editing/edit.cpp @@ -422,13 +422,7 @@ Chord* Score::addChord(const Fraction& tick, TDuration d, Chord* oc, bool genTie for (size_t i = 0; i < n; ++i) { Note* n1 = oc->notes()[i]; Note* n2 = chord->notes()[i]; - Tie* tie = Factory::createTie(this->dummy()); - tie->setStartNote(n1); - tie->setEndNote(n2); - tie->setTick(tie->startNote()->tick()); - tie->setTick2(tie->endNote()->tick()); - tie->setTrack(n1->track()); - undoAddElement(tie); + tieNotesTogether(n1, n2); } } @@ -1700,15 +1694,7 @@ Note* Score::addTiedMidiPitch(int pitch, bool addFlag, Chord* prevChord, bool al if (prevChord) { Note* nn = prevChord->findNote(n->pitch()); if (nn) { - Tie* tie = Factory::createTie(this->dummy()); - tie->setStartNote(nn); - tie->setEndNote(n); - tie->setTick(tie->startNote()->tick()); - tie->setTick2(tie->endNote()->tick()); - tie->setTrack(n->track()); - n->setTieBack(tie); - nn->setTieFor(tie); - undoAddElement(tie); + tieNotesTogether(nn, n); } } return n; @@ -1908,14 +1894,7 @@ void Score::regroupNotesAndRests(const Fraction& startTick, const Fraction& endT std::vector nl2 = nchord2->notes(); if (!firstpart) { for (size_t j = 0; j < nl1.size(); ++j) { - Tie* tie = Factory::createTie(this->dummy()); - tie->setStartNote(nl1[j]); - tie->setEndNote(nl2[j]); - tie->setTick(tie->startNote()->tick()); - tie->setTick2(tie->endNote()->tick()); - tie->setTrack(tr); - nl1[j]->setTieFor(tie); - nl2[j]->setTieBack(tie); + Tie* tie = tieNotesTogether(nl1[j], nl2[j]); ties.push_back(tie); } }