Skip to content

Commit

Permalink
Merge pull request #3995 from dmitrio95/convert-double-articulations
Browse files Browse the repository at this point in the history
fix #276568 Convert double articulations
  • Loading branch information
anatoly-os committed Oct 12, 2018
2 parents 5eaf97d + 41435b0 commit 667aaff
Show file tree
Hide file tree
Showing 9 changed files with 2,926 additions and 21 deletions.
7 changes: 7 additions & 0 deletions libmscore/articulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ bool Articulation::isAccent() const
|| _symId == SymId::articAccentStaccatoAbove || _symId == SymId::articAccentStaccatoBelow;
}

bool Articulation::isMarcato() const
{
return _symId == SymId::articMarcatoAbove || _symId == SymId::articMarcatoBelow
|| _symId == SymId::articMarcatoStaccatoAbove || _symId == SymId::articMarcatoStaccatoBelow
|| _symId == SymId::articMarcatoTenutoAbove || _symId == SymId::articMarcatoTenutoBelow;
}

//---------------------------------------------------------
// isLuteFingering
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/articulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Articulation final : public Element {
bool isTenuto() const;
bool isStaccato() const;
bool isAccent() const;
bool isMarcato() const;
bool isLuteFingering() const;

void doAutoplace();
Expand Down
10 changes: 9 additions & 1 deletion libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,15 @@ bool Chord::setProperty(Pid propertyId, const QVariant& v)

Articulation* Chord::hasArticulation(const Articulation* aa)
{
SymId id = aa->symId();
return hasArticulation(aa->symId());
}

//---------------------------------------------------------
// hasArticulation
//---------------------------------------------------------

Articulation* Chord::hasArticulation(SymId id)
{
for (Articulation* a : _articulations) {
if (id == a->symId())
return a;
Expand Down
1 change: 1 addition & 0 deletions libmscore/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Chord final : public ChordRest {
QVector<Articulation*>& articulations() { return _articulations; }
const QVector<Articulation*>& articulations() const { return _articulations; }
Articulation* hasArticulation(const Articulation*);
Articulation* hasArticulation(SymId id);
bool hasSingleArticulation() const { return _articulations.size() == 1; }

virtual void crossMeasureSetup(bool on);
Expand Down
86 changes: 66 additions & 20 deletions libmscore/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,8 +1587,11 @@ bool readChordRestProperties206(XmlReader& e, ChordRest* ch)
ch->setBeamMode(bm);
}
else if (tag == "Articulation") {
Element* a = readArticulation(ch, e);
ch->add(a);
Element* el = readArticulation(ch, e);
if (el->isFermata())
ch->segment()->add(el);
else
ch->add(el);
}
else if (tag == "leadingSpace" || tag == "trailingSpace") {
qDebug("ChordRest: %s obsolete", tag.toLocal8Bit().data());
Expand Down Expand Up @@ -1831,6 +1834,65 @@ bool readChordProperties206(XmlReader& e, Chord* ch)
return true;
}

//---------------------------------------------------------
// convertDoubleArticulations
// Replace double articulations with proper SMuFL
// symbols which were not available for use prior to 3.0
//---------------------------------------------------------

static void convertDoubleArticulations(Chord* chord)
{
std::vector<Articulation*> pairableArticulations;
for (Articulation* a : chord->articulations()) {
if (a->isStaccato() || a->isTenuto()
|| a->isAccent() || a->isMarcato()) {
pairableArticulations.push_back(a);
};
}
if (pairableArticulations.size() != 2)
// Do not replace triple articulation if this happens
return;

SymId newSymId = SymId::noSym;
for (int i = 0; i < 2; ++i) {
if (newSymId != SymId::noSym)
break;
Articulation* ai = pairableArticulations[i];
Articulation* aj = pairableArticulations[(i == 0) ? 1 : 0];
if (ai->isStaccato()) {
if (aj->isAccent())
newSymId = SymId::articAccentStaccatoAbove;
else if (aj->isMarcato())
newSymId = SymId::articMarcatoStaccatoAbove;
else if (aj->isTenuto())
newSymId = SymId::articTenutoStaccatoAbove;
}
else if (ai->isTenuto()) {
if (aj->isAccent())
newSymId = SymId::articTenutoAccentAbove;
else if (aj->isMarcato())
newSymId = SymId::articMarcatoTenutoAbove;
}
}

if (newSymId != SymId::noSym) {
// We reuse old articulation and change symbol ID
// rather than constructing a new articulation
// in order to preserve its other properties.
Articulation* newArtic = pairableArticulations[0];
for (Articulation* a : pairableArticulations) {
chord->remove(a);
if (a != newArtic)
delete a;
}

ArticulationAnchor anchor = newArtic->anchor();
newArtic->setSymId(newSymId);
newArtic->setAnchor(anchor);
chord->add(newArtic);
}
}

//---------------------------------------------------------
// readChord
//---------------------------------------------------------
Expand All @@ -1847,13 +1909,6 @@ static void readChord(Chord* chord, XmlReader& e)
readNote(note, e);
chord->add(note);
}
else if (tag == "Articulation") {
Element* el = readArticulation(chord, e);
if (el->isFermata())
chord->segment()->add(el);
else
chord->add(el);
}
else if (tag == "Stem") {
Stem* stem = new Stem(chord->score());
while (e.readNextStartElement()) {
Expand All @@ -1876,6 +1931,7 @@ static void readChord(Chord* chord, XmlReader& e)
else
e.unknown();
}
convertDoubleArticulations(chord);
}

//---------------------------------------------------------
Expand All @@ -1885,17 +1941,7 @@ static void readChord(Chord* chord, XmlReader& e)
static void readRest(Rest* rest, XmlReader& e)
{
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "Articulation") {
Element* el = readArticulation(rest, e);
if (el->isFermata())
rest->segment()->add(el);
else
rest->add(el);
}
else if (readChordRestProperties206(e, rest))
;
else
if (!readChordRestProperties206(e, rest))
e.unknown();
}
}
Expand Down
Loading

0 comments on commit 667aaff

Please sign in to comment.