From fc5de439d3f30aaf7f265b258881f5ebd6f3b6a2 Mon Sep 17 00:00:00 2001
From: Casper Jeukendrup <48658420+cbjeukendrup@users.noreply.github.com>
Date: Thu, 27 Feb 2025 03:34:44 +0100
Subject: [PATCH] (Code review) Fixes
---
src/engraving/dom/check.cpp | 5 +++
src/engraving/rendering/score/debugpaint.cpp | 2 +-
.../internal/notationactioncontroller.cpp | 45 ++++++++++---------
.../internal/notationactioncontroller.h | 5 ++-
src/notation/internal/notationuiactions.cpp | 1 +
5 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/src/engraving/dom/check.cpp b/src/engraving/dom/check.cpp
index 1080c90752610..a44a52f81f650 100644
--- a/src/engraving/dom/check.cpp
+++ b/src/engraving/dom/check.cpp
@@ -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();
@@ -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) {
@@ -189,6 +191,7 @@ Ret Score::sanityCheckLocal()
errors << muse::mtrc("engraving", "Corrupted measure: %1, measure %2, staff %3.")
.arg(excerptInfo()).arg(mNumber).arg(staffIdx + 1);
m->setCorrupted(staffIdx, true);
+ setHasCorruptedMeasures(true);
}
if (voices[0] != mLen) {
@@ -196,6 +199,7 @@ Ret Score::sanityCheckLocal()
errors << muse::mtrc("engraving", "Incomplete measure: %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()));
@@ -209,6 +213,7 @@ Ret Score::sanityCheckLocal()
errors << muse::mtrc("engraving", "Voice too long: %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);
}
}
}
diff --git a/src/engraving/rendering/score/debugpaint.cpp b/src/engraving/rendering/score/debugpaint.cpp
index cd02903c559a5..914e9cf92cd02 100644
--- a/src/engraving/rendering/score/debugpaint.cpp
+++ b/src/engraving/rendering/score/debugpaint.cpp
@@ -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);
diff --git a/src/notation/internal/notationactioncontroller.cpp b/src/notation/internal/notationactioncontroller.cpp
index c7be858169f41..4b33df3ddc30e 100644
--- a/src/notation/internal/notationactioncontroller.cpp
+++ b/src/notation/internal/notationactioncontroller.cpp
@@ -73,28 +73,6 @@ const std::unordered_map 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;
@@ -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 handler, bool (NotationActionController::* isEnabled)() const)
{
diff --git a/src/notation/internal/notationactioncontroller.h b/src/notation/internal/notationactioncontroller.h
index 28d88905c29f0..6c73ea60f12ad 100644
--- a/src/notation/internal/notationactioncontroller.h
+++ b/src/notation/internal/notationactioncontroller.h
@@ -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;
@@ -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::*)(),
diff --git a/src/notation/internal/notationuiactions.cpp b/src/notation/internal/notationuiactions.cpp
index 050d333dc28ac..5ccd154cda4f1 100644
--- a/src/notation/internal/notationuiactions.cpp
+++ b/src/notation/internal/notationuiactions.cpp
@@ -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",