fix #293459: Tie command does not properly handle chords with unisons

This commit is contained in:
Matt McClinch 2019-08-22 07:55:10 -04:00
parent e36df5633e
commit 682e5b7742
6 changed files with 37 additions and 9 deletions

View file

@ -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);
@ -2530,13 +2530,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;
}

View file

@ -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; }

View file

@ -4607,8 +4607,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);

View file

@ -3109,6 +3109,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
//---------------------------------------------------------

View file

@ -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();

View file

@ -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;
}
}
}
}