Skip to content

Commit

Permalink
(Code review) Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup authored and Jojo-Schmitz committed Feb 28, 2025
1 parent 0f41f08 commit fc5de43
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
5 changes: 5 additions & 0 deletions src/engraving/dom/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Ret Score::sanityCheckLocal()
};

setHasCorruptedMeasures(false);

for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
Fraction mLen = m->ticks();
size_t endStaff = staves().size();
Expand All @@ -159,6 +160,7 @@ Ret Score::sanityCheckLocal()
Fraction voices[VOICES];

m->setCorrupted(staffIdx, false);
setHasCorruptedMeasures(true);

for (Segment* s = m->first(SegmentType::ChordRest); s; s = s->next(SegmentType::ChordRest)) {
for (voice_idx_t v = 0; v < VOICES; ++v) {
Expand Down Expand Up @@ -189,13 +191,15 @@ Ret Score::sanityCheckLocal()
errors << muse::mtrc("engraving", "<b>Corrupted measure</b>: %1, measure %2, staff %3.")
.arg(excerptInfo()).arg(mNumber).arg(staffIdx + 1);
m->setCorrupted(staffIdx, true);
setHasCorruptedMeasures(true);
}

if (voices[0] != mLen) {
//: %1 describes in which score the corruption is (either `Full score` or `"[part name]" part score`)
errors << muse::mtrc("engraving", "<b>Incomplete measure</b>: %1, measure %2, staff %3. Found: %4. Expected: %5.")
.arg(excerptInfo()).arg(mNumber).arg(staffIdx + 1).arg(voices[0].toString(), mLen.toString());
m->setCorrupted(staffIdx, true);
setHasCorruptedMeasures(true);
// try to fix a bad full measure rest
if (fmrest0) {
// fmrest0->setDuration(mLen * fmrest0->staff()->timeStretch(fmrest0->tick()));
Expand All @@ -209,6 +213,7 @@ Ret Score::sanityCheckLocal()
errors << muse::mtrc("engraving", "<b>Voice too long</b>: %1, measure %2, staff %3, voice %4. Found: %5. Expected: %6.")
.arg(excerptInfo()).arg(mNumber).arg(staffIdx + 1).arg(v + 1).arg(voices[v].toString(), mLen.toString());
m->setCorrupted(staffIdx, true);
setHasCorruptedMeasures(true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/score/debugpaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void DebugPaint::paintPageDebug(Painter& painter, const Page* page, const std::v
}
}

if (score->hasCorruptedMeasures() && options.showCorruptedMeasures) {
if (options.showCorruptedMeasures && score->hasCorruptedMeasures()) {
painter.setPen(Pen(Color::RED, 4.0));
painter.setBrush(BrushStyle::NoBrush);

Expand Down
45 changes: 23 additions & 22 deletions src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,6 @@ const std::unordered_map<ActionCode, bool EngravingDebuggingOptions::*> Notation
{ "show-corrupted-measures", &EngravingDebuggingOptions::showCorruptedMeasures }
};

void NotationActionController::checkForScoreCorruptions()
{
String name = currentMasterNotation()->masterScore()->name();
Ret ret = currentMasterNotation()->masterScore()->sanityCheck();
if (ret) {
std::string title = muse::mtrc("project", "Score “%1” seems to be sane and healthy").arg(name).toStdString();
std::string body = muse::trc("project",
"This score does not seem to contain errors that could cause MuseScore Studio to malfunction.");

interactive()->info(title, body, {
interactive()->buttonData(IInteractive::Button::Ok) }).button();
} else {
std::string title = muse::mtrc("project", "Score “%1” is corrupted").arg(name).toStdString();
std::string body = muse::trc("project", "This score contains errors that could cause MuseScore Studio to malfunction.\n"
"Fix those at the earliest to prevent crashes and further corruptions.");

interactive()->warning(title, body, ret.text(), {
interactive()->buttonData(IInteractive::Button::Ok) }).button();
}
return;
}

void NotationActionController::init()
{
TRACEFUNC;
Expand Down Expand Up @@ -2309,6 +2287,29 @@ bool NotationActionController::isToggleVisibleAllowed() const
return false;
}

void NotationActionController::checkForScoreCorruptions()
{
project::INotationProjectPtr project = globalContext()->currentProject();
if (!project) {
return;
}

String fileName = io::filename(project->path()).toString();

Ret ret = project->masterNotation()->masterScore()->sanityCheck();
if (ret) {
std::string title = muse::mtrc("project", "File “%1” seems not corrupted").arg(fileName).toStdString();
std::string body = muse::trc("project", "This file does not seem to contain errors.");
interactive()->info(title, body);
} else {
std::string title = muse::mtrc("project", "File “%1” is corrupted").arg(fileName).toStdString();
std::string body = muse::trc("project", "This file contains errors that could cause MuseScore Studio to malfunction.\n"
"Please fix those at the earliest, to prevent crashes and further corruptions.");

interactive()->warning(title, body, ret.text());
}
}

void NotationActionController::registerAction(const ActionCode& code,
std::function<void()> handler, bool (NotationActionController::* isEnabled)() const)
{
Expand Down
5 changes: 3 additions & 2 deletions src/notation/internal/notationactioncontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class NotationActionController : public muse::actions::Actionable, public muse::
public:
void init();

void checkForScoreCorruptions();

bool canReceiveAction(const muse::actions::ActionCode& code) const override;

muse::async::Notification currentNotationChanged() const;
Expand Down Expand Up @@ -224,6 +222,9 @@ class NotationActionController : public muse::actions::Actionable, public muse::
bool isNotationPage() const;
bool isStandardStaff() const;
bool isTablatureStaff() const;

void checkForScoreCorruptions();

void registerAction(const muse::actions::ActionCode&, void (NotationActionController::*)(const muse::actions::ActionData& data),
bool (NotationActionController::*)() const = &NotationActionController::isNotationPage);
void registerAction(const muse::actions::ActionCode&, void (NotationActionController::*)(),
Expand Down
1 change: 1 addition & 0 deletions src/notation/internal/notationuiactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,7 @@ const UiActionList NotationUiActions::m_engravingDebuggingActions = {
mu::context::UiCtxProjectOpened,
mu::context::CTX_NOTATION_OPENED,
TranslatableString("action", "Show element masks"),
TranslatableString("action", "Show/hide element masks"),
Checkable::Yes
),
UiAction("show-corrupted-measures",
Expand Down

0 comments on commit fc5de43

Please sign in to comment.