Skip to content

Commit 172b53d

Browse files
juli27cbjeukendrup
authored andcommitted
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 2f924da commit 172b53d

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

+338
-287
lines changed

src/engraving/dom/barline.h

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

107-
void setSpanStaff(int val) { m_spanStaff = val; }
107+
void setSpanStaff(const bool val) { m_spanStaff = val; }
108108
void setSpanFrom(int val) { m_spanFrom = val; }
109109
void setSpanTo(int val) { m_spanTo = val; }
110110
void setShowTips(bool val);
111-
int spanStaff() const { return m_spanStaff; }
111+
bool spanStaff() const { return m_spanStaff; }
112112
int spanFrom() const { return m_spanFrom; }
113113
int spanTo() const { return m_spanTo; }
114114
bool showTips() const;
@@ -176,7 +176,7 @@ class BarLine final : public EngravingItem
176176
BarLine(Segment* parent);
177177
BarLine(const BarLine&);
178178

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

src/engraving/dom/excerpt.cpp

Lines changed: 1 addition & 42 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"
@@ -36,7 +34,6 @@
3634
#include "factory.h"
3735
#include "guitarbend.h"
3836
#include "harmony.h"
39-
#include "laissezvib.h"
4037
#include "layoutbreak.h"
4138
#include "linkedobjects.h"
4239
#include "lyrics.h"
@@ -49,7 +46,6 @@
4946
#include "rest.h"
5047
#include "score.h"
5148
#include "segment.h"
52-
#include "sig.h"
5349
#include "staff.h"
5450
#include "stafftype.h"
5551
#include "system.h"
@@ -991,38 +987,6 @@ static MeasureBase* cloneMeasure(MeasureBase* mb, Score* score, const Score* osc
991987
}
992988

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

1028992
if (clone) {
@@ -1036,12 +1000,7 @@ static MeasureBase* cloneMeasure(MeasureBase* mb, Score* score, const Score* osc
10361000
}
10371001

10381002
ne->setScore(score);
1039-
if (oe->isBarLine()) {
1040-
BarLine* nbl = toBarLine(ne);
1041-
if (adjustedBarlineSpan) {
1042-
nbl->setSpanStaff(adjustedBarlineSpan);
1043-
}
1044-
} else if (oe->isChordRest()) {
1003+
if (oe->isChordRest()) {
10451004
ChordRest* ocr = toChordRest(oe);
10461005
ChordRest* ncr = toChordRest(ne);
10471006

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;
@@ -255,14 +254,14 @@ void InstrumentTemplate::init(const InstrumentTemplate& t)
255254
trait = t.trait;
256255
groupId = t.groupId;
257256
glissandoStyle = t.glissandoStyle;
257+
barlineSpan = t.barlineSpan;
258258

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

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

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
@@ -193,4 +192,3 @@ extern void addTemplateToGroup(const InstrumentTemplate* templ, const String& gr
193192

194193
extern ClefType defaultClef(int patch);
195194
} // namespace mu::engraving
196-
#endif

src/engraving/dom/score.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,9 +4043,7 @@ void Score::updateBracesAndBarlines(Part* part, size_t newIndex)
40434043
auto updateBracketSpan = [this, part](size_t modIndex, size_t refIndex) {
40444044
Staff* modStaff = staff(part->staves()[modIndex]->idx());
40454045
Staff* refStaff = staff(part->staves()[refIndex]->idx());
4046-
if (modStaff->getProperty(Pid::STAFF_BARLINE_SPAN) != refStaff->getProperty(Pid::STAFF_BARLINE_SPAN)) {
4047-
modStaff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, refStaff->getProperty(Pid::STAFF_BARLINE_SPAN));
4048-
}
4046+
modStaff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, refStaff->getProperty(Pid::STAFF_BARLINE_SPAN));
40494047
};
40504048

40514049
if (newIndex >= 2) {
@@ -4055,8 +4053,9 @@ void Score::updateBracesAndBarlines(Part* part, size_t newIndex)
40554053
if (part->nstaves() == 2) {
40564054
const InstrumentTemplate* tp = searchTemplate(part->instrumentId());
40574055
if (tp) {
4058-
if (tp->barlineSpan[0] > 0) {
4059-
staff(part->staves()[0]->idx())->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, tp->barlineSpan[0]);
4056+
const bool firstStaffBarLineSpan = tp->barlineSpan[0];
4057+
if (firstStaffBarLineSpan) {
4058+
staff(part->staff(0)->idx())->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, firstStaffBarLineSpan);
40604059
}
40614060
if (noBracesFound && (tp->bracket[0] != BracketType::NO_BRACKET)) {
40624061
undoAddBracket(part->staves()[0], 0, tp->bracket[0], part->nstaves());
@@ -4145,8 +4144,8 @@ void Score::remapBracketsAndBarlines()
41454144
// Look in the masterScore for all the staves spanned by a common barline.
41464145
// If at least one of them is also in this score, then connect it through.
41474146
bool extendBarline = false;
4148-
int span = masterStaff->barLineSpan();
4149-
while (!extendBarline && span > 0 && masterStaff->idx() + 1 < master->nstaves()) {
4147+
bool span = masterStaff->barLineSpan();
4148+
while (!extendBarline && span && masterStaff->idx() + 1 < master->nstaves()) {
41504149
masterStaff = masterScore()->staff(masterStaff->idx() + 1);
41514150
span = masterStaff->barLineSpan();
41524151
if (masterStaff->findLinkedInScore(this)) {
@@ -4155,7 +4154,7 @@ void Score::remapBracketsAndBarlines()
41554154
}
41564155
}
41574156
if (extendBarline) {
4158-
staff->setBarLineSpan(1);
4157+
staff->setBarLineSpan(true);
41594158
}
41604159
}
41614160
}

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
@@ -1627,7 +1627,7 @@ bool Staff::setProperty(Pid id, const PropertyValue& v)
16271627
setPlaybackVoice(3, v.toBool());
16281628
break;
16291629
case Pid::STAFF_BARLINE_SPAN: {
1630-
setBarLineSpan(v.toInt());
1630+
setBarLineSpan(v.toBool());
16311631
// update non-generated barlines
16321632
track_idx_t track = idx() * VOICES;
16331633
std::vector<EngravingItem*> blList;
@@ -1645,7 +1645,7 @@ bool Staff::setProperty(Pid id, const PropertyValue& v)
16451645
}
16461646
for (EngravingItem* e : blList) {
16471647
if (e && e->isBarLine() && !e->generated()) {
1648-
toBarLine(e)->setSpanStaff(v.toInt());
1648+
toBarLine(e)->setSpanStaff(barLineSpan());
16491649
}
16501650
}
16511651
}

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
@@ -188,7 +188,7 @@ void DynamicsLayout::manageBarlineCollisions(const Dynamic* item, TextBase::Layo
188188
return;
189189
}
190190

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

src/engraving/rendering/score/horizontalspacing.cpp

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

558558
BarLine* barline = toBarLine(barlineSegment->element(staff2track(staffIdx)));
559-
if (!barline || barline->spanStaff() == 0) {
559+
if (!barline || !barline->spanStaff()) {
560560
continue;
561561
}
562562

0 commit comments

Comments
 (0)