Skip to content

Commit

Permalink
Merge pull request musescore#15935 from Eism/score_corrupted_added_case
Browse files Browse the repository at this point in the history
Added another case in which the score is considered corrupted
  • Loading branch information
Eism committed Jan 23, 2023
2 parents bb38af9 + a1f9222 commit c072186
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
26 changes: 25 additions & 1 deletion src/engraving/libmscore/check.cpp
Expand Up @@ -114,15 +114,23 @@ Ret Score::sanityCheck()
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
Fraction mLen = m->ticks();
size_t endStaff = staves().size();

for (size_t staffIdx = 0; staffIdx < endStaff; ++staffIdx) {
Rest* fmrest0 = 0; // full measure rest in voice 0
Fraction voices[VOICES];

#ifndef NDEBUG
m->setCorrupted(staffIdx, false);
#endif

for (Segment* s = m->first(SegmentType::ChordRest); s; s = s->next(SegmentType::ChordRest)) {
for (size_t v = 0; v < VOICES; ++v) {
ChordRest* cr = toChordRest(s->element(static_cast<int>(staffIdx) * VOICES + static_cast<int>(v)));
EngravingItem* element = s->element(static_cast<int>(staffIdx) * VOICES + static_cast<int>(v));
if (!element) {
continue;
}

ChordRest* cr = toChordRest(element);
if (cr == 0) {
continue;
}
Expand All @@ -136,6 +144,21 @@ Ret Score::sanityCheck()
}
}

bool checkRepeats = m->isMeasureRepeatGroup(staffIdx);
bool repeatsIsValid = true;

if (checkRepeats) {
repeatsIsValid = m->measureRepeatElement(staffIdx) != nullptr;
}

if (!repeatsIsValid) {
errors << mtrc("engraving", u"<b>Corrupted measure</b>: Measure %1, Staff %2.")
.arg(mNumber).arg(staffIdx + 1);
#ifndef NDEBUG
m->setCorrupted(staffIdx, true);
#endif
}

if (voices[0] != mLen) {
errors << mtrc("engraving", u"<b>Incomplete measure</b>: Measure %1, Staff %2. Found: %3. Expected: %4.")
.arg(mNumber).arg(staffIdx + 1).arg(voices[0].toString(), mLen.toString());
Expand All @@ -158,6 +181,7 @@ Ret Score::sanityCheck()
}
}
}

mNumber++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/measure.cpp
Expand Up @@ -3081,7 +3081,7 @@ MeasureRepeat* Measure::measureRepeatElement(staff_idx_t staffIdx) const
track_idx_t etrack = staff2track(staffIdx + 1);
for (track_idx_t track = strack; track < etrack; ++track) {
// should only be in first track, but just in case
for (Segment* s = m->first(SegmentType::ChordRest); s && s != m->last(); s = s->next(SegmentType::ChordRest)) {
for (Segment* s = m->first(SegmentType::ChordRest); s; s = s->next(SegmentType::ChordRest)) {
// should only be in first segment, but just in case
EngravingItem* e = s->element(track);
if (e && e->isMeasureRepeat()) {
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/libmscore/rendermidi.cpp
Expand Up @@ -1139,9 +1139,14 @@ void MidiRenderer::renderStaffChunk(const Chunk& chunk, EventMap* events, const
if (m->isMeasureRepeatGroup(staffIdx)) {
MeasureRepeat* mr = m->measureRepeatElement(staffIdx);
Measure const* playMeasure = lastMeasure;
if (!playMeasure || !mr) {
continue;
}

for (int i = m->measureRepeatCount(staffIdx); i < mr->numMeasures() && playMeasure->prevMeasure(); ++i) {
playMeasure = playMeasure->prevMeasure();
}

int offset = (m->tick() - playMeasure->tick()).ticks();
collectMeasureEvents(events, playMeasure, sctx, tickOffset + offset);
} else {
Expand Down
15 changes: 11 additions & 4 deletions src/engraving/libmscore/rest.cpp
Expand Up @@ -1174,12 +1174,19 @@ void Rest::editDrag(EditData& editData)
bool Rest::shouldNotBeDrawn() const
{
const StaffType* st = staff() ? staff()->staffTypeForElement(this) : nullptr;
if (generated()
|| (st && st->isTabStaff() && (!st->showRests() || st->genDurations())
&& (!measure() || !measure()->isMMRest()))
|| (measure() && measure()->measureRepeatCount(staffIdx()))) {
if (generated()) {
return true;
}

if (st && st->isTabStaff() && (!st->showRests() || st->genDurations())
&& (!measure() || !measure()->isMMRest())) {
return true;
}

if (measure() && measure()->measureRepeatCount(staffIdx())) {
return true;
}

return false;
}

Expand Down

0 comments on commit c072186

Please sign in to comment.