Skip to content

Commit

Permalink
Fix #330595: Crash on selecting entire score after XML import
Browse files Browse the repository at this point in the history
Backport of musescore#10860, plus a fix on importing an empty XML file, which
apparently doesn't apply to master. For master it got fix in musescore#8200,
in 3.x it got fixed in musescore#8199, but broke again with the port of musescore#8530.
Converting some `foreach(..., ...)` into `for (... : ...)` along the way.
  • Loading branch information
Jojo-Schmitz committed Mar 24, 2022
1 parent b287f3c commit 0dcde3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static Fraction lastChordTicks(const Segment* s, const Fraction& tick)
void MusicXmlLyricsExtend::setExtend(const int no, const int track, const Fraction& tick)
{
QList<Lyrics*> list;
foreach(Lyrics* l, _lyrics) {
for (Lyrics* l : _lyrics) {
Element* const el = l->parent();
if (el->type() == ElementType::CHORD || el->type() == ElementType::REST) {
ChordRest* const par = static_cast<ChordRest*>(el);
Expand All @@ -180,7 +180,7 @@ void MusicXmlLyricsExtend::setExtend(const int no, const int track, const Fracti
}
}
// cleanup
foreach(Lyrics* l, list) {
for (Lyrics* l: list) {
_lyrics.remove(l);
}
}
Expand Down Expand Up @@ -950,7 +950,7 @@ static Fraction calculateTupletDuration(const Tuplet* const t)
{
Fraction res;

foreach (DurationElement* de, t->elements()) {
for (DurationElement* de : t->elements()) {
if (de->type() == ElementType::CHORD || de->type() == ElementType::REST) {
const auto cr = static_cast<ChordRest*>(de);
const auto fraction = cr->ticks(); // TODO : take care of nested tuplets
Expand Down Expand Up @@ -1027,7 +1027,7 @@ static void handleTupletStop(Tuplet*& tuplet, const int normalNotes)
tuplet->setTicks(f);
// TODO determine usefulness of following check
int totalDuration = 0;
foreach (DurationElement* de, tuplet->elements()) {
for (DurationElement* de : tuplet->elements()) {
if (de->type() == ElementType::CHORD || de->type() == ElementType::REST) {
totalDuration+=de->globalTicks().ticks();
}
Expand Down Expand Up @@ -1497,7 +1497,7 @@ static void resetTuplets(Tuplets& tuplets)

static void cleanFretDiagrams(Measure* measure)
{
if (measure->no() > 0)
if (!measure || measure->no() > 0)
return;
// Case 1: Dummy hidden first measure with all fretboards attached
bool isDummyMeasure = toMeasureBase(measure)->lineBreak();
Expand Down Expand Up @@ -2318,7 +2318,7 @@ static void markUserAccidentals(const int firstStaff,
if (!e || e->type() != Ms::ElementType::CHORD)
continue;
Chord* chord = static_cast<Chord*>(e);
foreach (Note* nt, chord->notes()) {
for (Note* nt : chord->notes()) {
if (alterMap.contains(nt)) {
int alter = alterMap.value(nt);
int ln = absStep(nt->tpc(), nt->pitch());
Expand Down Expand Up @@ -4480,7 +4480,7 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure, cons
QStringList sl = number.split(",", QString::SkipEmptyParts);
QList<int> iEndingNumbers;
bool unsupported = false;
foreach(const QString &s, sl) {
for (const QString &s : sl) {
int iEndingNumber = s.toInt();
if (iEndingNumber <= 0) {
unsupported = true;
Expand Down Expand Up @@ -5283,7 +5283,7 @@ static void addFiguredBassElemens(FiguredBassList& fbl, const Fraction noteStart
{
if (!fbl.isEmpty()) {
auto sTick = noteStartTime; // starting tick
foreach (FiguredBass* fb, fbl) {
for (FiguredBass* fb : fbl) {
fb->setTrack(msTrack);
// No duration tag defaults ticks() to 0; set to note value
if (fb->ticks().isZero())
Expand Down
14 changes: 7 additions & 7 deletions libmscore/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void Selection::appendChord(Chord* chord)
for (Note* note : chord->notes()) {
_el.append(note);
if (note->accidental()) _el.append(note->accidental());
foreach(Element* el, note->el())
for (Element* el : note->el())
appendFiltered(el);
for (NoteDot* dot : note->dots())
_el.append(dot);
Expand All @@ -494,15 +494,15 @@ void Selection::appendChord(Chord* chord)
if (note->tieFor()->endElement()->isNote()) {
Note* endNote = toNote(note->tieFor()->endElement());
Segment* s = endNote->chord()->segment();
if (s->tick() < tickEnd())
if (!s || s->tick() < tickEnd())
_el.append(note->tieFor());
}
}
for (Spanner* sp : note->spannerFor()) {
if (sp->endElement()->isNote()) {
Note* endNote = toNote(sp->endElement());
Segment* s = endNote->chord()->segment();
if (s->tick() < tickEnd())
if (!s || s->tick() < tickEnd())
_el.append(sp);
}
}
Expand Down Expand Up @@ -689,7 +689,7 @@ void Selection::dump()
case SelState::RANGE: qDebug("RANGE"); break;
case SelState::LIST: qDebug("LIST"); break;
}
foreach(const Element* e, _el)
for (const Element* e : _el)
qDebug(" %p %s", e, e->name());
}

Expand Down Expand Up @@ -879,7 +879,7 @@ QByteArray Selection::symbolListMimeData() const
std::multimap<qint64, MapData> map;

// scan selection element list, inserting relevant elements in a tick-sorted map
foreach (Element* e, _el) {
for (Element* e : _el) {
switch (e->type()) {
/* All these element types are ignored:
Expand Down Expand Up @@ -1050,7 +1050,7 @@ Enabling copying of more element types requires enabling pasting in Score::paste
if (seg->isChordRestType()) {
// if no ChordRest in right track, look in anotations
if (seg->element(currTrack) == nullptr) {
foreach (Element* el, seg->annotations()) {
for (Element* el : seg->annotations()) {
// do annotations include our element?
if (el == iter->second.e) {
done = true;
Expand Down Expand Up @@ -1098,7 +1098,7 @@ std::vector<Note*> Selection::noteList(int selTrack) const
std::vector<Note*>nl;

if (_state == SelState::LIST) {
foreach(Element* e, _el) {
for (Element* e : _el) {
if (e->isNote())
nl.push_back(toNote(e));
}
Expand Down

0 comments on commit 0dcde3c

Please sign in to comment.