diff --git a/src/engraving/dom/box.cpp b/src/engraving/dom/box.cpp index 4e4d2f6e2c716..dbdf7b9a38287 100644 --- a/src/engraving/dom/box.cpp +++ b/src/engraving/dom/box.cpp @@ -698,11 +698,6 @@ void FBox::add(EngravingItem* e) FretDiagram* fd = toFretDiagram(e); fd->setFlag(ElementFlag::MOVABLE, false); m_fretDiagrams.push_back(fd); - } else if (e->isHarmony()) { - Harmony* harmony = toHarmony(e); - harmony->setFlag(ElementFlag::MOVABLE, false); - harmony->setIsPlayable(false); - m_harmonies.push_back(harmony); } else { LOGD("FBox::add: element not allowed"); return; @@ -856,15 +851,10 @@ PropertyValue FBox::propertyDefault(Pid propertyId) const void FBox::init() { - for (Harmony* harmony : m_harmonies) { - harmony->deleteLater(); - } - for (FretDiagram* fretDiagram : m_fretDiagrams) { fretDiagram->deleteLater(); } - m_harmonies.clear(); m_fretDiagrams.clear(); for (mu::engraving::Segment* segment = score()->firstSegment(mu::engraving::SegmentType::ChordRest); segment; @@ -874,28 +864,18 @@ void FBox::init() continue; } - Harmony* harmony = nullptr; FretDiagram* fretDiagram = nullptr; if (item->isHarmony()) { - harmony = toHarmony(item)->clone(); + // todo + continue; } else if (item->isFretDiagram()) { fretDiagram = toFretDiagram(item)->clone(); - harmony = fretDiagram->harmony()->clone(); - } - - if (!harmony || !harmony->play()) { - continue; + fretDiagram->harmony()->setAutoplace(false); + fretDiagram->setAutoplace(false); } - add(harmony); - - if (!fretDiagram) { - // todo: generate and call add - m_fretDiagrams.push_back(nullptr); - } else { - add(fretDiagram); - } + add(fretDiagram); } } } diff --git a/src/engraving/dom/box.h b/src/engraving/dom/box.h index 50b6ee18be614..e1dd37726c54b 100644 --- a/src/engraving/dom/box.h +++ b/src/engraving/dom/box.h @@ -209,7 +209,6 @@ class FBox : public VBox bool setProperty(Pid propertyId, const PropertyValue& val) override; PropertyValue propertyDefault(Pid propertyId) const override; - const std::vector harmonies() const { return m_harmonies; } const std::vector fretDiagrams() const { return m_fretDiagrams; } void init(); @@ -229,7 +228,6 @@ class FBox : public VBox private: void resolveContentRect(); - std::vector m_harmonies; std::vector m_fretDiagrams; double m_textScale = 0.0; diff --git a/src/engraving/dom/harmony.cpp b/src/engraving/dom/harmony.cpp index 79832a26e02f1..ad59d79b371d7 100644 --- a/src/engraving/dom/harmony.cpp +++ b/src/engraving/dom/harmony.cpp @@ -1337,7 +1337,8 @@ void Harmony::render() m_fontList.clear(); for (const ChordFont& cf : chordList->fonts) { Font ff(font()); - ff.setPointSizeF(ff.pointSizeF() * cf.mag); + double mag = m_userMag.value_or(cf.mag); + ff.setPointSizeF(ff.pointSizeF() * mag); if (!(cf.family.isEmpty() || cf.family == "default")) { ff.setFamily(cf.family, Font::Type::Harmony); } @@ -1891,4 +1892,13 @@ Sid Harmony::getPropertyStyle(Pid pid) const } return TextBase::getPropertyStyle(pid); } + +double Harmony::mag() const +{ + if (m_userMag.has_value()) { + return m_userMag.value(); + } + + return EngravingItem::mag(); +} } diff --git a/src/engraving/dom/harmony.h b/src/engraving/dom/harmony.h index 90f108e7c9012..9b5db6b2e0d7a 100644 --- a/src/engraving/dom/harmony.h +++ b/src/engraving/dom/harmony.h @@ -194,6 +194,9 @@ class Harmony final : public TextBase bool setProperty(Pid propertyId, const PropertyValue& v) override; PropertyValue propertyDefault(Pid id) const override; + double mag() const override; + void setUserMag(double m) { m_userMag = m; } + //! HACK Temporary hack bool isDrawEditMode() const { return m_isDrawEditMode; } void setIsDrawEditMode(bool val) { m_isDrawEditMode = val; } @@ -246,6 +249,8 @@ class Harmony final : public TextBase NoteCaseType m_baseRenderCase = NoteCaseType::AUTO; // case to render bool m_isDrawEditMode = false; + + std::optional m_userMag; }; } // namespace mu::engraving #endif diff --git a/src/engraving/dom/scoretree.cpp b/src/engraving/dom/scoretree.cpp index 64be99e4b340d..97a5362e88de3 100644 --- a/src/engraving/dom/scoretree.cpp +++ b/src/engraving/dom/scoretree.cpp @@ -678,10 +678,6 @@ EngravingObjectList FBox::scanChildren() const { EngravingObjectList children; - for (Harmony* harmony : m_harmonies) { - children.push_back(harmony); - } - for (FretDiagram* fretDiagram : m_fretDiagrams) { children.push_back(fretDiagram); } diff --git a/src/engraving/rendering/score/tlayout.cpp b/src/engraving/rendering/score/tlayout.cpp index d346d02fa5794..104eda08464b0 100644 --- a/src/engraving/rendering/score/tlayout.cpp +++ b/src/engraving/rendering/score/tlayout.cpp @@ -1453,43 +1453,39 @@ void TLayout::layoutFBox(const FBox* item, FBox::LayoutData* ldata, const Layout ldata->setPos(PointF()); - const std::vector harmonies = item->harmonies(); const std::vector fretDiagrams = item->fretDiagrams(); - if (harmonies.empty() || fretDiagrams.empty()) { + if (fretDiagrams.empty()) { return; } - const int totalHarmonies = harmonies.size(); + const int totalDiagrams = fretDiagrams.size(); double maxFretDiagramHeight = 0.0; double maxFretDiagramWidth = 0.0; - double maxHarmonyHeight = 0.0; - for (int i = 0; i < totalHarmonies; ++i) { - Harmony* harmony = harmonies[i]; + for (int i = 0; i < totalDiagrams; ++i) { + FretDiagram *fretDiagram = fretDiagrams[i]; + if (!fretDiagram) { + continue; + } - layoutItem(harmony, const_cast(ctx)); - maxHarmonyHeight = std::max(maxHarmonyHeight, harmony->ldata()->harmonyHeight.value()); + fretDiagram->setUserMag(item->diagramScale()); - if (FretDiagram* fretDiagram = fretDiagrams[i]) { - fretDiagram->setUserMag(item->diagramScale()); + Harmony *harmony = fretDiagram->harmony(); + harmony->setUserMag(item->textScale()); + harmony->render(); - layoutItem(fretDiagram, const_cast(ctx)); + layoutItem(fretDiagram, const_cast(ctx)); - double height = 0.0; - double width = 0.0; - auto shapes = fretDiagram->shape().elements(); - for (ShapeElement& shape : shapes) { - height += shape.height(); - width += shape.width(); - } + double height = fretDiagram->ldata()->bbox().height() + fretDiagram->harmony()->ldata()->harmonyHeight + + ctx.conf().styleMM(Sid::harmonyFretDist); + double width = fretDiagram->ldata()->bbox().width(); - maxFretDiagramHeight = std::max(maxFretDiagramHeight, height); - maxFretDiagramWidth = std::max(maxFretDiagramWidth, width); - } + maxFretDiagramHeight = std::max(maxFretDiagramHeight, height); + maxFretDiagramWidth = std::max(maxFretDiagramWidth, width); } double cellWidth = maxFretDiagramWidth; - double cellHeight = maxFretDiagramHeight + 4 + maxHarmonyHeight; + double cellHeight = maxFretDiagramHeight; ldata->cellWidth = cellWidth; ldata->cellHeight = cellHeight; @@ -1500,8 +1496,8 @@ void TLayout::layoutFBox(const FBox* item, FBox::LayoutData* ldata, const Layout const double rowGap = item->rowGap().val() * spatium; const double columnGap = item->columnGap().val() * spatium; - const int rows = std::ceil(double(totalHarmonies) / double(chordsPerRow)); - const int columns = std::min(totalHarmonies, chordsPerRow); + const int rows = std::ceil(double(totalDiagrams) / double(chordsPerRow)); + const int columns = std::min(totalDiagrams, chordsPerRow); static constexpr double MARGINS = 8.0; const double totalTableHeight = rows * cellHeight + (rows - 1) * rowGap + MARGINS; @@ -1531,35 +1527,26 @@ void TLayout::layoutFBox(const FBox* item, FBox::LayoutData* ldata, const Layout : alignH == AlignH::RIGHT ? item->width() - totalTableWidth : 0.0; const double startY = !muse::RealIsNull(topMargin) ? topMargin : -bottomMargin; - for (int i = 0; i < totalHarmonies; ++i) { + for (int i = 0; i < totalDiagrams; ++i) { int row = i / chordsPerRow; int col = i % chordsPerRow; - int itemsInRow = std::min(chordsPerRow, totalHarmonies - row * chordsPerRow); + int itemsInRow = std::min(chordsPerRow, totalDiagrams - row * chordsPerRow); double rowOffsetX = alignH == AlignH::HCENTER ? (totalTableWidth - (itemsInRow * cellWidth + (itemsInRow - 1) * columnGap)) / 2 : alignH == AlignH::RIGHT ? totalTableWidth - (itemsInRow * cellWidth + (itemsInRow - 1) * columnGap) - rightMargin + spatium : leftMargin + spatium; - Harmony* harmony = harmonies[i]; FretDiagram* fretDiagram = fretDiagrams[i]; - const double harmonyHeight = harmony->ldata()->harmonyHeight; - const double fretDiagramWidth = fretDiagram ? maxFretDiagramWidth : 0.0; - const double harmonyWidth = harmony->ldata()->bbox().width(); - double x = startX + rowOffsetX + col * (cellWidth + columnGap); - double y = startY + row * (cellHeight + rowGap) + harmonyHeight; - - double harmonyX = x + (fretDiagramWidth - harmonyWidth) / 2; - double harmonyY = y; - - harmony->mutldata()->setPos(PointF(harmonyX, harmonyY)); + double y = startY + row * (cellHeight + rowGap); if (fretDiagram) { double fretDiagramX = x; - double fretDiagramY = harmonyY + harmonyHeight + 4; + double fretDiagramY = y + fretDiagram->harmony()->ldata()->harmonyHeight + ctx.conf().styleMM(Sid::harmonyFretDist); + LOGD() << "============= harmony height: " << fretDiagram->harmony()->ldata()->harmonyHeight; fretDiagram->mutldata()->setPos(PointF(fretDiagramX, fretDiagramY)); } } @@ -2742,31 +2729,28 @@ void TLayout::layoutFretDiagram(const FretDiagram* item, FretDiagram::LayoutData ldata->setShape(shape); - if (!item->explicitParent()->isSegment()) { - ldata->setPos(PointF()); - return; - } - - // We need to get the width of the notehead/rest in order to position the fret diagram correctly - Segment* pSeg = item->segment(); - double noteheadWidth = 0; - if (pSeg->isChordRestType()) { - staff_idx_t idx = item->staff()->idx(); - for (EngravingItem* e = pSeg->firstElementOfSegment(idx); e; e = pSeg->nextElementOfSegment(e, idx)) { - if (e->isRest()) { - const Rest* r = toRest(e); - LD_CONDITION(r->ldata()->sym.has_value()); - noteheadWidth = item->symWidth(r->ldata()->sym()); - break; - } else if (e->isNote()) { - Note* n = toNote(e); - noteheadWidth = n->headWidth(); - break; + if (item->explicitParent()->isSegment()) { + // We need to get the width of the notehead/rest in order to position the fret diagram correctly + Segment* pSeg = item->segment(); + double noteheadWidth = 0; + if (pSeg->isChordRestType()) { + staff_idx_t idx = item->staff()->idx(); + for (EngravingItem* e = pSeg->firstElementOfSegment(idx); e; e = pSeg->nextElementOfSegment(e, idx)) { + if (e->isRest()) { + const Rest* r = toRest(e); + LD_CONDITION(r->ldata()->sym.has_value()); + noteheadWidth = item->symWidth(r->ldata()->sym()); + break; + } else if (e->isNote()) { + Note* n = toNote(e); + noteheadWidth = n->headWidth(); + break; + } } } - } - ldata->setPos((noteheadWidth - item->mainWidth()) / 2, -(ldata->shape().bottom() + item->styleP(Sid::fretY))); + ldata->setPos((noteheadWidth - item->mainWidth()) / 2, -(ldata->shape().bottom() + item->styleP(Sid::fretY))); + } if (item->autoplace()) { const Segment* s = toSegment(item->explicitParent()); @@ -2774,9 +2758,9 @@ void TLayout::layoutFretDiagram(const FretDiagram* item, FretDiagram::LayoutData LD_CONDITION(ldata->isSetPos()); LD_CONDITION(m->ldata()->isSetPos()); LD_CONDITION(s->ldata()->isSetPos()); - } - Autoplace::autoplaceSegmentElement(item, ldata); + Autoplace::autoplaceSegmentElement(item, ldata); + } Harmony* harmony = item->harmony(); if (harmony) {