Skip to content

Commit

Permalink
Fixup l.v. symbol positioning after XML import
Browse files Browse the repository at this point in the history
This is a temporary and somewhat hacky fix that iterates through the
score and adjusts the positioning of l.v. symbols after MusicXML import.
TODO: improve default placement of l.v. symbols to avoid this process.

Duplicate of musescore#8556, part 2
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Sep 2, 2021
1 parent fb5f5a6 commit e080a27
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ void MusicXMLParserPass2::scorePartwise()

_score->connectArpeggios();
cleanFretDiagrams(_score->firstMeasure());
_score->fixupLaissezVibrer();
}

//---------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,51 @@ void Score::connectArpeggios()
}
}

//---------------------------------------------------------
// fixupLaissezVibrer
// This is a temporary hack to improve the placement of
// l.v. articulations when importing MusciXML.
// TODO: vastly improve the automatic placement of the
// l.v. articulation.
//---------------------------------------------------------

void Score::fixupLaissezVibrer()
{
int tracks = nstaves() * VOICES;
Measure* m = firstMeasure();
if (!m)
return;
if (m->canvasPos() == QPointF(0, 0))
doLayout();

SegmentType st = SegmentType::ChordRest;
for (Segment* s = m->first(st); s; s = s->next1(st)) {
for (int i = 0; i < tracks; ++i) {
Element* e = s->element(i);
if (e == 0 || !e->isChord())
continue;
Chord* c = toChord(e);
for (auto a : c->articulations()) {
if (a->symId() != SymId::articLaissezVibrerAbove && a->symId() != SymId::articLaissezVibrerBelow)
continue;

// Manually override placement
a->setAutoplace(false);
a->setMinDistance(Spatium(0));
c->layoutArticulations();
c->layoutArticulations2();
bool below = a->symId() == SymId::articLaissezVibrerBelow;
Note* n = below ? c->notes().front() : c->notes().back();

QPointF target = below ? n->canvasBoundingRect().bottomLeft() + QPointF(0.5 * n->width(), 0.25 * spatium())
: n->canvasBoundingRect().topLeft() + QPointF(0.5 * n->width(), -0.25 * spatium());
QPointF current = below ? a->canvasBoundingRect().topLeft() : a->canvasBoundingRect().bottomLeft();
a->setOffset(a->offset() + target - current);
}
}
}
}

//---------------------------------------------------------
// checkDivider
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ class Score : public QObject, public ScoreElement {

void connectTies(bool silent=false);
void connectArpeggios();
void fixupLaissezVibrer();

qreal point(const Spatium sp) const { return sp.val() * spatium(); }

Expand Down
18 changes: 12 additions & 6 deletions mtest/musicxml/io/testUnterminatedTies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,16 @@
<measure number="3" width="90.13">
<note default-x="16.50" default-y="-55.00">
<pitch>
<step>B</step>
<octave>3</octave>
<step>E</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
<stem>down</stem>
<notations>
<tied type="start"/>
</notations>
</note>
<note>
<rest/>
Expand All @@ -218,13 +221,16 @@
<measure number="4" width="90.13">
<note default-x="16.50" default-y="-55.00">
<pitch>
<step>B</step>
<octave>3</octave>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
<stem>down</stem>
<notations>
<tied type="let-ring"/>
</notations>
</note>
<note>
<rest/>
Expand Down
26 changes: 20 additions & 6 deletions mtest/musicxml/io/testUnterminatedTies_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@
<durationType>quarter</durationType>
<Articulation>
<subtype>articLaissezVibrerBelow</subtype>
<autoplace>0</autoplace>
<offset x="1.17797" y="-0.21"/>
</Articulation>
<StemDirection>up</StemDirection>
<Note>
Expand All @@ -240,10 +242,15 @@
<voice>
<Chord>
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Articulation>
<subtype>articLaissezVibrerAbove</subtype>
<autoplace>0</autoplace>
<offset x="1.17797" y="0.23"/>
</Articulation>
<StemDirection>down</StemDirection>
<Note>
<pitch>59</pitch>
<tpc>19</tpc>
<pitch>76</pitch>
<tpc>18</tpc>
</Note>
</Chord>
<Rest>
Expand All @@ -258,10 +265,15 @@
<voice>
<Chord>
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Articulation>
<subtype>articLaissezVibrerAbove</subtype>
<autoplace>0</autoplace>
<offset x="1.17797" y="0.23"/>
</Articulation>
<StemDirection>down</StemDirection>
<Note>
<pitch>59</pitch>
<tpc>19</tpc>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Rest>
Expand Down Expand Up @@ -382,6 +394,8 @@
<durationType>quarter</durationType>
<Articulation>
<subtype>articLaissezVibrerBelow</subtype>
<autoplace>0</autoplace>
<offset x="1.17797" y="-0.21"/>
</Articulation>
<StemDirection>up</StemDirection>
<Note>
Expand Down

0 comments on commit e080a27

Please sign in to comment.