Skip to content

Commit

Permalink
fixed musescore#16042: Show corrupted message before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Eism committed Jan 31, 2023
1 parent dd61065 commit 5efce80
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 70 deletions.
36 changes: 25 additions & 11 deletions src/engraving/engravingproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,36 @@ bool EngravingProject::readOnly() const

Ret EngravingProject::setupMasterScore(bool forceMode)
{
return doSetupMasterScore(m_masterScore, forceMode);
return doSetupMasterScore(forceMode);
}

Ret EngravingProject::doSetupMasterScore(MasterScore* score, bool forceMode)
Ret EngravingProject::doSetupMasterScore(bool forceMode)
{
TRACEFUNC;

score->createPaddingTable();
score->connectTies();
m_masterScore->createPaddingTable();
m_masterScore->connectTies();

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

score->rebuildMidiMapping();
score->setSoloMute();
m_masterScore->rebuildMidiMapping();
m_masterScore->setSoloMute();

for (Score* s : score->scoreList()) {
for (Score* s : m_masterScore->scoreList()) {
s->setPlaylistDirty();
s->addLayoutFlags(LayoutFlag::FIX_PITCH_VELO);
s->setLayoutAll();
}

score->updateChannel();
score->update();
m_masterScore->updateChannel();
m_masterScore->update();

if (!forceMode) {
return score->sanityCheck();
Ret ret = checkCorrupted();
m_isCorruptedUponLoading = !ret;
return ret;
}

return make_ok();
Expand Down Expand Up @@ -159,3 +161,15 @@ bool EngravingProject::writeMscz(MscWriter& writer, bool onlySelection, bool cre

return ok;
}

bool EngravingProject::isCorruptedUponLoading() const
{
return m_isCorruptedUponLoading;
}

Ret EngravingProject::checkCorrupted() const
{
TRACEFUNC;

return m_masterScore->sanityCheck();
}
9 changes: 8 additions & 1 deletion src/engraving/engravingproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,23 @@ class EngravingProject : public std::enable_shared_from_this<EngravingProject>
Ret loadMscz(const MscReader& msc, bool ignoreVersionError);
bool writeMscz(MscWriter& writer, bool onlySelection, bool createThumbnail);

bool isCorrupted() const;
bool isCorruptedUponLoading() const;

Ret checkCorrupted() const;

private:
friend class MasterScore;

EngravingProject();

void init(const MStyle& style);

Ret doSetupMasterScore(MasterScore* score, bool forceMode);
Ret doSetupMasterScore(bool forceMode);

MasterScore* m_masterScore = nullptr;

bool m_isCorruptedUponLoading = false;
};

using EngravingProjectPtr = std::shared_ptr<EngravingProject>;
Expand Down
3 changes: 3 additions & 0 deletions src/framework/global/types/ret.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class Ret

EngravingFirst = 2000,
EngravingLast = 2999,

ProjectFirst = 3000,
ProjectLast = 3999,
};

Ret() = default;
Expand Down
1 change: 1 addition & 0 deletions src/project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/projectmodule.cpp
${CMAKE_CURRENT_LIST_DIR}/projectmodule.h
${CMAKE_CURRENT_LIST_DIR}/projecttypes.h
${CMAKE_CURRENT_LIST_DIR}/projecterrors.h
${CMAKE_CURRENT_LIST_DIR}/inotationproject.h
${CMAKE_CURRENT_LIST_DIR}/iprojectcreator.h
${CMAKE_CURRENT_LIST_DIR}/inotationreader.h
Expand Down
4 changes: 3 additions & 1 deletion src/project/inotationproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ class INotationProject

virtual void markAsUnsaved() = 0;

virtual void revertChanges() = 0;

virtual ValNt<bool> needSave() const = 0;
virtual bool canSave() const = 0;
virtual Ret canSave() const = 0;

virtual Ret save(const io::path_t& path = io::path_t(), SaveMode saveMode = SaveMode::Save) = 0;
virtual Ret writeToDevice(QIODevice* device) = 0;
Expand Down
24 changes: 20 additions & 4 deletions src/project/internal/notationproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "io/buffer.h"

#include "libmscore/undo.h"

#include "engraving/engravingproject.h"
#include "engraving/compat/scoreaccess.h"
#include "engraving/compat/mscxcompat.h"
Expand All @@ -38,8 +40,7 @@
#include "notation/notationerrors.h"
#include "projectaudiosettings.h"
#include "projectfileinfoprovider.h"

#include "libmscore/undo.h"
#include "projecterrors.h"

#include "defer.h"
#include "log.h"
Expand Down Expand Up @@ -763,6 +764,11 @@ void NotationProject::markAsUnsaved()
m_masterNotation->masterScore()->setSaved(false);
}

void NotationProject::revertChanges()
{
load(path());
}

mu::ValNt<bool> NotationProject::needSave() const
{
ValNt<bool> needSave;
Expand All @@ -773,9 +779,19 @@ mu::ValNt<bool> NotationProject::needSave() const
return needSave;
}

bool NotationProject::canSave() const
Ret NotationProject::canSave() const
{
return m_masterNotation->hasParts();
if (!m_masterNotation->hasParts()) {
return make_ret(Err::NoPartsError);
}

Ret ret = m_engravingProject->checkCorrupted();
if (!ret) {
Err errorCode = m_engravingProject->isCorruptedUponLoading() ? Err::CorruptionUponOpenningError : Err::CorruptionError;
ret.setCode(static_cast<int>(errorCode));
}

return ret;
}

ProjectMeta NotationProject::metaInfo() const
Expand Down
4 changes: 3 additions & 1 deletion src/project/internal/notationproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class NotationProject : public INotationProject, public async::Asyncable

void markAsUnsaved() override;

void revertChanges() override;

ValNt<bool> needSave() const override;
bool canSave() const override;
Ret canSave() const override;

Ret save(const io::path_t& path = io::path_t(), SaveMode saveMode = SaveMode::Save) override;
Ret writeToDevice(QIODevice* device) override;
Expand Down

0 comments on commit 5efce80

Please sign in to comment.