Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/engraving/dom/noteentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,7 @@ std::pair<Note*, Note*> 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);

Expand Down
14 changes: 14 additions & 0 deletions src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment thread
miiizen marked this conversation as resolved.

//---------------------------------------------------------
// doLayout
// do a complete (re-) layout
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
35 changes: 19 additions & 16 deletions src/engraving/editing/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Comment on lines +1861 to +1873
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Only recreate ties for notes that were originally tied forward.

Line 1867 currently retries every note in oc if searchTieNote() finds a match. On mixed chords, that can introduce brand-new ties on notes that were previously untied. Please capture the original outgoing-tie membership before mutating the chain and filter this loop to that subset only.

}

connectTies();

if (elementToSelect) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
27 changes: 3 additions & 24 deletions src/engraving/editing/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1908,14 +1894,7 @@ void Score::regroupNotesAndRests(const Fraction& startTick, const Fraction& endT
std::vector<Note*> 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);
Comment on lines +1897 to 1898
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Avoid double-registering ties in undo stack.

tieNotesTogether(...) already performs undoAddElement(tie), but these ties are still re-added in the later loop at Line 1966–1969. This can create duplicate undo entries / invalid state in regrouping.

🔧 Proposed fix
@@
-                                    Tie* tie = tieNotesTogether(nl1[j], nl2[j]);
-                                    ties.push_back(tie);
+                                    ties.push_back(tieNotesTogether(nl1[j], nl2[j]));
@@
-                        if (tieBack[i]) {
-                            Tie* tie = Factory::createTie(this->dummy());
-                            tie->setStartNote(tieBack[i]);
-                            tie->setEndNote(n);
-                            tie->setTick(tie->startNote()->tick());
-                            tie->setTick2(tie->endNote()->tick());
-                            tie->setTrack(track);
-                            n->setTieBack(tie);
-                            tieBack[i]->setTieFor(tie);
-                            ties.push_back(tie);
-                        }
-                        if (tieFor[i]) {
-                            Tie* tie = Factory::createTie(this->dummy());
-                            tie->setStartNote(nn);
-                            tie->setEndNote(tieFor[i]);
-                            tie->setTick(tie->startNote()->tick());
-                            tie->setTick2(tie->endNote()->tick());
-                            tie->setTrack(track);
-                            nn->setTieFor(tie);
-                            tieFor[i]->setTieBack(tie);
-                            ties.push_back(tie);
-                        }
+                        if (tieBack[i]) {
+                            ties.push_back(tieNotesTogether(tieBack[i], n));
+                        }
+                        if (tieFor[i]) {
+                            ties.push_back(tieNotesTogether(nn, tieFor[i]));
+                        }
@@
-                    if (!ties.empty()) {         // at least one tie was created
-                        for (Tie* tie : ties) {
-                            undoAddElement(tie);
-                        }
-                        connectTies();
-                    }
+                    if (!ties.empty()) {         // at least one tie was created
+                        connectTies();
+                    }

}
}
Expand Down