Skip to content

Commit

Permalink
fix musescore#18065: add Capo if it is not in the Guitar palette
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPudashkin committed Jul 4, 2023
1 parent a64c3ab commit 9f63f47
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
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

0 comments on commit 9f63f47

Please sign in to comment.