Skip to content

Commit 0ff1749

Browse files
authored
Merge pull request #26686 from sammik/barlines-bottom
correct barline on oneline to hidden staff
2 parents 4e708d9 + 3e1cc11 commit 0ff1749

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/engraving/dom/barline.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static size_t nextVisibleSpannedStaff(const BarLine* bl)
451451
}
452452

453453
//---------------------------------------------------------
454-
// getY
454+
// calcY
455455
//---------------------------------------------------------
456456

457457
void BarLine::calcY()
@@ -465,52 +465,55 @@ void BarLine::calcY()
465465
return;
466466
}
467467
staff_idx_t staffIdx1 = staffIdx();
468-
const Staff* staff1 = score()->staff(staffIdx1);
469-
staff_idx_t staffIdx2 = staffIdx1;
470-
size_t nstaves = score()->nstaves();
468+
staff_idx_t staffIdx2 = m_spanStaff ? nextVisibleSpannedStaff(this) : staffIdx1;
471469

472-
Measure* measure = segment()->measure();
473-
if (m_spanStaff) {
474-
staffIdx2 = nextVisibleSpannedStaff(this);
475-
}
470+
bool spanStaff = staffIdx2 != staffIdx1;
476471

472+
Measure* measure = segment()->measure();
477473
System* system = measure->system();
478474
if (!system) {
479475
return;
480476
}
481477

482-
// test start and end staff visibility
483-
484-
// base y on top visible staff in barline span
485-
// after skipping ones with hideSystemBarLine set
486-
// and accounting for staves that are shown but have invisible measures
487-
488478
Fraction tick = segment()->measure()->tick();
479+
const Staff* staff1 = score()->staff(staffIdx1);
489480
const StaffType* staffType1 = staff1->staffType(tick);
490481

482+
bool oneLine = staffType1->lines() <= 1;
483+
491484
int from = m_spanFrom;
492485
int to = m_spanTo;
493-
bool oneLine = staffType1->lines() <= 1;
494-
if (oneLine && m_spanFrom == 0) {
486+
487+
if (oneLine && m_spanFrom == 0 && m_spanTo == 0) {
495488
from = BARLINE_SPAN_1LINESTAFF_FROM;
496-
if (!m_spanStaff || (staffIdx1 == nstaves - 1)) {
489+
if (!spanStaff) {
497490
to = BARLINE_SPAN_1LINESTAFF_TO;
498491
}
499492
}
500-
SysStaff* sysStaff1 = system->staff(staffIdx1);
501-
double startStaffY = sysStaff1->y();
493+
502494
double spatium1 = staffType1->spatium(style());
503495
double lineDistance = staffType1->lineDistance().val() * spatium1;
504496
double offset = staffType1->yoffset().val() * spatium1;
505497
double lineWidth = style().styleS(Sid::staffLineWidth).val() * spatium1 * .5;
506498

507499
double y1 = offset + from * lineDistance * .5 - lineWidth;
508-
double y2;
509-
510-
if (staffIdx2 != staffIdx1) {
511-
y2 = measure->staffLines(staffIdx2)->y1() - startStaffY - to * lineDistance * 0.5;
512-
} else {
513-
y2 = offset + (staffType1->lines() * 2 - 2 + to) * lineDistance * .5 + lineWidth;
500+
double y2 = offset + (staffType1->lines() * 2 - 2 + to) * lineDistance * .5 + lineWidth;
501+
502+
if (spanStaff) {
503+
// we need spatium and line distance of bottom staff
504+
// as it may be scalled diferently
505+
const Staff* staff2 = score()->staff(staffIdx2);
506+
const StaffType* staffType2 = staff2 ? staff2->staffType(tick) : staffType1;
507+
double spatium2 = staffType2->spatium(style());
508+
double lineDistance2 = staffType2->lineDistance().val() * spatium2;
509+
double startStaffY = system->staff(staffIdx1)->y();
510+
511+
y2 = measure->staffLines(staffIdx2)->y1() - startStaffY - to * lineDistance2 * 0.5;
512+
513+
// if bottom staff is single line, set span-to zeropoint to the top of the standard barline
514+
if (staffType2->lines() <= 1) {
515+
y2 += BARLINE_SPAN_1LINESTAFF_FROM * lineDistance2 * 0.5;
516+
}
514517
}
515518

516519
// if stafftype change in next measure, check new staff positions
@@ -525,9 +528,9 @@ void BarLine::calcY()
525528
from = m_spanFrom;
526529
to = m_spanTo;
527530
}
528-
if (oneLineNext && m_spanFrom == 0) {
531+
if (oneLineNext && m_spanFrom == 0 && m_spanTo == 0) {
529532
from = BARLINE_SPAN_1LINESTAFF_FROM;
530-
if (!m_spanStaff || (staffIdx1 == nstaves - 1)) {
533+
if (!spanStaff) {
531534
to = BARLINE_SPAN_1LINESTAFF_TO;
532535
}
533536
}
@@ -544,7 +547,7 @@ void BarLine::calcY()
544547
y1 = y1Next;
545548
}
546549

547-
if (staffIdx2 == staffIdx1) {
550+
if (!spanStaff) {
548551
double y2Next = offsetNext + (staffType1Next->lines() * 2 - 2 + to) * lineDistanceNext * .5 + lineWidthNext;
549552
if (y2Next > y2) {
550553
y2 = y2Next;

0 commit comments

Comments
 (0)