Skip to content

Commit

Permalink
Enforce volta anchor on all scores
Browse files Browse the repository at this point in the history
Backport of musescore#25031

Also fix most clazy warnings
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Nov 20, 2024
1 parent 981e55e commit 69a0e68
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
21 changes: 13 additions & 8 deletions libmscore/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,11 @@ static void readVolta114(XmlReader& e, Volta* volta)
else if (!readTextLineProperties114(e, volta))
e.unknown();
}
if (volta->anchor() != Volta::VOLTA_ANCHOR) {
// Volta strictly assumes that its anchor is measure, so don't let old scores override this.
qWarning("Correcting volta anchor type from %d to %d", int(volta->anchor()), int(Volta::VOLTA_ANCHOR));
volta->setAnchor(Volta::VOLTA_ANCHOR);
}
volta->setOffset(QPointF()); // ignore offsets
volta->setAutoplace(true);
}
Expand Down Expand Up @@ -1449,7 +1454,7 @@ static void readMeasure(Measure* m, int staffIdx, XmlReader& e)
QList<Chord*> graceNotes;

//sort tuplet elements. needed for nested tuplets #22537
for (Tuplet* t : e.tuplets())
for (Tuplet*& t : e.tuplets())
t->sortElements();
e.tuplets().clear();
e.setTrack(staffIdx * VOICES);
Expand Down Expand Up @@ -2080,11 +2085,11 @@ static void readMeasure(Measure* m, int staffIdx, XmlReader& e)
}
// For nested tuplets created with MuseScore 1.3 tuplet dialog (i.e. "Other..." dialog),
// the parent tuplet was not set. Try to infere if the tuplet was actually a nested tuplet
for (Tuplet* tuplet : e.tuplets()) {
for (Tuplet*& tuplet : e.tuplets()) {
Fraction tupletTick = tuplet->tick();
Fraction tupletDuration = tuplet->actualTicks() - Fraction::fromTicks(1);
std::vector<DurationElement*> tElements = tuplet->elements();
for (Tuplet* tuplet2 : e.tuplets()) {
for (Tuplet*& tuplet2 : e.tuplets()) {
if ((tuplet2->tuplet()) || (tuplet2->voice() != tuplet->voice())) // already a nested tuplet or in a different voice
continue;
// int possibleDuration = tuplet2->duration().ticks() * tuplet->ratio().denominator() / tuplet->ratio().numerator() - 1;
Expand Down Expand Up @@ -2529,7 +2534,7 @@ static void readPart(Part* part, XmlReader& e)
part->setPartName(part->instrument()->trackName());

if (part->instrument()->useDrumset()) {
for (Staff* staff : *part->staves()) {
for (Staff*& staff : *part->staves()) {
int lines = staff->lines(Fraction(0,1));
int bf = staff->barLineFrom();
int bt = staff->barLineTo();
Expand Down Expand Up @@ -2677,7 +2682,7 @@ static void readStyle(MStyle* style, XmlReader& e)
else if (tag == "ChordList") {
style->chordList()->clear();
style->chordList()->read(e);
for (ChordFont f : style->chordList()->fonts) {
for (ChordFont& f : style->chordList()->fonts) {
if (f.family == "MuseJazz") {
f.family = "MuseJazz Text";
}
Expand Down Expand Up @@ -2989,7 +2994,7 @@ Score::FileError MasterScore::read114(XmlReader& e)

setEnableVerticalSpread(false);

for (Staff* s : staves()) {
for (Staff*& s : staves()) {
int idx = s->idx();
int track = idx * VOICES;

Expand Down Expand Up @@ -3154,7 +3159,7 @@ Score::FileError MasterScore::read114(XmlReader& e)
//
// sanity check for barLineSpan and update ottavas
//
for (Staff* staff : staves()) {
for (Staff*& staff : staves()) {
int barLineSpan = staff->barLineSpan();
int idx = staff->idx();
int n = nstaves();
Expand Down Expand Up @@ -3230,7 +3235,7 @@ Score::FileError MasterScore::read114(XmlReader& e)

fixTicks();

for (Part* p : parts()) {
for (Part*& p : parts()) {
p->updateHarmonyChannels(false);
}

Expand Down
27 changes: 16 additions & 11 deletions libmscore/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ bool readChordRestProperties206(XmlReader& e, ChordRest* ch)
ch->add(el);
}
else if (tag == "leadingSpace" || tag == "trailingSpace") {
qDebug("ChordRest: %s obsolete", tag.toLocal8Bit().data());
qDebug("ChordRest: %s obsolete", tag.toLocal8Bit().constData());
e.skipCurrentElement();
}
else if (tag == "Beam") {
Expand Down Expand Up @@ -1818,12 +1818,12 @@ bool readChordRestProperties206(XmlReader& e, ChordRest* ch)
if (spanner->type() == ElementType::SLUR)
spanner->setStartElement(ch);
if (e.pasteMode()) {
for (ScoreElement* el : spanner->linkList()) {
for (ScoreElement*& el : spanner->linkList()) {
if (el == spanner)
continue;
Spanner* ls = static_cast<Spanner*>(el);
ls->setTick(spanner->tick());
for (ScoreElement* ee : ch->linkList()) {
for (ScoreElement*& ee : ch->linkList()) {
ChordRest* cr = toChordRest(ee);
if (cr->score() == ee->score() && cr->staffIdx() == ls->staffIdx()) {
ls->setTrack(cr->track());
Expand All @@ -1844,12 +1844,12 @@ bool readChordRestProperties206(XmlReader& e, ChordRest* ch)
if (start)
spanner->setTrack(start->track());
if (e.pasteMode()) {
for (ScoreElement* el : spanner->linkList()) {
for (ScoreElement*& el : spanner->linkList()) {
if (el == spanner)
continue;
Spanner* ls = static_cast<Spanner*>(el);
ls->setTick2(spanner->tick2());
for (ScoreElement* ee : ch->linkList()) {
for (ScoreElement*& ee : ch->linkList()) {
ChordRest* cr = toChordRest(ee);
if (cr->score() == ee->score() && cr->staffIdx() == ls->staffIdx()) {
ls->setTrack2(cr->track());
Expand Down Expand Up @@ -2020,7 +2020,7 @@ bool readChordProperties206(XmlReader& e, Chord* ch)
static void convertDoubleArticulations(Chord* chord, XmlReader& e)
{
std::vector<Articulation*> pairableArticulations;
for (Articulation* a : chord->articulations()) {
for (Articulation*& a : chord->articulations()) {
if (a->isStaccato() || a->isTenuto()
|| a->isAccent() || a->isMarcato()) {
pairableArticulations.push_back(a);
Expand Down Expand Up @@ -2213,6 +2213,11 @@ static void readVolta206(XmlReader& e, Volta* volta)
else if (!readTextLineProperties(e, volta))
e.unknown();
}
if (volta->anchor() != Volta::VOLTA_ANCHOR) {
// Volta strictly assumes that its anchor is measure, so don't let old scores override this.
qWarning("Correcting volta anchor type from %d to %d", int(volta->anchor()), int(Volta::VOLTA_ANCHOR));
volta->setAnchor(Volta::VOLTA_ANCHOR);
}
adjustPlacement(volta);
}

Expand Down Expand Up @@ -3403,7 +3408,7 @@ static void readStyle(MStyle* style, XmlReader& e)
style->chordList()->clear();
style->chordList()->read(e);
style->setCustomChordList(true);
for (ChordFont f : style->chordList()->fonts) {
for (ChordFont& f : style->chordList()->fonts) {
if (f.family == "MuseJazz") {
f.family = "MuseJazz Text";
}
Expand Down Expand Up @@ -3704,7 +3709,7 @@ static bool readScore(Score* score, XmlReader& e)
#endif
score->fixTicks();

for (Part* p : score->parts()) {
for (Part*& p : score->parts()) {
p->updateHarmonyChannels(false);
}

Expand Down Expand Up @@ -3815,10 +3820,10 @@ Score::FileError MasterScore::read206(XmlReader& e)
setEnableVerticalSpread(false);

int id = 1;
for (LinkedElements* le : e.linkIds())
for (LinkedElements*& le : e.linkIds())
le->setLid(this, id++);

for (Staff* s : staves())
for (Staff*& s : staves())
s->updateOttava();

// fix segment span
Expand Down Expand Up @@ -3858,7 +3863,7 @@ Score::FileError MasterScore::read206(XmlReader& e)
// fix positions
// offset = saved offset - layout position
doLayout();
for (auto i : e.fixOffsets()) {
for (auto& i : e.fixOffsets()) {
i.first->setOffset(i.second - i.first->pos());
}

Expand Down
5 changes: 3 additions & 2 deletions libmscore/spanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Note* Spanner::startElementFromSpanner(Spanner* sp, Element* newEnd)
int newTrack = (newEnd->track() - oldEnd->track()) + oldStart->track();
// look in notes linked to oldStart for a note with the
// same score as new score and appropriate track
for (ScoreElement* newEl : oldStart->linkList())
for (ScoreElement*& newEl : oldStart->linkList())
if (toNote(newEl)->score() == score && toNote(newEl)->track() == newTrack) {
newStart = toNote(newEl);
break;
Expand Down Expand Up @@ -753,7 +753,7 @@ Note* Spanner::endElementFromSpanner(Spanner* sp, Element* newStart)
int newTrack = newStart->track() + (oldEnd->track() - oldStart->track());
// look in notes linked to oldEnd for a note with the
// same score as new score and appropriate track
for (ScoreElement* newEl : oldEnd->linkList())
for (ScoreElement*& newEl : oldEnd->linkList())
if (toNote(newEl)->score() == score && toNote(newEl)->track() == newTrack) {
newEnd = toNote(newEl);
break;
Expand Down Expand Up @@ -872,6 +872,7 @@ Measure* Spanner::startMeasure() const

Measure* Spanner::endMeasure() const
{
Q_ASSERT(anchor() == Spanner::Anchor::MEASURE);
return toMeasure(_endElement);
}

Expand Down
10 changes: 9 additions & 1 deletion libmscore/volta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "style.h"
#include "system.h"
#include "tempo.h"
#include "text.h"
#include "xml.h"

#include <algorithm>
Expand Down Expand Up @@ -142,7 +141,11 @@ void Volta::read(XmlReader& e)
const QStringRef& tag(e.name());
if (tag == "endings") {
QString s = e.readElementText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QStringList sl = s.split(",", Qt::SkipEmptyParts);
#else
QStringList sl = s.split(",", QString::SkipEmptyParts);
#endif
_endings.clear();
for (const QString& l : qAsConst(sl)) {
int i = l.simplified().toInt();
Expand All @@ -154,6 +157,11 @@ void Volta::read(XmlReader& e)
else if (!readProperties(e))
e.unknown();
}
if (this->anchor() != Volta::VOLTA_ANCHOR) {
// Volta strictly assumes that its anchor is measure, so don't let old scores override this.
qWarning("Correcting volta anchor type from %d to %d", int(this->anchor()), int(Volta::VOLTA_ANCHOR));
this->setAnchor(Volta::VOLTA_ANCHOR);
}
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/volta.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class VoltaSegment final : public TextLineBaseSegment {

class Volta final : public TextLineBase {
QList<int> _endings;
static constexpr Anchor VOLTA_ANCHOR = Anchor::MEASURE;

public:
static constexpr Anchor VOLTA_ANCHOR = Anchor::MEASURE;
enum class Type : char {
OPEN, CLOSED
};
Expand Down

0 comments on commit 69a0e68

Please sign in to comment.