Skip to content

Commit

Permalink
Merge pull request #143 from mgavioli/Fix_19151_1-line-staff_barlines
Browse files Browse the repository at this point in the history
Fix 19151: bar lines of 1-line-staves
  • Loading branch information
mgavioli committed Dec 12, 2012
2 parents 40e5376 + fb4f151 commit 41fb8bc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
14 changes: 10 additions & 4 deletions libmscore/barline.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ class MuseScoreView;
class Segment;
class QPainter;

#define DEFAULT_BARLINE_TO (4*2)
#define MIN_BARLINE_FROMTO_DIST 2
#define MIN_BARLINE_SPAN_FROMTO (-2)
#define DEFAULT_BARLINE_TO (4*2)
#define MIN_BARLINE_FROMTO_DIST 2
#define MIN_BARLINE_SPAN_FROMTO (-2)
// bar line span for 1-line staves is special: goes from 2sp above the line to 2sp below the line;
// for some reason, the single staff line counts as line -1 rather than as line 0
// thus, 2sp above it is -2 rather than -4 and 2sp below it is 6 rather than 4
// (see StaffLines::y1() function in element.cpp)
#define BARLINE_SPAN_1LINESTAFF_FROM (-2)
#define BARLINE_SPAN_1LINESTAFF_TO 6
// used while reading a score for a default spanTo (to last staff line) toward a staff not yet read;
// fixed once all staves are read
#define UNKNOWN_BARLINE_TO (-4)
#define UNKNOWN_BARLINE_TO (-4)

//---------------------------------------------------------
// @@ BarLine
Expand Down
5 changes: 3 additions & 2 deletions libmscore/scorefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,9 @@ bool Score::read(const QDomElement& de)
st->setBarLineFrom(st->lines()*2);
// check spanTo
Staff* stTo = st->barLineSpan() <= 1 ? st : staff(idx + st->barLineSpan() - 1);
int maxBarLineTo = stTo->lines()*2;
int defaultBarLineTo = (stTo->lines() - 1) * 2;
// 1-line staves have special bar line spans
int maxBarLineTo = stTo->lines() == 1 ? BARLINE_SPAN_1LINESTAFF_TO : stTo->lines()*2;
int defaultBarLineTo = stTo->lines() == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (stTo->lines() - 1) * 2;
if(st->barLineTo() == UNKNOWN_BARLINE_TO)
st->setBarLineTo(defaultBarLineTo);
if(st->barLineTo() < MIN_BARLINE_SPAN_FROMTO)
Expand Down
40 changes: 29 additions & 11 deletions libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,16 @@ void Staff::write(Xml& xml) const
foreach(const BracketItem& i, _brackets)
xml.tagE("bracket type=\"%d\" span=\"%d\"", i._bracket, i._bracketSpan);
// for economy and consistency, only output "from" and "to" attributes if different from default
int defaultLineTo = _barLineSpan == 0 ? _barLineTo : (score()->staff(idx+_barLineSpan-1)->lines() - 1) * 2;
if (_barLineSpan != 1 || _barLineFrom != 0 || _barLineTo != defaultLineTo) {
if(_barLineFrom != 0 || _barLineTo != defaultLineTo)
int defaultLineFrom = (lines() == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0);
int defaultLineTo;
if (_barLineSpan == 0) // if no bar line at all
defaultLineTo = _barLineTo; // whatever the current spanTo is, use as default
else { // if some bar line, default is the default for span target staff
int targetStaffLines = score()->staff(idx+_barLineSpan-1)->lines();
defaultLineTo = (targetStaffLines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (targetStaffLines-1) * 2);
}
if (_barLineSpan != 1 || _barLineFrom != defaultLineFrom || _barLineTo != defaultLineTo) {
if(_barLineFrom != defaultLineFrom || _barLineTo != defaultLineTo)
xml.tag(QString("barLineSpan from=\"%1\" to=\"%2\"").arg(_barLineFrom).arg(_barLineTo), _barLineSpan);
else
xml.tag("barLineSpan", _barLineSpan);
Expand All @@ -413,7 +420,9 @@ void Staff::read(const QDomElement& de)
StaffType* st = score()->staffType(val.toInt());
if (st) {
_staffType = st;
_barLineTo = (lines()-1) * 2; // set default barLineTo according to staff type
// set default barLineTo according to staff type (1-line staff bar lines are special)
_barLineFrom = (lines() == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0);
_barLineTo = (lines() == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (lines() - 1) * 2);
}
}
else if (tag == "small")
Expand All @@ -430,13 +439,16 @@ void Staff::read(const QDomElement& de)
}
else if (tag == "barLineSpan") {
_barLineSpan = val.toInt();
_barLineFrom = e.attribute("from", "0").toInt();
int defaultSpan = (lines() == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0);
_barLineFrom = e.attribute("from", QString::number(defaultSpan)).toInt();
// WARNING: following statement assume staff type is correctly set
// if no bar line or single staff span, set _barLineTo to this staff height
// if span to another staff (yet to be read), set to unknown
// (Score::read() will retrieve the correct height of the target staff)
int defaultLineTo = _barLineSpan <= 1 ? (lines() - 1) * 2 : UNKNOWN_BARLINE_TO;
_barLineTo = e.attribute("to", QString::number(defaultLineTo)).toInt();
defaultSpan = _barLineSpan <= 1 ?
(lines() == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (lines() - 1) * 2)
: UNKNOWN_BARLINE_TO;
_barLineTo = e.attribute("to", QString::number(defaultSpan)).toInt();
}
else if (tag == "distOffset")
_userDist = e.text().toDouble() * spatium();
Expand Down Expand Up @@ -657,11 +669,17 @@ void Staff::setStaffType(StaffType* st)
int linesOld = lines();
int linesNew = st->lines();
_staffType = st;
if(linesNew != linesOld) {
if (linesNew != linesOld) {
int sIdx = score()->staffIdx(this);
if(sIdx < 0) { // staff does not belong to score (yet?)
_barLineFrom = 0; // set default barLineFrom/To
_barLineTo = (linesNew-1)*2; // set default barLineTo
if (sIdx < 0) { // staff does not belong to score (yet?)
if (linesNew == 1) { // 1-line staves have special bar lines
_barLineFrom = BARLINE_SPAN_1LINESTAFF_FROM;
_barLineTo = BARLINE_SPAN_1LINESTAFF_TO;
}
else { // set default barLineFrom/to (from first to last staff line)
_barLineFrom = 0;
_barLineTo = (linesNew-1)*2;
}
}
else // update barLineFrom/To in whole score context
score()->updateBarLineSpans(sIdx, linesOld, linesNew /*, true*/);
Expand Down

0 comments on commit 41fb8bc

Please sign in to comment.