Skip to content

Commit

Permalink
Merge pull request musescore#18387 from RomanPudashkin/capo_compat
Browse files Browse the repository at this point in the history
capo_compat
  • Loading branch information
RomanPudashkin committed Jul 5, 2023
2 parents e190d03 + 06904c2 commit 7a20137
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/engraving/libmscore/factory.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions src/engraving/types/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/palette/internal/palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "palettelayout.h"

#include "palettecell.h"
#include "palettecompat.h"

#include "log.h"

Expand Down Expand Up @@ -317,6 +318,8 @@ bool Palette::read(XmlReader& e, bool pasteMode)
m_type = guessType();
}

PaletteCompat::addNewItemsIfNeeded(*this, gpaletteScore);

return true;
}

Expand Down
30 changes: 30 additions & 0 deletions src/palette/internal/palettecompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Capo>(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);
}
}
5 changes: 5 additions & 0 deletions src/palette/internal/palettecompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/stubs/braille/qml/MuseScore/Braille/BrailleView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7a20137

Please sign in to comment.