Skip to content

Commit

Permalink
replace the old Capo (based on StaffText) with the new Capo item
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPudashkin committed Jul 5, 2023
1 parent 9f63f47 commit 377dfef
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/engraving/libmscore/factory.cpp
Expand Up @@ -712,3 +712,5 @@ PlayTechAnnotation* Factory::createPlayTechAnnotation(Segment * parent, PlayingT

return annotation;
}

CREATE_ITEM_IMPL(Capo, ElementType::CAPO, Segment, isAccessibleEnabled)
2 changes: 2 additions & 0 deletions src/engraving/libmscore/factory.h
Expand Up @@ -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);
};
Expand Down
66 changes: 66 additions & 0 deletions src/engraving/rw/compat/compatutils.cpp
Expand Up @@ -40,6 +40,7 @@
#include "libmscore/stafftext.h"
#include "libmscore/stafftextbase.h"
#include "libmscore/playtechannotation.h"
#include "libmscore/capo.h"

#include "types/string.h"

Expand Down Expand Up @@ -74,6 +75,8 @@ const std::set<SymId> CompatUtils::ORNAMENT_IDS {

void CompatUtils::doCompatibilityConversions(MasterScore* masterScore)
{
TRACEFUNC;

if (!masterScore) {
return;
}
Expand All @@ -90,6 +93,7 @@ void CompatUtils::doCompatibilityConversions(MasterScore* masterScore)
splitArticulations(masterScore);
resetArticulationOffsets(masterScore);
resetStemLengthsForTwoNoteTrems(masterScore);
replaceStaffTextWithCapo(masterScore);
}
}

Expand Down Expand Up @@ -560,3 +564,65 @@ void CompatUtils::resetStemLengthsForTwoNoteTrems(MasterScore* masterScore)
}
}
}

void CompatUtils::replaceStaffTextWithCapo(MasterScore* score)
{
TRACEFUNC;

std::set<StaffTextBase*> 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;
}
}
1 change: 1 addition & 0 deletions src/engraving/rw/compat/compatutils.h
Expand Up @@ -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

0 comments on commit 377dfef

Please sign in to comment.