Skip to content

Fix layout of chord symbol on invisible fret diagram #29368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/engraving/dom/fret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,6 @@ void FretDiagram::applyAlignmentToHarmony()

void FretDiagram::resetHarmonyAlignment()
{
if (m_harmony->propertyFlags(Pid::OFFSET) == PropertyFlags::STYLED) {
m_harmony->resetProperty(Pid::OFFSET);
}

m_harmony->resetProperty(Pid::ALIGN);
}

Expand Down Expand Up @@ -1182,6 +1178,15 @@ PropertyValue FretDiagram::propertyDefault(Pid pid) const
return EngravingItem::propertyDefault(pid);
}

void FretDiagram::setVisible(bool f)
{
EngravingItem::setVisible(f);

if (m_harmony && m_harmony->isStyled(Pid::OFFSET)) {
m_harmony->resetProperty(Pid::OFFSET);
}
}

void FretDiagram::setTrack(track_idx_t val)
{
EngravingItem::setTrack(val);
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/fret.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ class FretDiagram final : public EngravingItem
bool setProperty(Pid propertyId, const PropertyValue&) override;
PropertyValue propertyDefault(Pid) const override;

virtual void setVisible(bool f);

void setTrack(track_idx_t val) override;

String accessibleInfo() const override;
Expand Down
10 changes: 7 additions & 3 deletions src/engraving/dom/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,13 @@ PropertyValue Harmony::propertyDefault(Pid id) const
case Pid::PLAY:
v = true;
break;
case Pid::OFFSET:
if (explicitParent() && explicitParent()->isFretDiagram()) {
case Pid::OFFSET: {
const FretDiagram* fd = explicitParent() && explicitParent()->isFretDiagram() ? toFretDiagram(explicitParent()) : nullptr;
if (fd && fd->visible()) {
v = PropertyValue::fromValue(PointF(0.0, 0.0));
break;
}
}
// fall-through
default:
v = TextBase::propertyDefault(id);
Expand All @@ -1559,7 +1561,9 @@ PropertyValue Harmony::propertyDefault(Pid id) const
Sid Harmony::getPropertyStyle(Pid pid) const
{
if (pid == Pid::OFFSET) {
if (explicitParent() && explicitParent()->isFretDiagram()) {
const FretDiagram* fd = explicitParent() && explicitParent()->isFretDiagram() ? toFretDiagram(explicitParent()) : nullptr;

if (fd && fd->visible()) {
return Sid::NOSTYLE;
} else if (textStyleType() == TextStyleType::HARMONY_A) {
return placeAbove() ? Sid::chordSymbolAPosAbove : Sid::chordSymbolAPosBelow;
Expand Down
13 changes: 12 additions & 1 deletion src/engraving/rendering/score/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,18 @@ void SystemLayout::layoutSystemElements(System* system, LayoutContext& ctx)
AlignmentLayout::alignItemsForSystem(fretItems, system);
}

layoutHarmonies(elementsToLayout.harmonies, system, true, ctx);
for (Harmony* harmony : elementsToLayout.harmonies) {
FretDiagram* fdParent = harmony->parent()->isFretDiagram() ? toFretDiagram(harmony->parent()) : nullptr;
if (fdParent && !fdParent->visible()) {
harmony->mutldata()->moveY(-fdParent->pos().y());
}
Autoplace::autoplaceSegmentElement(harmony, harmony->mutldata());
}

if (ctx.conf().styleB(Sid::verticallyAlignChordSymbols)) {
std::vector<EngravingItem*> harmonyItems(elementsToLayout.harmonies.begin(), elementsToLayout.harmonies.end());
AlignmentLayout::alignItemsForSystem(harmonyItems, system);
}

for (FretDiagram* fretDiag : elementsToLayout.fretDiagrams) {
if (Harmony* harmony = fretDiag->harmony()) {
Expand Down
10 changes: 6 additions & 4 deletions src/engraving/rendering/score/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2783,10 +2783,12 @@ void TLayout::layoutFretDiagram(const FretDiagram* item, FretDiagram::LayoutData
Harmony* harmony = item->harmony();
if (harmony) {
TLayout::layoutHarmony(harmony, harmony->mutldata(), ctx);
double vertDist = ldata->bbox().top() - harmony->ldata()->bbox().translated(harmony->pos()).bottom();
double diff = vertDist - harmony->minDistance().val() * item->spatium();
if (diff < 0) {
harmony->mutldata()->moveY(diff);
if (item->visible()) {
double vertDist = ldata->bbox().top() - harmony->ldata()->bbox().translated(harmony->pos()).bottom();
double diff = vertDist - harmony->minDistance().val() * item->spatium();
if (diff < 0) {
harmony->mutldata()->moveY(diff);
}
}
}

Expand Down
Binary file added vtest/scores/harmony-36.mscz
Binary file not shown.
Loading