Skip to content

Commit a9cd231

Browse files
committed
engraving: Cleanup bar line span properties
They used to be integers in the pre-3.0 days, where a staff or bar line could specify that it spans multiple staves. This then got simplified to a bool, but this transition wasn't done cleanly. This commit makes up for that by making sure that we only work with booleans. int values are converted appropriately when reading pre-3.0 scores.
1 parent 23ed47d commit a9cd231

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+337
-283
lines changed

src/engraving/dom/barline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ class BarLine final : public EngravingItem
106106
Segment* segment() const { return toSegment(explicitParent()); }
107107
Measure* measure() const { return explicitParent() ? toMeasure(explicitParent()->explicitParent()) : nullptr; }
108108

109-
void setSpanStaff(int val) { m_spanStaff = val; }
109+
void setSpanStaff(const bool val) { m_spanStaff = val; }
110110
void setSpanFrom(int val) { m_spanFrom = val; }
111111
void setSpanTo(int val) { m_spanTo = val; }
112112
void setShowTips(bool val);
113-
int spanStaff() const { return m_spanStaff; }
113+
bool spanStaff() const { return m_spanStaff; }
114114
int spanFrom() const { return m_spanFrom; }
115115
int spanTo() const { return m_spanTo; }
116116
bool showTips() const;
@@ -186,7 +186,7 @@ class BarLine final : public EngravingItem
186186
BarLine(Segment* parent);
187187
BarLine(const BarLine&);
188188

189-
int m_spanStaff = 0; // span barline to next staff if true, values > 1 are used for importing from 2.x
189+
bool m_spanStaff = false; // span barline to next staff if true
190190
int m_spanFrom = 0; // line number on start and end staves
191191
int m_spanTo = 0;
192192
BarLineType m_barLineType = BarLineType::NORMAL;

src/engraving/dom/excerpt.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#include "excerpt.h"
2424

25-
#include <list>
26-
2725
#include "containers.h"
2826

2927
#include "dom/partialtie.h"
@@ -37,7 +35,6 @@
3735
#include "factory.h"
3836
#include "guitarbend.h"
3937
#include "harmony.h"
40-
#include "laissezvib.h"
4138
#include "layoutbreak.h"
4239
#include "linkedobjects.h"
4340
#include "lyrics.h"
@@ -50,7 +47,6 @@
5047
#include "rest.h"
5148
#include "score.h"
5249
#include "segment.h"
53-
#include "sig.h"
5450
#include "staff.h"
5551
#include "stafftype.h"
5652
#include "system.h"
@@ -992,37 +988,6 @@ static MeasureBase* cloneMeasure(MeasureBase* mb, Score* score, const Score* osc
992988
}
993989

994990
EngravingItem* oe = oseg->element(srcTrack);
995-
int adjustedBarlineSpan = 0;
996-
if (srcTrack % VOICES == 0 && oseg->segmentType() == SegmentType::BarLine) {
997-
// mid-measure barline segment
998-
// may need to clone barline from a previous staff and/or adjust span
999-
int oIdx = static_cast<int>(srcTrack / VOICES);
1000-
if (!oe) {
1001-
// no barline on this staff in original score,
1002-
// but check previous staves
1003-
for (int i = oIdx - 1; i >= 0; --i) {
1004-
oe = oseg->element(i * VOICES);
1005-
if (oe) {
1006-
break;
1007-
}
1008-
}
1009-
}
1010-
if (oe) {
1011-
// barline found, now check span
1012-
BarLine* bl = toBarLine(oe);
1013-
int oSpan1 = static_cast<int>(bl->staff()->idx());
1014-
int oSpan2 = static_cast<int>(oSpan1 + bl->spanStaff());
1015-
if (oSpan1 <= oIdx && oIdx <= oSpan2) {
1016-
// this staff is within span
1017-
// calculate adjusted span for excerpt
1018-
int oSpan = oSpan2 - oIdx;
1019-
adjustedBarlineSpan = std::min(oSpan, static_cast<int>(score->nstaves()));
1020-
} else {
1021-
// this staff is not within span
1022-
oe = nullptr;
1023-
}
1024-
}
1025-
}
1026991

1027992
bool cloneBarLine = false;
1028993
if (oseg->isEndBarLineType()) {
@@ -1046,9 +1011,6 @@ static MeasureBase* cloneMeasure(MeasureBase* mb, Score* score, const Score* osc
10461011
ne->setScore(score);
10471012
if (oe->isBarLine()) {
10481013
BarLine* nbl = toBarLine(ne);
1049-
if (adjustedBarlineSpan) {
1050-
nbl->setSpanStaff(adjustedBarlineSpan);
1051-
}
10521014
PlayCountText* newText = nbl->playCountText();
10531015
Staff* dstStaff = score->staff(track2staff(track));
10541016
if (dstStaff->shouldShowPlayCount()) {

src/engraving/dom/instrtemplate.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ InstrumentTemplate::InstrumentTemplate()
210210
smallStaff[i] = false;
211211
bracket[i] = BracketType::NO_BRACKET;
212212
bracketSpan[i] = 0;
213-
barlineSpan[i] = false;
214213
}
215214
transpose.diatonic = 0;
216215
transpose.chromatic = 0;
@@ -254,14 +253,14 @@ void InstrumentTemplate::init(const InstrumentTemplate& t)
254253
sequenceOrder = t.sequenceOrder;
255254
trait = t.trait;
256255
groupId = t.groupId;
256+
barlineSpan = t.barlineSpan;
257257

258258
for (int i = 0; i < MAX_STAVES; ++i) {
259259
clefTypes[i] = t.clefTypes[i];
260260
staffLines[i] = t.staffLines[i];
261261
smallStaff[i] = t.smallStaff[i];
262262
bracket[i] = t.bracket[i];
263263
bracketSpan[i] = t.bracketSpan[i];
264-
barlineSpan[i] = t.barlineSpan[i];
265264
}
266265
}
267266

@@ -355,10 +354,10 @@ void InstrumentTemplate::write(XmlWriter& xml) const
355354
}
356355
}
357356
if (barlineSpan[i]) {
358-
if (i) {
359-
xml.tag("barlineSpan", { { "staff", i + 1 } }, barlineSpan[i]);
357+
if (i > 0) {
358+
xml.tag("barlineSpan", { { "staff", i + 1 } }, int { barlineSpan[i] });
360359
} else {
361-
xml.tag("barlineSpan", barlineSpan[i]);
360+
xml.tag("barlineSpan", int { barlineSpan[i] });
362361
}
363362
}
364363
}

src/engraving/dom/instrtemplate.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
*/
22+
#pragma once
2223

23-
#ifndef MU_ENGRAVING_INSTRTEMPLATE_H
24-
#define MU_ENGRAVING_INSTRTEMPLATE_H
25-
24+
#include <array>
2625
#include <list>
2726

2827
#include "io/path.h"
@@ -119,7 +118,7 @@ class InstrumentTemplate
119118
int staffLines[MAX_STAVES];
120119
BracketType bracket[MAX_STAVES]; // bracket type (NO_BRACKET)
121120
int bracketSpan[MAX_STAVES];
122-
int barlineSpan[MAX_STAVES];
121+
std::array<bool, MAX_STAVES> barlineSpan{};
123122
bool smallStaff[MAX_STAVES];
124123

125124
bool extended = false; // belongs to extended instrument set if true
@@ -191,4 +190,3 @@ extern void addTemplateToGroup(const InstrumentTemplate* templ, const String& gr
191190

192191
extern ClefType defaultClef(int patch);
193192
} // namespace mu::engraving
194-
#endif

src/engraving/dom/score.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,9 +4047,7 @@ void Score::updateBracesAndBarlines(Part* part, size_t newIndex)
40474047
auto updateBracketSpan = [this, part](size_t modIndex, size_t refIndex) {
40484048
Staff* modStaff = staff(part->staves()[modIndex]->idx());
40494049
Staff* refStaff = staff(part->staves()[refIndex]->idx());
4050-
if (modStaff->getProperty(Pid::STAFF_BARLINE_SPAN) != refStaff->getProperty(Pid::STAFF_BARLINE_SPAN)) {
4051-
modStaff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, refStaff->getProperty(Pid::STAFF_BARLINE_SPAN));
4052-
}
4050+
modStaff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, refStaff->getProperty(Pid::STAFF_BARLINE_SPAN));
40534051
};
40544052

40554053
if (newIndex >= 2) {
@@ -4059,8 +4057,9 @@ void Score::updateBracesAndBarlines(Part* part, size_t newIndex)
40594057
if (part->nstaves() == 2) {
40604058
const InstrumentTemplate* tp = searchTemplate(part->instrumentId());
40614059
if (tp) {
4062-
if (tp->barlineSpan[0] > 0) {
4063-
staff(part->staves()[0]->idx())->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, tp->barlineSpan[0]);
4060+
const bool firstStaffBarLineSpan = tp->barlineSpan[0];
4061+
if (firstStaffBarLineSpan) {
4062+
staff(part->staff(0)->idx())->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, firstStaffBarLineSpan);
40644063
}
40654064
if (noBracesFound && (tp->bracket[0] != BracketType::NO_BRACKET)) {
40664065
undoAddBracket(part->staves()[0], 0, tp->bracket[0], part->nstaves());
@@ -4149,8 +4148,8 @@ void Score::remapBracketsAndBarlines()
41494148
// Look in the masterScore for all the staves spanned by a common barline.
41504149
// If at least one of them is also in this score, then connect it through.
41514150
bool extendBarline = false;
4152-
int span = masterStaff->barLineSpan();
4153-
while (!extendBarline && span > 0 && masterStaff->idx() + 1 < master->nstaves()) {
4151+
bool span = masterStaff->barLineSpan();
4152+
while (!extendBarline && span && masterStaff->idx() + 1 < master->nstaves()) {
41544153
masterStaff = masterScore()->staff(masterStaff->idx() + 1);
41554154
span = masterStaff->barLineSpan();
41564155
if (masterStaff->findLinkedInScore(this)) {
@@ -4159,7 +4158,7 @@ void Score::remapBracketsAndBarlines()
41594158
}
41604159
}
41614160
if (extendBarline) {
4162-
staff->setBarLineSpan(1);
4161+
staff->setBarLineSpan(true);
41634162
}
41644163
}
41654164
}

src/engraving/dom/scoreorder.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void ScoreOrder::setBracketsAndBarlines(Score* score)
423423
}
424424
}
425425
if (!braceSpan) {
426-
staff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, 0);
426+
staff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, false);
427427
} else {
428428
--braceSpan;
429429
}
@@ -462,11 +462,8 @@ void ScoreOrder::setBracketsAndBarlines(Score* score)
462462
thnBracketSpan += static_cast<int>(part->nstaves());
463463
}
464464
if (prvStaff) {
465-
bool oldBarlineSpan = prvStaff->getProperty(Pid::STAFF_BARLINE_SPAN).toBool();
466-
bool newBarlineSpan = prvBarLineSpan && (!prvSection.isEmpty() && (sg.section == prvSection));
467-
if (oldBarlineSpan != newBarlineSpan) {
468-
prvStaff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, newBarlineSpan);
469-
}
465+
const bool newBarlineSpan = prvBarLineSpan && (!prvSection.isEmpty() && (sg.section == prvSection));
466+
prvStaff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, newBarlineSpan);
470467
}
471468
prvStaff = staff;
472469
++staffIdx;

src/engraving/dom/staff.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ bool Staff::setProperty(Pid id, const PropertyValue& v)
16301630
setPlaybackVoice(3, v.toBool());
16311631
break;
16321632
case Pid::STAFF_BARLINE_SPAN: {
1633-
setBarLineSpan(v.toInt());
1633+
setBarLineSpan(v.toBool());
16341634
// update non-generated barlines
16351635
track_idx_t track = idx() * VOICES;
16361636
std::vector<EngravingItem*> blList;
@@ -1648,7 +1648,7 @@ bool Staff::setProperty(Pid id, const PropertyValue& v)
16481648
}
16491649
for (EngravingItem* e : blList) {
16501650
if (e && e->isBarLine() && !e->generated()) {
1651-
toBarLine(e)->setSpanStaff(v.toInt());
1651+
toBarLine(e)->setSpanStaff(barLineSpan());
16521652
}
16531653
}
16541654
}

src/engraving/dom/staff.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ class Staff final : public EngravingItem
145145
void setMergeMatchingRests(AutoOnOff val) { m_mergeMatchingRests = val; }
146146
bool shouldMergeMatchingRests() const;
147147

148-
int barLineSpan() const { return m_barLineSpan; }
148+
bool barLineSpan() const { return m_barLineSpan; }
149149
int barLineFrom() const { return m_barLineFrom; }
150150
int barLineTo() const { return m_barLineTo; }
151-
void setBarLineSpan(int val) { m_barLineSpan = val; }
151+
void setBarLineSpan(const bool val) { m_barLineSpan = val; }
152152
void setBarLineFrom(int val) { m_barLineFrom = val; }
153153
void setBarLineTo(int val) { m_barLineTo = val; }
154154
double staffHeight() const;
@@ -293,7 +293,7 @@ class Staff final : public EngravingItem
293293
std::map<int, TimeSig*> m_timesigs;
294294

295295
std::vector<BracketItem*> m_brackets;
296-
int m_barLineSpan = false; // true - span barline to next staff
296+
bool m_barLineSpan = false; // true - span barline to next staff
297297
int m_barLineFrom = 0; // line of start staff to draw the barline from (0 = staff top line, ...)
298298
int m_barLineTo = 0; // line of end staff to draw the bar line to (0= staff bottom line, ...)
299299

src/engraving/rendering/score/dynamicslayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void DynamicsLayout::manageBarlineCollisions(const Dynamic* item, TextBase::Layo
187187
return;
188188
}
189189

190-
if (item->score()->staff(barLineStaff)->barLineSpan() < 1) {
190+
if (!item->score()->staff(barLineStaff)->barLineSpan()) {
191191
return; // Barline doesn't extend through staves
192192
}
193193

src/engraving/rendering/score/horizontalspacing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ double HorizontalSpacing::spaceLyricsAgainstBarlines(Segment* firstSeg, Segment*
540540
}
541541

542542
BarLine* barline = toBarLine(barlineSegment->element(staff2track(staffIdx)));
543-
if (!barline || barline->spanStaff() == 0) {
543+
if (!barline || !barline->spanStaff()) {
544544
continue;
545545
}
546546

0 commit comments

Comments
 (0)