Skip to content

Commit

Permalink
Merge pull request #24831 from mike-spa/portStuff
Browse files Browse the repository at this point in the history
Port stuff
  • Loading branch information
RomanPudashkin authored Sep 20, 2024
2 parents 7411da4 + 02699b6 commit 9dd3adb
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 51 deletions.
8 changes: 1 addition & 7 deletions src/engraving/dom/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,7 @@ void BarLine::calcY()
double y2;

if (staffIdx2 != staffIdx1) {
BarLine* barline2 = toBarLine(segment()->element(staffIdx2 * VOICES));
double from2 = barline2 ? barline2->m_spanFrom : m_spanFrom;
const Staff* staff2 = score()->staff(staffIdx2);
const StaffType* staffType2 = staff2 ? staff2->staffType(tick) : staff1->staffType(tick);
double spatium2 = staffType2->spatium(style());
double lineDistance2 = staffType2->lineDistance().val() * spatium2;
y2 = measure->staffLines(staffIdx2)->y1() - startStaffY + from2 * lineDistance2 * .5;
y2 = measure->staffLines(staffIdx2)->y1() - startStaffY - to * lineDistance * 0.5;
} else {
y2 = offset + (staffType1->lines() * 2 - 2 + to) * lineDistance * .5 + lineWidth;
}
Expand Down
12 changes: 12 additions & 0 deletions src/engraving/dom/hairpin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ EngravingItem* HairpinSegment::drop(EditData& data)
return d;
}

void HairpinSegment::setPropertyFlags(Pid id, PropertyFlags f)
{
int i = getPropertyFlagsIdx(id);
if (i == -1) {
// Can happen (for example when edit-dragging the aperture) that we're editing
// the HairpinSegment but the relevant property belongs to the Hairpin.
hairpin()->setPropertyFlags(id, f);
return;
}
m_propertyFlagsList[i] = f;
}

//---------------------------------------------------------
// gripsPositions
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/hairpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class HairpinSegment final : public TextLineBaseSegment
bool acceptDrop(EditData&) const override;
EngravingItem* drop(EditData&) override;

void setPropertyFlags(Pid id, PropertyFlags f) override;

bool m_drawCircledTip = false;
PointF m_circledTip;
double m_circledTipRadius = 0.0;
Expand Down
4 changes: 4 additions & 0 deletions src/engraving/dom/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ void SlurSegment::changeAnchor(EditData& ed, EngravingItem* element)
void SlurSegment::editDrag(EditData& ed)
{
Grip g = ed.curGrip;
if (g == Grip::NO_GRIP) {
return;
}

ups(g).off += ed.delta;

PointF delta;
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/infrastructure/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ double Shape::left() const
{
double dist = DBL_MAX;
for (const ShapeElement& r : m_elements) {
if (!RealIsNull(r.height()) && !(r.item() && r.item()->isTextBase()) && r.left() < dist) {
// if (r.left() < dist)
// TURBO-HACK: the only purpose of this is to ignore fingering for spacing the first CR segment after the header.
if (!RealIsNull(r.height()) && !(r.item() && r.item()->isFingering()) && r.left() < dist) {
dist = r.left();
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/engraving/rendering/dev/lyricslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,13 @@ void LyricsLayout::layoutDashes(LyricsLineSegment* item)
bool isDashOnFirstSyllable = lyricsLine->tick2() == system->firstMeasure()->tick();
double curLength = endX - startX;
double dashMinLength = style.styleMM(Sid::lyricsDashMinLength);
int dashCount = std::floor(curLength / style.styleMM(Sid::lyricsDashMaxDistance));
bool firstAndLastGapAreHalf = style.styleB(Sid::lyricsDashFirstAndLastGapAreHalf);
bool forceDash = style.styleB(Sid::lyricsDashForce)
|| (style.styleB(Sid::lyricsShowDashIfSyllableOnFirstNote) && isDashOnFirstSyllable);
double maxDashDistance = style.styleMM(Sid::lyricsDashMaxDistance);
int dashCount = firstAndLastGapAreHalf && curLength > maxDashDistance ? std::ceil(curLength / maxDashDistance)
: std::floor(curLength / maxDashDistance);

if (curLength > dashMinLength || forceDash) {
dashCount = std::max(dashCount, 1);
}
Expand All @@ -381,7 +385,7 @@ void LyricsLayout::layoutDashes(LyricsLineSegment* item)
double dashWidth = std::min(curLength, style.styleMM(Sid::lyricsDashMaxLength).val());

bool dashesLeftAligned = lyricsDashSystemStart != LyricsDashSystemStart::STANDARD && !item->isSingleBeginType();
double dashDist = curLength / (dashesLeftAligned ? dashCount : dashCount + 1);
double dashDist = curLength / (dashesLeftAligned || firstAndLastGapAreHalf ? dashCount : dashCount + 1);
double xDash = 0.0;
if (dashesLeftAligned) {
for (int i = 0; i < dashCount; ++i) {
Expand All @@ -390,7 +394,11 @@ void LyricsLayout::layoutDashes(LyricsLineSegment* item)
}
} else {
for (int i = 0; i < dashCount; ++i) {
xDash += dashDist;
if (firstAndLastGapAreHalf && i == 0) {
xDash += 0.5 * dashDist;
} else {
xDash += dashDist;
}
item->mutldata()->addDash(LineF(PointF(xDash - 0.5 * dashWidth, 0.0), PointF(xDash + 0.5 * dashWidth, 0.0)));
}
}
Expand Down
113 changes: 74 additions & 39 deletions src/engraving/rendering/dev/pagelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,6 @@ void PageLayout::collectPage(LayoutContext& ctx)
ChordLayout::computeUp(c2, ctx);
}
}
// Fingering and articulations on top of cross-staff beams must be laid out here
if (c->beam() && (c->beam()->cross() || c->staffMove() != 0)) {
ChordLayout::layoutArticulations(c, ctx);
ChordLayout::layoutArticulations2(c, ctx, true);

for (Note* note : c->notes()) {
for (EngravingItem* e : note->el()) {
if (!e || !e->isFingering()) {
continue;
}
Fingering* fingering = toFingering(e);
if (fingering->isOnCrossBeamSide()) {
TLayout::layoutFingering(fingering, fingering->mutldata());
if (fingering->addToSkyline()) {
const Note* n = fingering->note();
const RectF r
= fingering->ldata()->bbox().translated(
fingering->pos() + n->pos() + n->chord()->pos() + segment->pos()
+ segment->measure()->pos());
s->staff(fingering->note()->chord()->vStaffIdx())->skyline().add(r, fingering);
}
}
}
}
}
}
} else if (e2->isBarLine()) {
TLayout::layoutBarLine2(toBarLine(e2), ctx);
Expand Down Expand Up @@ -413,8 +388,17 @@ void PageLayout::collectPage(LayoutContext& ctx)
page->mutldata()->setBbox(0.0, 0.0, ctx.conf().loWidth(), height + ctx.state().page()->bm());
}

// HACK: we relayout here cross-staff slurs because only now the information
// about staff distances is fully available.
layoutCrossStaffElements(ctx, page);

for (const System* system : page->systems()) {
SystemLayout::centerElementsBetweenStaves(system);
}

page->invalidateBspTree();
}

void PageLayout::layoutCrossStaffElements(LayoutContext& ctx, Page* page)
{
for (System* system : page->systems()) {
if (!system->firstMeasure()) {
continue;
Expand All @@ -431,23 +415,74 @@ void PageLayout::collectPage(LayoutContext& ctx)
continue;
}

auto spanners = ctx.dom().spannerMap().findOverlapping(stick.ticks(), etick.ticks());
for (auto interval : spanners) {
Spanner* sp = interval.value;
if (!sp->isSlur() || sp->tick() == system->endTick()) {
layoutCrossStaffSlurs(ctx, system);

layoutArticAndFingeringOnCrossStaffBeams(ctx, system);
}
}

void PageLayout::layoutCrossStaffSlurs(LayoutContext& ctx, System* system)
{
Fraction stick = system->firstMeasure()->tick();
Fraction etick = system->endTick();

auto spanners = ctx.dom().spannerMap().findOverlapping(stick.ticks(), etick.ticks());
for (auto interval : spanners) {
Spanner* sp = interval.value;
if (!sp->isSlur() || sp->tick() == system->endTick()) {
continue;
}
if (toSlur(sp)->isCrossStaff()) {
SlurTieLayout::layoutSystem(toSlur(sp), system, ctx);
}
}
}

void PageLayout::layoutArticAndFingeringOnCrossStaffBeams(LayoutContext& ctx, System* system)
{
for (const MeasureBase* mb : system->measures()) {
if (!mb->isMeasure()) {
continue;
}
for (const Segment& segment : toMeasure(mb)->segments()) {
if (!segment.isChordRestType()) {
continue;
}
if (toSlur(sp)->isCrossStaff()) {
SlurTieLayout::layoutSystem(toSlur(sp), system, ctx);
for (EngravingItem* item : segment.elist()) {
if (!item || !item->isChord()) {
continue;
}

Chord* c = toChord(item);
bool hasCrossBeam = c->beam() && (c->beam()->cross() || c->staffMove() != 0);
if (!hasCrossBeam) {
continue;
}

ChordLayout::layoutArticulations(c, ctx);
ChordLayout::layoutArticulations2(c, ctx, true);

for (Note* note : c->notes()) {
for (EngravingItem* e : note->el()) {
if (!e || !e->isFingering()) {
continue;
}
Fingering* fingering = toFingering(e);
if (fingering->isOnCrossBeamSide()) {
TLayout::layoutFingering(fingering, fingering->mutldata());
if (fingering->addToSkyline()) {
const Note* n = fingering->note();
const RectF r = fingering->ldata()->bbox().translated(
fingering->pos() + n->pos() + n->chord()->pos() + segment.pos()
+ segment.measure()->pos());
system->staff(fingering->note()->chord()->vStaffIdx())->skyline().add(r, fingering);
}
}
}
}
}
}
}

for (const System* system : page->systems()) {
SystemLayout::centerElementsBetweenStaves(system);
}

page->invalidateBspTree();
}

//---------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/engraving/rendering/dev/pagelayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class PageLayout
static void layoutPage(LayoutContext& ctx, Page* page, double restHeight, double footerPadding);
static void checkDivider(LayoutContext& ctx, bool left, System* s, double yOffset, bool remove = false);
static void distributeStaves(LayoutContext& ctx, Page* page, double footerPadding);

static void layoutCrossStaffElements(LayoutContext& ctx, Page* page);
static void layoutCrossStaffSlurs(LayoutContext& ctx, System* system);
static void layoutArticAndFingeringOnCrossStaffBeams(LayoutContext& ctx, System* system);
};
}

Expand Down
29 changes: 29 additions & 0 deletions src/engraving/rendering/dev/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2885,6 +2885,31 @@ bool SystemLayout::elementShouldBeCenteredBetweenStaves(const EngravingItem* ite
return centerProperty == AutoOnOff::ON || item->appliesToAllVoicesInInstrument();
}

bool SystemLayout::elementHasAnotherStackedOutside(const EngravingItem* element, const Shape& elementShape, const SkylineLine& skylineLine)
{
double elemShapeLeft = -elementShape.left();
double elemShapeRight = elementShape.right();
double elemShapeTop = elementShape.top();
double elemShapeBottom = elementShape.bottom();

for (const ShapeElement& skylineElement : skylineLine.elements()) {
if (!skylineElement.item() || skylineElement.item() == element || skylineElement.item()->parent() == element) {
continue;
}
bool intersectHorizontally = elemShapeRight > skylineElement.left() && elemShapeLeft < skylineElement.right();
if (!intersectHorizontally) {
continue;
}
bool skylineElementIsStackedOnIt = skylineLine.isNorth() ? skylineElement.top() < elemShapeBottom : skylineElement.bottom()
> elemShapeTop;
if (skylineElementIsStackedOnIt) {
return true;
}
}

return false;
}

void SystemLayout::centerElementBetweenStaves(EngravingItem* element, const System* system)
{
bool isAbove = element->placeAbove();
Expand Down Expand Up @@ -2916,6 +2941,10 @@ void SystemLayout::centerElementBetweenStaves(EngravingItem* element, const Syst

const SkylineLine& skylineOfThisStaff = isAbove ? thisStaff->skyline().north() : thisStaff->skyline().south();

if (elementHasAnotherStackedOutside(element, elementShape, skylineOfThisStaff)) {
return;
}

SkylineLine thisSkyline = skylineOfThisStaff.getFilteredCopy([element](const ShapeElement& shEl) {
const EngravingItem* shapeItem = shEl.item();
if (!shapeItem) {
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/rendering/dev/systemlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class System;
class Measure;
class Bracket;
class BracketItem;
class SkylineLine;
}

namespace mu::engraving::rendering::dev {
Expand Down Expand Up @@ -86,6 +87,7 @@ class SystemLayout
static double minVertSpaceForCrossStaffBeams(System* system, staff_idx_t staffIdx1, staff_idx_t staffIdx2, LayoutContext& ctx);

static bool elementShouldBeCenteredBetweenStaves(const EngravingItem* item, const System* system);
static bool elementHasAnotherStackedOutside(const EngravingItem* element, const Shape& elementShape, const SkylineLine& skylineLine);
static void centerElementBetweenStaves(EngravingItem* element, const System* system);
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/engraving/rw/write/twrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ void TWrite::writeProperties(const TextLineBase* item, XmlWriter& xml, WriteCont
writeProperty(item, xml, pid);
}
}

writeProperties(static_cast<const SLine*>(item), xml, ctx);
}

Expand Down Expand Up @@ -1606,6 +1607,9 @@ void TWrite::write(const Hairpin* item, XmlWriter& xml, WriteContext& ctx)
writeProperty(item, xml, Pid::SNAP_BEFORE);
writeProperty(item, xml, Pid::SNAP_AFTER);

writeProperty(item, xml, Pid::HAIRPIN_HEIGHT);
writeProperty(item, xml, Pid::HAIRPIN_CONT_HEIGHT);

writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
xml.endElement();
}
Expand Down
1 change: 1 addition & 0 deletions src/engraving/style/styledef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const std::array<StyleDef::StyleValue, size_t(Sid::STYLES)> StyleDef::styleValue
styleDef(lyricsDashMaxLength, Spatium(0.6)),
styleDef(lyricsDashMaxDistance, Spatium(16.0)),
styleDef(lyricsDashForce, true),
styleDef(lyricsDashFirstAndLastGapAreHalf, true),
styleDef(lyricsAlignVerseNumber, true),
styleDef(lyricsLineThickness, Spatium(0.1)),
styleDef(lyricsMelismaAlign, Align(AlignH::LEFT, AlignV::BASELINE)),
Expand Down
1 change: 1 addition & 0 deletions src/engraving/style/styledef.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ enum class Sid {
lyricsDashMaxLength,
lyricsDashMaxDistance,
lyricsDashForce,
lyricsDashFirstAndLastGapAreHalf,
lyricsAlignVerseNumber,
lyricsLineThickness,
lyricsMelismaAlign,
Expand Down
Binary file added vtest/scores/barline-6.mscz
Binary file not shown.

0 comments on commit 9dd3adb

Please sign in to comment.