Skip to content

Commit

Permalink
[engraving] remove friend class SystemLayout from System
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jul 13, 2023
1 parent 8e09dec commit 6ff5f44
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 166 deletions.
86 changes: 43 additions & 43 deletions src/engraving/layout/v0/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ void SystemLayout::manageNarrowSpacing(System* system, LayoutContext& ctx, doubl

void SystemLayout::layoutSystem(System* system, LayoutContext& ctx, double xo1, const bool isFirstSystem, bool firstSystemIndent)
{
if (system->_staves.empty()) { // ignore vbox
if (system->staves().empty()) { // ignore vbox
return;
}

Expand All @@ -1678,7 +1678,7 @@ void SystemLayout::layoutSystem(System* system, LayoutContext& ctx, double xo1,
textSizeScaling = std::max(textSizeScaling, 1.0);
instrumentNameOffset *= textSizeScaling;

size_t nstaves = system->_staves.size();
size_t nstaves = system->staves().size();

//---------------------------------------------------
// find x position of staves
Expand All @@ -1696,16 +1696,16 @@ void SystemLayout::layoutSystem(System* system, LayoutContext& ctx, double xo1,

if (RealIsNull(indent)) {
if (ctx.conf().styleB(Sid::alignSystemToMargin)) {
system->_leftMargin = 0.0;
system->setLeftMargin(0.0);
} else {
system->_leftMargin = maxBracketsWidth;
system->setLeftMargin(maxBracketsWidth);
}
} else {
system->_leftMargin = indent + maxBracketsWidth;
system->setLeftMargin(indent + maxBracketsWidth);
}

for (size_t staffIdx = 0; staffIdx < nstaves; ++staffIdx) {
SysStaff* s = system->_staves[staffIdx];
SysStaff* s = system->staves().at(staffIdx);
const Staff* staff = ctx.dom().staff(staffIdx);
if (!staff->show() || !s->show()) {
s->setbbox(RectF());
Expand All @@ -1716,27 +1716,27 @@ void SystemLayout::layoutSystem(System* system, LayoutContext& ctx, double xo1,
int staffLines = staff->lines(Fraction(0, 1));
if (staffLines <= 1) {
double h = staff->lineDistance(Fraction(0, 1)) * staffMag * system->spatium();
s->bbox().setRect(system->_leftMargin + xo1, -h, 0.0, 2 * h);
s->bbox().setRect(system->leftMargin() + xo1, -h, 0.0, 2 * h);
} else {
double h = (staffLines - 1) * staff->lineDistance(Fraction(0, 1));
h = h * staffMag * system->spatium();
s->bbox().setRect(system->_leftMargin + xo1, 0.0, 0.0, h);
s->bbox().setRect(system->leftMargin() + xo1, 0.0, 0.0, h);
}
}

//---------------------------------------------------
// layout brackets
//---------------------------------------------------

system->setBracketsXPosition(xo1 + system->_leftMargin);
system->setBracketsXPosition(xo1 + system->leftMargin());

//---------------------------------------------------
// layout instrument names x position
// at this point it is not clear which staves will
// be hidden, so layout all instrument names
//---------------------------------------------------

for (SysStaff* s : system->_staves) {
for (const SysStaff* s : system->staves()) {
for (InstrumentName* t : s->instrumentNames) {
TLayout::layout(t, ctx);

Expand Down Expand Up @@ -1858,7 +1858,7 @@ double SystemLayout::totalBracketOffset(LayoutContext& ctx)

double SystemLayout::layoutBrackets(System* system, LayoutContext& ctx)
{
size_t nstaves = system->_staves.size();
size_t nstaves = system->staves().size();
size_t columns = system->getBracketsColumnsCount();

#if (!defined (_MSCVER) && !defined (_MSC_VER))
Expand All @@ -1873,7 +1873,7 @@ double SystemLayout::layoutBrackets(System* system, LayoutContext& ctx)
}

std::vector<Bracket*> bl;
bl.swap(system->_brackets);
bl.swap(system->brackets());

for (size_t staffIdx = 0; staffIdx < nstaves; ++staffIdx) {
const Staff* s = ctx.dom().staff(staffIdx);
Expand All @@ -1896,7 +1896,7 @@ double SystemLayout::layoutBrackets(System* system, LayoutContext& ctx)

double totalBracketWidth = 0.0;

if (!system->_brackets.empty()) {
if (!system->brackets().empty()) {
for (double w : bracketWidth) {
totalBracketWidth += w;
}
Expand All @@ -1907,11 +1907,11 @@ double SystemLayout::layoutBrackets(System* system, LayoutContext& ctx)

void SystemLayout::addBrackets(System* system, Measure* measure, LayoutContext& ctx)
{
if (system->_staves.empty()) { // ignore vbox
if (system->staves().empty()) { // ignore vbox
return;
}

size_t nstaves = system->_staves.size();
size_t nstaves = system->staves().size();

//---------------------------------------------------
// find x position of staves
Expand All @@ -1921,7 +1921,7 @@ void SystemLayout::addBrackets(System* system, Measure* measure, LayoutContext&
size_t columns = system->getBracketsColumnsCount();

std::vector<Bracket*> bl;
bl.swap(system->_brackets);
bl.swap(system->brackets());

for (staff_idx_t staffIdx = 0; staffIdx < nstaves; ++staffIdx) {
const Staff* s = ctx.dom().staff(staffIdx);
Expand All @@ -1944,7 +1944,7 @@ void SystemLayout::addBrackets(System* system, Measure* measure, LayoutContext&

system->setBracketsXPosition(measure->x());

mu::join(system->_brackets, bl);
mu::join(system->brackets(), bl);
}

//---------------------------------------------------------
Expand All @@ -1958,7 +1958,7 @@ Bracket* SystemLayout::createBracket(System* system, LayoutContext& ctx, Bracket
std::vector<Bracket*>& bl,
Measure* measure)
{
size_t nstaves = system->_staves.size();
size_t nstaves = system->staves().size();
staff_idx_t firstStaff = staffIdx;
staff_idx_t lastStaff = staffIdx + bi->bracketSpan() - 1;
if (lastStaff >= nstaves) {
Expand Down Expand Up @@ -2049,9 +2049,9 @@ void SystemLayout::layout2(System* system, LayoutContext& ctx)
system->setPos(0.0, 0.0);
std::list<std::pair<size_t, SysStaff*> > visibleStaves;

for (size_t i = 0; i < system->_staves.size(); ++i) {
for (size_t i = 0; i < system->staves().size(); ++i) {
const Staff* s = ctx.dom().staff(i);
SysStaff* ss = system->_staves[i];
SysStaff* ss = system->staves().at(i);
if (s->show() && ss->show()) {
visibleStaves.push_back(std::pair<size_t, SysStaff*>(i, ss));
} else {
Expand Down Expand Up @@ -2091,7 +2091,7 @@ void SystemLayout::layout2(System* system, LayoutContext& ctx)
}
if (ni == visibleStaves.end()) {
ss->setYOff(yOffset);
ss->bbox().setRect(system->_leftMargin, y - yOffset, system->width() - system->_leftMargin, h);
ss->bbox().setRect(system->leftMargin(), y - yOffset, system->width() - system->leftMargin(), h);
ss->saveLayout();
break;
}
Expand All @@ -2108,11 +2108,11 @@ void SystemLayout::layout2(System* system, LayoutContext& ctx)
}
dist += staff2->userDist();
bool fixedSpace = false;
for (MeasureBase* mb : system->ml) {
for (const MeasureBase* mb : system->measures()) {
if (!mb->isMeasure()) {
continue;
}
Measure* m = toMeasure(mb);
const Measure* m = toMeasure(mb);
Spacer* sp = m->vspacerDown(si1);
if (sp) {
if (sp->spacerType() == SpacerType::FIXED) {
Expand Down Expand Up @@ -2150,15 +2150,15 @@ void SystemLayout::layout2(System* system, LayoutContext& ctx)
dist = std::max(dist, d + minVerticalDistance);
}
ss->setYOff(yOffset);
ss->bbox().setRect(system->_leftMargin, y - yOffset, system->width() - system->_leftMargin, h);
ss->bbox().setRect(system->leftMargin(), y - yOffset, system->width() - system->leftMargin(), h);
ss->saveLayout();
y += dist;
}

system->_systemHeight = system->staff(visibleStaves.back().first)->bbox().bottom();
system->setHeight(system->_systemHeight);
system->setSystemHeight(system->staff(visibleStaves.back().first)->bbox().bottom());
system->setHeight(system->systemHeight());

SystemLayout::setMeasureHeight(system, system->_systemHeight, ctx);
SystemLayout::setMeasureHeight(system, system->systemHeight(), ctx);

//---------------------------------------------------
// layout brackets vertical position
Expand Down Expand Up @@ -2202,18 +2202,18 @@ void SystemLayout::restoreLayout2(System* system, LayoutContext& ctx)
return;
}

for (SysStaff* s : system->_staves) {
for (SysStaff* s : system->staves()) {
s->restoreLayout();
}

system->setHeight(system->_systemHeight);
SystemLayout::setMeasureHeight(system, system->_systemHeight, ctx);
system->setHeight(system->systemHeight());
SystemLayout::setMeasureHeight(system, system->systemHeight(), ctx);
}

void SystemLayout::setMeasureHeight(System* system, double height, LayoutContext& ctx)
{
double _spatium = system->spatium();
for (MeasureBase* m : system->ml) {
for (MeasureBase* m : system->measures()) {
if (m->isMeasure()) {
// note that the factor 2 * _spatium must be corrected for when exporting
// system distance in MusicXML (issue #24733)
Expand All @@ -2231,17 +2231,17 @@ void SystemLayout::setMeasureHeight(System* system, double height, LayoutContext

void SystemLayout::layoutBracketsVertical(System* system, LayoutContext& ctx)
{
for (Bracket* b : system->_brackets) {
for (Bracket* b : system->brackets()) {
int staffIdx1 = static_cast<int>(b->firstStaff());
int staffIdx2 = static_cast<int>(b->lastStaff());
double sy = 0; // assume bracket not visible
double ey = 0;
// if start staff not visible, try next staff
while (staffIdx1 <= staffIdx2 && !system->_staves[staffIdx1]->show()) {
while (staffIdx1 <= staffIdx2 && !system->staves().at(staffIdx1)->show()) {
++staffIdx1;
}
// if end staff not visible, try prev staff
while (staffIdx1 <= staffIdx2 && !system->_staves[staffIdx2]->show()) {
while (staffIdx1 <= staffIdx2 && !system->staves().at(staffIdx2)->show()) {
--staffIdx2;
}
// if the score doesn't have "alwaysShowBracketsWhenEmptyStavesAreHidden" as true,
Expand All @@ -2252,8 +2252,8 @@ void SystemLayout::layoutBracketsVertical(System* system, LayoutContext& ctx)
bool notHidden = ctx.conf().styleB(Sid::alwaysShowBracketsWhenEmptyStavesAreHidden)
? (staffIdx1 <= staffIdx2) : (staffIdx1 < staffIdx2) || (b->span() == 1 && staffIdx1 == staffIdx2);
if (notHidden) { // set vert. pos. and height to visible spanned staves
sy = system->_staves[staffIdx1]->bbox().top();
ey = system->_staves[staffIdx2]->bbox().bottom();
sy = system->staves().at(staffIdx1)->bbox().top();
ey = system->staves().at(staffIdx2)->bbox().bottom();
}
b->setPosY(sy);
b->setHeight(ey - sy);
Expand Down Expand Up @@ -2344,7 +2344,7 @@ void SystemLayout::setInstrumentNames(System* system, LayoutContext& ctx, bool l
}
if (!ctx.conf().isShowInstrumentNames()
|| (ctx.conf().styleB(Sid::hideInstrumentNameIfOneInstrument) && ctx.dom().visiblePartCount() <= 1)) {
for (SysStaff* staff : system->_staves) {
for (SysStaff* staff : system->staves()) {
for (InstrumentName* t : staff->instrumentNames) {
ctx.mutDom().removeElement(t);
}
Expand All @@ -2353,7 +2353,7 @@ void SystemLayout::setInstrumentNames(System* system, LayoutContext& ctx, bool l
}

int staffIdx = 0;
for (SysStaff* staff : system->_staves) {
for (SysStaff* staff : system->staves()) {
const Staff* s = ctx.dom().staff(staffIdx);
Part* part = s->part();

Expand Down Expand Up @@ -2442,24 +2442,24 @@ double SystemLayout::minDistance(const System* top, const System* bottom, Layout
const Staff* staff = ctx.dom().staff(firstStaff);
double userDist = staff ? staff->userDist() : 0.0;
dist = std::max(dist, userDist);
top->fixedDownDistance = false;
top->setFixedDownDistance(false);

for (MeasureBase* mb1 : top->ml) {
for (const MeasureBase* mb1 : top->measures()) {
if (mb1->isMeasure()) {
Measure* m = toMeasure(mb1);
const Measure* m = toMeasure(mb1);
Spacer* sp = m->vspacerDown(lastStaff);
if (sp) {
if (sp->spacerType() == SpacerType::FIXED) {
dist = sp->gap();
top->fixedDownDistance = true;
top->setFixedDownDistance(true);
break;
} else {
dist = std::max(dist, sp->gap().val());
}
}
}
}
if (!top->fixedDownDistance) {
if (!top->hasFixedDownDistance()) {
for (const MeasureBase* mb2 : bottom->measures()) {
if (mb2->isMeasure()) {
const Measure* m = toMeasure(mb2);
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/scoretree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ EngravingObjectList System::scanChildren() const
children.push_back(dividerRight);
}

for (SysStaff* staff : _staves) {
for (SysStaff* staff : m_staves) {
for (InstrumentName* instrName : staff->instrumentNames) {
children.push_back(instrName);
}
Expand Down
Loading

0 comments on commit 6ff5f44

Please sign in to comment.