Skip to content

Commit

Permalink
Merge pull request #6109 from jthistle/305717-fret-diagrams-links-issues
Browse files Browse the repository at this point in the history
fix #305717: chord symbols attached to fret diagrams don't link to parts
  • Loading branch information
anatoly-os committed Jun 1, 2020
2 parents 7952f0c + e146e6a commit 721e42e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
11 changes: 9 additions & 2 deletions libmscore/edit.cpp
Expand Up @@ -4579,6 +4579,14 @@ void Score::undoAddElement(Element* element)
ne->setScore(score);
ne->setSelected(false);
ne->setTrack(staffIdx * VOICES + element->voice());

if (ne->isFretDiagram()) {
FretDiagram* fd = toFretDiagram(ne);
Harmony* fdHarmony = fd->harmony();
fdHarmony->setScore(score);
fdHarmony->setSelected(false);
fdHarmony->setTrack(staffIdx * VOICES + element->voice());
}
}

if (element->isArticulation()) {
Expand Down Expand Up @@ -4664,8 +4672,7 @@ void Score::undoAddElement(Element* element)
if (ne->isHarmony()) {
for (Element* segel : segment->annotations()) {
if (segel && segel->isFretDiagram() && segel->track() == ntrack) {
ne->setTrack(segel->track());
ne->setParent(segel);
segel->add(ne);
break;
}
}
Expand Down
32 changes: 24 additions & 8 deletions libmscore/excerpt.cpp
Expand Up @@ -429,6 +429,22 @@ static void cloneTuplets(ChordRest* ocr, ChordRest* ncr, Tuplet* ot, TupletMap&
ncr->setTuplet(nt);
}

//---------------------------------------------------------
// processLinkedClone
//---------------------------------------------------------

void Excerpt::processLinkedClone(Element* ne, Score* score, int strack)
{
// reset offset as most likely it will not fit
PropertyFlags f = ne->propertyFlags(Pid::OFFSET);
if (f == PropertyFlags::UNSTYLED) {
ne->setPropertyFlags(Pid::OFFSET, PropertyFlags::STYLED);
ne->resetProperty(Pid::OFFSET);
}
ne->setTrack(strack == -1 ? 0 : strack);
ne->setScore(score);
}

//---------------------------------------------------------
// cloneStaves
//---------------------------------------------------------
Expand Down Expand Up @@ -489,14 +505,7 @@ void Excerpt::cloneStaves(Score* oscore, Score* score, const QList<int>& map, QM
continue;
if ((e->track() == srcTrack && strack != -1) || (e->systemFlag() && srcTrack == 0)) {
Element* ne = e->linkedClone();
// reset offset as most likely it will not fit
PropertyFlags f = ne->propertyFlags(Pid::OFFSET);
if (f == PropertyFlags::UNSTYLED) {
ne->setPropertyFlags(Pid::OFFSET, PropertyFlags::STYLED);
ne->resetProperty(Pid::OFFSET);
}
ne->setTrack(strack == -1 ? 0 : strack);
ne->setScore(score);
processLinkedClone(ne, score, strack);
if (!ns)
ns = nm->getSegment(oseg->segmentType(), oseg->tick());
ns->add(ne);
Expand All @@ -506,6 +515,13 @@ void Excerpt::cloneStaves(Score* oscore, Score* score, const QList<int>& map, QM
Harmony* h = toHarmony(ne);
h->render();
}
else if (ne->isFretDiagram()) {
Harmony* h = toHarmony(toFretDiagram(ne)->harmony());
if (h) {
processLinkedClone(h, score, strack);
h->render();
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions libmscore/excerpt.h
Expand Up @@ -71,6 +71,7 @@ class Excerpt : public QObject {
static void cloneStaves(Score* oscore, Score* score, const QList<int>& map, QMultiMap<int, int>& allTracks);
static void cloneStaff(Staff* ostaff, Staff* nstaff);
static void cloneStaff2(Staff* ostaff, Staff* nstaff, const Fraction& stick, const Fraction& etick);
static void processLinkedClone(Element* ne, Score* score, int strack);
};

} // namespace Ms
Expand Down
16 changes: 16 additions & 0 deletions libmscore/fret.cpp
Expand Up @@ -83,6 +83,22 @@ FretDiagram::~FretDiagram()
delete _harmony;
}

//---------------------------------------------------------
// linkedClone
//---------------------------------------------------------

Element* FretDiagram::linkedClone()
{
FretDiagram* e = clone();
e->setAutoplace(true);
if (_harmony) {
Element* newHarmony = _harmony->linkedClone();
e->add(newHarmony);
}
score()->undo(new Link(e, this));
return e;
}

//---------------------------------------------------------
// fromString
/// Create diagram from string like "XO-123"
Expand Down
1 change: 1 addition & 0 deletions libmscore/fret.h
Expand Up @@ -164,6 +164,7 @@ class FretDiagram final : public Element {
~FretDiagram();

void draw(QPainter*) const override;
Element* linkedClone() override;
FretDiagram* clone() const override { return new FretDiagram(*this); }

Segment* segment() { return toSegment(parent()); }
Expand Down

0 comments on commit 721e42e

Please sign in to comment.