Skip to content

Commit

Permalink
Migration of palette elements
Browse files Browse the repository at this point in the history
Introduce PaletteCompat class
  • Loading branch information
mike-spa committed May 26, 2023
1 parent 15d6c8b commit ed69724
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/engraving/rw/compat/compatutils.cpp
Expand Up @@ -49,6 +49,30 @@
using namespace mu::engraving;
using namespace mu::engraving::compat;

const std::set<SymId> CompatUtils::ORNAMENT_IDS {
SymId::ornamentTurn,
SymId::ornamentTurnInverted,
SymId::ornamentTurnSlash,
SymId::ornamentTrill,
SymId::brassMuteClosed,
SymId::ornamentMordent,
SymId::ornamentShortTrill,
SymId::ornamentTremblement,
SymId::ornamentPrallMordent,
SymId::ornamentLinePrall,
SymId::ornamentUpPrall,
SymId::ornamentUpMordent,
SymId::ornamentPrecompMordentUpperPrefix,
SymId::ornamentDownMordent,
SymId::ornamentPrallUp,
SymId::ornamentPrallDown,
SymId::ornamentPrecompSlide,
SymId::ornamentShake3,
SymId::ornamentShakeMuffat1,
SymId::ornamentTremblementCouperin,
SymId::ornamentPinceCouperin
};

void CompatUtils::doCompatibilityConversions(MasterScore* masterScore)
{
if (!masterScore) {
Expand Down Expand Up @@ -190,30 +214,6 @@ void CompatUtils::assignInitialPartToExcerpts(const std::vector<Excerpt*>& excer

void CompatUtils::replaceOldWithNewOrnaments(MasterScore* score)
{
static const std::set<SymId> ornamentIds {
SymId::ornamentTurn,
SymId::ornamentTurnInverted,
SymId::ornamentTurnSlash,
SymId::ornamentTrill,
SymId::brassMuteClosed,
SymId::ornamentMordent,
SymId::ornamentShortTrill,
SymId::ornamentTremblement,
SymId::ornamentPrallMordent,
SymId::ornamentLinePrall,
SymId::ornamentUpPrall,
SymId::ornamentUpMordent,
SymId::ornamentPrecompMordentUpperPrefix,
SymId::ornamentDownMordent,
SymId::ornamentPrallUp,
SymId::ornamentPrallDown,
SymId::ornamentPrecompSlide,
SymId::ornamentShake3,
SymId::ornamentShakeMuffat1,
SymId::ornamentTremblementCouperin,
SymId::ornamentPinceCouperin
};

std::set<Articulation*> oldOrnaments; // ornaments used to be articulations

for (Measure* meas = score->firstMeasure(); meas; meas = meas->nextMeasure()) {
Expand All @@ -229,7 +229,7 @@ void CompatUtils::replaceOldWithNewOrnaments(MasterScore* score)
if (articulation->isOrnament()) {
continue;
}
if (ornamentIds.find(articulation->symId()) != ornamentIds.end()) {
if (ORNAMENT_IDS.find(articulation->symId()) != ORNAMENT_IDS.end()) {
oldOrnaments.insert(articulation);
LinkedObjects* links = articulation->links();
if (!links || links->empty()) {
Expand Down
4 changes: 4 additions & 0 deletions src/engraving/rw/compat/compatutils.h
Expand Up @@ -23,10 +23,12 @@
#define MU_ENGRAVING_COMPATUTILS_H

#include <vector>
#include <set>

#include "libmscore/articulation.h"

namespace mu::engraving {
enum class SymId;
class Score;
class MasterScore;
class Excerpt;
Expand All @@ -46,6 +48,8 @@ class CompatUtils
static void reconstructTypeOfCustomDynamics(MasterScore* score);
static DynamicType reconstructDynamicTypeFromString(Dynamic* dynamic);
static ArticulationAnchor translateToNewArticulationAnchor(int anchor);

static const std::set<SymId> ORNAMENT_IDS;
};
}
#endif // MU_ENGRAVING_COMPATUTILS_H
2 changes: 2 additions & 0 deletions src/palette/CMakeLists.txt
Expand Up @@ -58,6 +58,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/palettecelliconengine.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/palettecelliconengine.h
${CMAKE_CURRENT_LIST_DIR}/internal/mimedatautils.h
${CMAKE_CURRENT_LIST_DIR}/internal/palettecompat.h
${CMAKE_CURRENT_LIST_DIR}/internal/palettecompat.cpp

${CMAKE_CURRENT_LIST_DIR}/view/paletterootmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/paletterootmodel.h
Expand Down
2 changes: 2 additions & 0 deletions src/palette/internal/palettecell.cpp
Expand Up @@ -20,6 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "palettecell.h"
#include "palettecompat.h"

#include "mimedatautils.h"

Expand Down Expand Up @@ -206,6 +207,7 @@ bool PaletteCell::read(XmlReader& e, bool pasteMode)
rw400::ReadContext ctx;
ctx.setPasteMode(pasteMode);
rw400::TRead::readItem(element.get(), e, ctx);
PaletteCompat::migrateOldPaletteItemIfNeeded(element, gpaletteScore);
element->styleChanged();

if (element->type() == ElementType::ACTION_ICON) {
Expand Down
75 changes: 75 additions & 0 deletions src/palette/internal/palettecompat.cpp
@@ -0,0 +1,75 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <memory>

#include "palettecompat.h"

#include "engraving/rw/compat/compatutils.h"

#include "libmscore/articulation.h"
#include "libmscore/chordrest.h"
#include "libmscore/engravingitem.h"
#include "libmscore/expression.h"
#include "libmscore/factory.h"
#include "libmscore/ornament.h"
#include "libmscore/score.h"
#include "libmscore/stafftext.h"
#include "engraving/types/symid.h"

using namespace mu::palette;
using namespace mu::engraving;

void PaletteCompat::migrateOldPaletteItemIfNeeded(ElementPtr& element, Score* paletteScore)
{
if (paletteScore->mscVersion() >= 410) {
return;
}

EngravingItem* item = element.get();

if (item->isArticulation()) {
const std::set<SymId>& ornamentIds = compat::CompatUtils::ORNAMENT_IDS;
bool isOldOrnament = ornamentIds.find(toArticulation(item)->symId()) != ornamentIds.end();

if (!isOldOrnament) {
return;
}

Articulation* oldOrnament = toArticulation(item);
Ornament* newOrnament = Factory::createOrnament((ChordRest*)(paletteScore->dummy()->chord()));
newOrnament->setSymId(oldOrnament->symId());
element.reset(newOrnament);
return;
}

if (item->isStaffText() && toStaffText(item)->textStyleType() == TextStyleType::EXPRESSION) {
StaffText* oldExpression = toStaffText(item);
Expression* newExpression = Factory::createExpression(paletteScore->dummy()->segment());
if (oldExpression->xmlText() == "Expression") {
newExpression->setXmlText("expression");
} else {
newExpression->setXmlText(oldExpression->xmlText());
}
element.reset(newExpression);
}
}
35 changes: 35 additions & 0 deletions src/palette/internal/palettecompat.h
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef MU_PALETTE_PALETTECOMPAT_H
#define MU_PALETTE_PALETTECOMPAT_H

#include "libmscore/engravingitem.h"

namespace mu::palette {
class PaletteCompat
{
public:
static void migrateOldPaletteItemIfNeeded(engraving::ElementPtr& element, engraving::Score* paletteScore);
};
} // namespace mu::palette
#endif // MU_PALETTE_PALETTECOMPAT_H

0 comments on commit ed69724

Please sign in to comment.