Skip to content

Commit

Permalink
Merge pull request #5275 from mattmcclinch/293459-tied-unisons
Browse files Browse the repository at this point in the history
fix #293459: Tie command does not properly handle chords with unisons
  • Loading branch information
dmitrio95 committed Nov 18, 2019
2 parents e6e1f20 + 682e5b7 commit 6638eaf
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
12 changes: 8 additions & 4 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void Chord::add(Element* e)

for (unsigned idx = 0; idx < _notes.size(); ++idx) {
if (note->pitch() <= _notes[idx]->pitch()) {
if (note->pitch() == _notes[idx]->pitch() && note->line() > _notes[idx]->line())
if (note->pitch() == _notes[idx]->pitch() && note->line() >= _notes[idx]->line())
_notes.insert(_notes.begin()+idx+1, note);
else
_notes.insert(_notes.begin()+idx, note);
Expand Down Expand Up @@ -2532,13 +2532,17 @@ void Chord::layoutArpeggio2()
// findNote
//---------------------------------------------------------

Note* Chord::findNote(int pitch) const
Note* Chord::findNote(int pitch, int skip) const
{
size_t ns = _notes.size();
for (size_t i = 0; i < ns; ++i) {
Note* n = _notes.at(i);
if (n->pitch() == pitch)
return n;
if (n->pitch() == pitch) {
if (skip == 0)
return n;
else
--skip;
}
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libmscore/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Chord final : public ChordRest {

qreal maxHeadWidth() const;

Note* findNote(int pitch) const;
Note* findNote(int pitch, int skip = 0) const;

Stem* stem() const { return _stem; }
Arpeggio* arpeggio() const { return _arpeggio; }
Expand Down
4 changes: 2 additions & 2 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4623,8 +4623,8 @@ void Score::undoAddElement(Element* element)
sm = cr2->staffIdx() - cr1->staffIdx();
Chord* c1 = findLinkedChord(cr1, score->staff(staffIdx));
Chord* c2 = findLinkedChord(cr2, score->staff(staffIdx + sm));
Note* nn1 = c1->findNote(n1->pitch());
Note* nn2 = c2 ? c2->findNote(n2->pitch()) : 0;
Note* nn1 = c1->findNote(n1->pitch(), n1->unisonIndex());
Note* nn2 = c2 ? c2->findNote(n2->pitch(), n2->unisonIndex()) : 0;

// create tie
Tie* ntie = toTie(ne);
Expand Down
21 changes: 21 additions & 0 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,27 @@ std::vector<Note*> Note::tiedNotes() const
return notes;
}

//---------------------------------------------------------
// unisonIndex
//---------------------------------------------------------

int Note::unisonIndex() const
{
int index = 0;
auto notes = chord()->notes();
size_t ns = notes.size();
for (size_t i = 0; i < ns; ++i) {
Note* n = notes.at(i);
if (n->pitch() == pitch()) {
if (n == this)
return index;
else
++index;
}
}
return 0;
}

//---------------------------------------------------------
// disconnectTiedNotes
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class Note final : public Element {
Note* firstTiedNote() const;
const Note* lastTiedNote() const;
Note* lastTiedNote() { return const_cast<Note*>(static_cast<const Note*>(this)->lastTiedNote()); }
int unisonIndex() const;
void disconnectTiedNotes();
void connectTiedNotes();

Expand Down
6 changes: 4 additions & 2 deletions libmscore/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,11 @@ Note* searchTieNote(Note* note)
return gn2;
}
for (Note* n : c->notes()) {
if (n->pitch() == note->pitch()) {
if (note2 == 0 || c->track() == chord->track())
if (n->pitch() == note->pitch() && !n->tieBack()) {
if (note2 == 0 || c->track() == chord->track()) {
note2 = n;
break;
}
}
}
}
Expand Down

0 comments on commit 6638eaf

Please sign in to comment.