From d7495182976b1c9ab554e22f4c04b1d06717b3c7 Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Thu, 3 Mar 2022 13:32:59 +0200 Subject: [PATCH] various optimizations --- src/notation/internal/notationparts.cpp | 40 ++++++++++++++++++++++--- src/notation/notationtypes.h | 27 +++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index 3e487f4f93..4d19852987 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -121,7 +121,7 @@ bool NotationParts::staffExists(const ID& staffId) const StaffConfig NotationParts::staffConfig(const ID& staffId) const { - Staff* staff = this->staffModifiable(staffId); + Staff* staff = staffModifiable(staffId); if (!staff) { return StaffConfig(); } @@ -285,9 +285,14 @@ void NotationParts::setPartSharpFlat(const ID& partId, const SharpFlat& sharpFla return; } + int shartFlatInt = static_cast(sharpFlat); + if (part->getProperty(Ms::Pid::PREFER_SHARP_FLAT) == shartFlatInt) { + return; + } + startEdit(); - part->undoChangeProperty(Ms::Pid::PREFER_SHARP_FLAT, static_cast(sharpFlat)); + part->undoChangeProperty(Ms::Pid::PREFER_SHARP_FLAT, shartFlatInt); apply(); @@ -364,9 +369,19 @@ void NotationParts::setInstrumentName(const InstrumentKey& instrumentKey, const return; } + const Ms::Instrument* instrument = part->instrument(instrumentKey.tick); + if (!instrument) { + return; + } + + QList newNames { StaffName(name, 0) }; + if (instrument->longNames() == newNames) { + return; + } + startEdit(); - score()->undo(new Ms::ChangeInstrumentLong(instrumentKey.tick, part, { StaffName(name, 0) })); + score()->undo(new Ms::ChangeInstrumentLong(instrumentKey.tick, part, newNames)); apply(); @@ -382,6 +397,15 @@ void NotationParts::setInstrumentAbbreviature(const InstrumentKey& instrumentKey return; } + const Ms::Instrument* instrument = part->instrument(instrumentKey.tick); + if (!instrument) { + return; + } + + if (instrument->abbreviature() == abbreviature) { + return; + } + startEdit(); score()->undo(new Ms::ChangeInstrumentShort(instrumentKey.tick, part, { StaffName(abbreviature, 0) })); @@ -448,13 +472,17 @@ void NotationParts::setStaffType(const ID& staffId, StaffType type) { TRACEFUNC; - Staff* staff = this->staffModifiable(staffId); + Staff* staff = staffModifiable(staffId); const Ms::StaffType* staffType = Ms::StaffType::preset(type); if (!staff || !staffType) { return; } + if (staff->staffType(DEFAULT_TICK) == staffType) { + return; + } + startEdit(); score()->undo(new Ms::ChangeStaffType(staff, *staffType)); @@ -473,6 +501,10 @@ void NotationParts::setStaffConfig(const ID& staffId, const StaffConfig& config) return; } + if (staffConfig(staffId) == config) { + return; + } + startEdit(); doSetStaffConfig(staff, config); diff --git a/src/notation/notationtypes.h b/src/notation/notationtypes.h index a1532aef99..2f775c6e2b 100644 --- a/src/notation/notationtypes.h +++ b/src/notation/notationtypes.h @@ -449,6 +449,33 @@ struct StaffConfig Staff::HideMode hideMode = Staff::HideMode::AUTO; engraving::NoteHeadScheme noteheadScheme = engraving::NoteHeadScheme::HEAD_AUTO; ClefTypeList clefTypeList; + + bool operator==(const StaffConfig& conf) const + { + bool equal = visible == conf.visible; + equal &= linesCount == conf.linesCount; + equal &= RealIsEqual(lineDistance, conf.lineDistance); + equal &= linesColor == conf.linesColor; + equal &= visibleLines == conf.visibleLines; + equal &= RealIsEqual(userDistance, conf.userDistance); + equal &= RealIsEqual(scale, conf.scale); + equal &= isSmall == conf.isSmall; + equal &= cutaway == conf.cutaway; + equal &= showIfEmpty == conf.showIfEmpty; + equal &= showClef == conf.showClef; + equal &= showTimeSignature == conf.showTimeSignature; + equal &= showKeySignature == conf.showKeySignature; + equal &= showBarlines == conf.showBarlines; + equal &= showStemless == conf.showStemless; + equal &= showLedgerLinesPitched == conf.showLedgerLinesPitched; + equal &= hideSystemBarline == conf.hideSystemBarline; + equal &= mergeMatchingRests == conf.mergeMatchingRests; + equal &= hideMode == conf.hideMode; + equal &= noteheadScheme == conf.noteheadScheme; + equal &= clefTypeList == conf.clefTypeList; + + return equal; + } }; struct TransposeOptions