From 9f63f47c7d91a71dcdbde39535e57688fb20ed77 Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Tue, 4 Jul 2023 11:41:43 +0300 Subject: [PATCH 1/3] fix #18065: add Capo if it is not in the Guitar palette --- src/engraving/types/constants.h | 1 + src/palette/internal/palette.cpp | 3 +++ src/palette/internal/palettecompat.cpp | 30 ++++++++++++++++++++++++++ src/palette/internal/palettecompat.h | 5 +++++ 4 files changed, 39 insertions(+) diff --git a/src/engraving/types/constants.h b/src/engraving/types/constants.h index 2d21d7761c7c1..6aaa8409962b5 100644 --- a/src/engraving/types/constants.h +++ b/src/engraving/types/constants.h @@ -83,6 +83,7 @@ struct Constants // - A bunch of new options for dynamics // - Clefs carry a "header" tag in the file (istead of trying to guess it from context) // - New "Ornament" item with new properties and options +// - New "Capo" item constexpr static int DIVISION = 480; constexpr static BeatsPerSecond DEFAULT_TEMPO = 2.0; //default tempo is equal 120 bpm diff --git a/src/palette/internal/palette.cpp b/src/palette/internal/palette.cpp index 00828be79b3ad..f863394198442 100644 --- a/src/palette/internal/palette.cpp +++ b/src/palette/internal/palette.cpp @@ -42,6 +42,7 @@ #include "palettelayout.h" #include "palettecell.h" +#include "palettecompat.h" #include "log.h" @@ -317,6 +318,8 @@ bool Palette::read(XmlReader& e, bool pasteMode) m_type = guessType(); } + PaletteCompat::addNewItemsIfNeeded(*this, gpaletteScore); + return true; } diff --git a/src/palette/internal/palettecompat.cpp b/src/palette/internal/palettecompat.cpp index 3308dd2956e0b..bcf9000147fb4 100644 --- a/src/palette/internal/palettecompat.cpp +++ b/src/palette/internal/palettecompat.cpp @@ -34,8 +34,12 @@ #include "libmscore/ornament.h" #include "libmscore/score.h" #include "libmscore/stafftext.h" +#include "libmscore/capo.h" #include "engraving/types/symid.h" +#include "palette.h" +#include "palettecell.h" + using namespace mu::palette; using namespace mu::engraving; @@ -69,3 +73,29 @@ void PaletteCompat::migrateOldPaletteItemIfNeeded(ElementPtr& element, Score* pa element.reset(newExpression); } } + +void PaletteCompat::addNewItemsIfNeeded(Palette& palette, Score* paletteScore) +{ + if (palette.type() == Palette::Type::Guitar) { + addNewGuitarItems(palette, paletteScore); + } +} + +void PaletteCompat::addNewGuitarItems(Palette& guitarPalette, Score* paletteScore) +{ + bool containsCapo = false; + + for (const PaletteCellPtr& cell : guitarPalette.cells()) { + if (cell->element && cell->element->isCapo()) { + containsCapo = true; + break; + } + } + + if (!containsCapo) { + auto capo = std::make_shared(paletteScore->dummy()->segment()); + capo->setXmlText(String::fromAscii(QT_TRANSLATE_NOOP("palette", "Capo"))); + int defaultPosition = std::min(7, guitarPalette.cellsCount()); + guitarPalette.insertElement(defaultPosition, capo, QT_TRANSLATE_NOOP("palette", "Capo"))->setElementTranslated(true); + } +} diff --git a/src/palette/internal/palettecompat.h b/src/palette/internal/palettecompat.h index 109b0191486c2..628a496020504 100644 --- a/src/palette/internal/palettecompat.h +++ b/src/palette/internal/palettecompat.h @@ -26,10 +26,15 @@ #include "libmscore/engravingitem.h" namespace mu::palette { +class Palette; class PaletteCompat { public: static void migrateOldPaletteItemIfNeeded(engraving::ElementPtr& element, engraving::Score* paletteScore); + static void addNewItemsIfNeeded(Palette& palette, engraving::Score* paletteScore); + +private: + static void addNewGuitarItems(Palette& guitarPalette, engraving::Score* paletteScore); }; } // namespace mu::palette #endif // MU_PALETTE_PALETTECOMPAT_H From 377dfef4c90e483b2ec0c971f7da5ab2222efaaf Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Tue, 4 Jul 2023 13:50:48 +0300 Subject: [PATCH 2/3] replace the old Capo (based on StaffText) with the new Capo item --- src/engraving/libmscore/factory.cpp | 2 + src/engraving/libmscore/factory.h | 2 + src/engraving/rw/compat/compatutils.cpp | 66 +++++++++++++++++++++++++ src/engraving/rw/compat/compatutils.h | 1 + 4 files changed, 71 insertions(+) diff --git a/src/engraving/libmscore/factory.cpp b/src/engraving/libmscore/factory.cpp index 4631e31c43dc8..b26994439060b 100644 --- a/src/engraving/libmscore/factory.cpp +++ b/src/engraving/libmscore/factory.cpp @@ -712,3 +712,5 @@ PlayTechAnnotation* Factory::createPlayTechAnnotation(Segment * parent, PlayingT return annotation; } + +CREATE_ITEM_IMPL(Capo, ElementType::CAPO, Segment, isAccessibleEnabled) diff --git a/src/engraving/libmscore/factory.h b/src/engraving/libmscore/factory.h index 349b32e96c09b..9a76c18b27a93 100644 --- a/src/engraving/libmscore/factory.h +++ b/src/engraving/libmscore/factory.h @@ -268,6 +268,8 @@ class Factory static PlayTechAnnotation* createPlayTechAnnotation(Segment* parent, PlayingTechniqueType techniqueType, TextStyleType styleType, bool isAccessibleEnabled = true); + static Capo* createCapo(Segment* parent, bool isAccessibleEnabled = true); + private: static EngravingItem* doCreateItem(ElementType type, EngravingItem* parent); }; diff --git a/src/engraving/rw/compat/compatutils.cpp b/src/engraving/rw/compat/compatutils.cpp index 078dfeda7abd6..ca2282546bf44 100644 --- a/src/engraving/rw/compat/compatutils.cpp +++ b/src/engraving/rw/compat/compatutils.cpp @@ -40,6 +40,7 @@ #include "libmscore/stafftext.h" #include "libmscore/stafftextbase.h" #include "libmscore/playtechannotation.h" +#include "libmscore/capo.h" #include "types/string.h" @@ -74,6 +75,8 @@ const std::set CompatUtils::ORNAMENT_IDS { void CompatUtils::doCompatibilityConversions(MasterScore* masterScore) { + TRACEFUNC; + if (!masterScore) { return; } @@ -90,6 +93,7 @@ void CompatUtils::doCompatibilityConversions(MasterScore* masterScore) splitArticulations(masterScore); resetArticulationOffsets(masterScore); resetStemLengthsForTwoNoteTrems(masterScore); + replaceStaffTextWithCapo(masterScore); } } @@ -560,3 +564,65 @@ void CompatUtils::resetStemLengthsForTwoNoteTrems(MasterScore* masterScore) } } } + +void CompatUtils::replaceStaffTextWithCapo(MasterScore* score) +{ + TRACEFUNC; + + std::set oldCapoSet; + + for (Measure* measure = score->firstMeasure(); measure; measure = measure->nextMeasure()) { + for (Segment* segment = measure->first(); segment; segment = segment->next()) { + for (EngravingItem* annotation : segment->annotations()) { + if (!annotation || !annotation->isStaffTextBase()) { + continue; + } + + StaffTextBase* text = toStaffTextBase(annotation); + + if (text->capo() > 0) { + oldCapoSet.insert(text); + } else { + continue; + } + + LinkedObjects* links = text->links(); + if (!links || links->empty()) { + continue; + } + + for (EngravingObject* linked : *links) { + if (linked != text && linked && linked->isStaffTextBase()) { + oldCapoSet.insert(toStaffTextBase(linked)); + } + } + } + } + } + + for (StaffTextBase* oldCapo : oldCapoSet) { + Segment* parentSegment = oldCapo->segment(); + Capo* newCapo = Factory::createCapo(parentSegment); + + int capoFretPosition = oldCapo->capo() - 1; + + CapoParams params; + params.active = capoFretPosition > 0; + params.fretPosition = capoFretPosition; + + newCapo->setTrack(oldCapo->track()); + newCapo->setParams(params); + newCapo->setProperty(Pid::PLACEMENT, oldCapo->placement()); + + LinkedObjects* links = oldCapo->links(); + newCapo->setLinks(links); + if (links) { + links->push_back(newCapo); + } + + parentSegment->add(newCapo); + parentSegment->removeAnnotation(oldCapo); + + delete oldCapo; + } +} diff --git a/src/engraving/rw/compat/compatutils.h b/src/engraving/rw/compat/compatutils.h index 055c00395ef2f..540341c579775 100644 --- a/src/engraving/rw/compat/compatutils.h +++ b/src/engraving/rw/compat/compatutils.h @@ -55,6 +55,7 @@ class CompatUtils static void resetRestVerticalOffset(MasterScore* masterScore); static void resetArticulationOffsets(MasterScore* masterScore); static void resetStemLengthsForTwoNoteTrems(MasterScore* masterScore); + static void replaceStaffTextWithCapo(MasterScore* masterScore); }; } #endif // MU_ENGRAVING_COMPATUTILS_H From 06904c2ba56bcc89eb47e7a9fe69547f98ec1d3a Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Tue, 4 Jul 2023 14:47:14 +0300 Subject: [PATCH 3/3] don't show BrailleViewStub stub --- src/stubs/braille/qml/MuseScore/Braille/BrailleView.qml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/stubs/braille/qml/MuseScore/Braille/BrailleView.qml b/src/stubs/braille/qml/MuseScore/Braille/BrailleView.qml index f77b6134e6979..b9510acbf3916 100644 --- a/src/stubs/braille/qml/MuseScore/Braille/BrailleView.qml +++ b/src/stubs/braille/qml/MuseScore/Braille/BrailleView.qml @@ -29,13 +29,10 @@ Item { id: root property NavigationPanel navigationPanel: NavigationPanel { - name: "BrailleView" - enabled: root.enabled && root.visible + name: "BrailleViewStub" + enabled: false direction: NavigationPanel.Both } - StyledTextLabel { - anchors.centerIn: parent - text: "BrailleView stub" - } + visible: false }