Skip to content

Commit e5062b1

Browse files
committed
Layout fermatas cross-staff
1 parent 42d7c59 commit e5062b1

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

src/engraving/dom/fermata.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "types/symnames.h"
2626
#include "types/translatablestring.h"
2727

28+
#include "beam.h"
2829
#include "chord.h"
2930
#include "chordrest.h"
3031
#include "measure.h"
@@ -258,6 +259,20 @@ double Fermata::mag() const
258259
return m;
259260
}
260261

262+
staff_idx_t Fermata::vStaffIdx() const
263+
{
264+
if (segment() && segment()->element(track())) {
265+
if (segment()->isChordRestType()) {
266+
const ChordRest* cr = toChordRest(segment()->element(track()));
267+
if (cr->beam() && cr->beam()->cross() && (placeAbove() == cr->isBelowCrossBeam(cr->beam()))) {
268+
return cr->staffIdx() + cr->beam()->crossStaffIdx() - placeAbove() ? 0 : 1;
269+
}
270+
}
271+
return segment()->element(track())->vStaffIdx();
272+
}
273+
return staffIdx();
274+
}
275+
261276
void Fermata::setSymIdAndTimeStretch(SymId id)
262277
{
263278
m_symId = id;

src/engraving/dom/fermata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Fermata final : public EngravingItem
5252
Fermata* clone() const override { return new Fermata(*this); }
5353

5454
double mag() const override;
55+
staff_idx_t vStaffIdx() const override;
5556

5657
SymId symId() const { return m_symId; }
5758
void setSymId(SymId id) { m_symId = id; }

src/engraving/rendering/score/tlayout.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,8 @@ void TLayout::layoutExpression(const Expression* item, Expression::LayoutData* l
21782178
void TLayout::layoutFermata(const Fermata* item, Fermata::LayoutData* ldata)
21792179
{
21802180
LAYOUT_CALL_ITEM(item);
2181-
const StaffType* stType = item->staffType();
2181+
const Staff* vStaff = item->score()->staff(item->vStaffIdx());
2182+
const StaffType* stType = vStaff->staffTypeForElement(item);
21822183
if (stType && stType->isHiddenElementOnTab(Sid::fermataShowTabCommon, Sid::fermataShowTabSimple)) {
21832184
ldata->setIsSkipDraw(true);
21842185
return;
@@ -2191,22 +2192,31 @@ void TLayout::layoutFermata(const Fermata* item, Fermata::LayoutData* ldata)
21912192
}
21922193

21932194
double x = 0.0;
2194-
double y = item->placeAbove() ? 0.0 : item->staff()->staffHeight(item->tick());
2195+
double y = item->placeAbove() ? 0.0 : vStaff->staffHeight(item->tick());
21952196
const Segment* s = item->segment();
21962197
const EngravingItem* e = s->element(item->track());
21972198

2199+
Shape staffShape = s->staffShape(item->vStaffIdx());
2200+
staffShape.removeTypes({ ElementType::FERMATA });
2201+
21982202
if (e) {
21992203
LD_CONDITION(e->ldata()->isSetBbox()); // e->shape()
22002204
LD_CONDITION(e->ldata()->isSetPos());
22012205

2202-
if (e->isChord()) {
2203-
const Chord* chord = toChord(e);
2204-
x = chord->x() + ChordLayout::centerX(chord);
2205-
} else if (e->isRest()) {
2206-
const Rest* rest = toRest(e);
2207-
x = rest->x() + rest->centerX();
2206+
if (e->isChordRest()) {
2207+
if (e->isChord()) {
2208+
const Chord* chord = toChord(e);
2209+
x = chord->x() + ChordLayout::centerX(chord);
2210+
} else if (e->isRest()) {
2211+
const Rest* rest = toRest(e);
2212+
x = rest->x() + rest->centerX();
2213+
}
2214+
const Beam* beam = toChordRest(e)->beam();
2215+
if (beam && beam->cross()) {
2216+
// staffShape.add(beam->shape().translate(beam->pagePos() - s->pagePos()));
2217+
}
22082218
} else {
2209-
x = e->x() - e->shape().left() + e->width() * item->staff()->staffMag(Fraction(0, 1)) * .5;
2219+
x = e->x() - e->shape().left() + e->width() * vStaff->staffMag(Fraction(0, 1)) * .5;
22102220
}
22112221
}
22122222

@@ -2229,8 +2239,6 @@ void TLayout::layoutFermata(const Fermata* item, Fermata::LayoutData* ldata)
22292239
if (item->isStyled(Pid::OFFSET)) {
22302240
y += item->offset().y();
22312241
}
2232-
Shape staffShape = item->segment()->staffShape(item->staffIdx());
2233-
staffShape.removeTypes({ ElementType::FERMATA });
22342242
if (item->placeAbove()) {
22352243
double minDist = ldata->shape().minVerticalDistance(staffShape) + item->minDistance().toMM(item->spatium());
22362244
y = std::min(y, -minDist);

vtest/scores/fermata-7.mscz

23.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)