Skip to content

Commit

Permalink
ported musescore#6461: Better handling of Clefs Barlines on ossias an…
Browse files Browse the repository at this point in the history
…d cutaway
  • Loading branch information
igorkorsukov committed Feb 2, 2021
1 parent b4661f7 commit c25c182
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ void BarLine::endEditDrag(EditData& ed)
newSpanTo = 0;
}

bool localDrag = ed.control() || segment()->isBarLine();
bool localDrag = ed.control() || segment()->isBarLineType();
if (localDrag) {
Segment* s = segment();
for (int staffIdx = staffIdx1; staffIdx < staffIdx2; ++staffIdx) {
Expand Down
73 changes: 72 additions & 1 deletion src/libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,16 @@ Measure::Measure(const Measure& m)

void Measure::layoutStaffLines()
{
int staffIdx = 0;
for (MStaff* ms : m_mstaves) {
ms->lines()->layout();
if (isCutawayClef(staffIdx) && (score()->staff(staffIdx)->cutaway() || !visible(staffIdx))) {
// draw short staff lines for a courtesy clef on a hidden measure
ms->lines()->layoutPartialWidth(width(), 4.0, true);
} else {
// normal staff lines
ms->lines()->layout();
}
staffIdx += 1;
}
}

Expand Down Expand Up @@ -2795,6 +2803,7 @@ bool Measure::isEmpty(int staffIdx) const
{
int strack;
int etrack;
bool hasStaves = score()->staff(staffIdx)->part()->staves()->size() > 1;
if (staffIdx < 0) {
strack = 0;
etrack = score()->nstaves() * VOICES;
Expand All @@ -2808,6 +2817,21 @@ bool Measure::isEmpty(int staffIdx) const
if (e && !e->isRest()) {
return false;
}
// Check for cross-staff chords
if (hasStaves) {
if (strack >= VOICES) {
e = s->element(track - VOICES);
if (e && !e->isRest() && e->vStaffIdx() == staffIdx) {
return false;
}
}
if (etrack < score()->nstaves() * VOICES) {
e = s->element(track + VOICES);
if (e && !e->isRest() && e->vStaffIdx() == staffIdx) {
return false;
}
}
}
}
for (Element* a : s->annotations()) {
if (!a || a->systemFlag() || !a->visible() || a->isFermata()) {
Expand All @@ -2822,6 +2846,53 @@ bool Measure::isEmpty(int staffIdx) const
return true;
}

//---------------------------------------------------------
// isCutawayClef
/// Check for empty measure with only
/// a Courtesy Clef before End Bar Line
//---------------------------------------------------------

bool Measure::isCutawayClef(int staffIdx) const
{
if (!score()->staff(staffIdx) || !m_mstaves[staffIdx]) {
return false;
}
bool empty = (score()->staff(staffIdx)->cutaway() && isEmpty(staffIdx)) || !m_mstaves[staffIdx]->visible();
if (!empty) {
return false;
}
int strack;
int etrack;
if (staffIdx < 0) {
strack = 0;
etrack = score()->nstaves() * VOICES;
} else {
strack = staffIdx * VOICES;
etrack = strack + VOICES;
}
// find segment before EndBarLine
Segment* s = nullptr;
for (Segment* ls = last(); ls; ls = ls->prev()) {
if (ls->segmentType() == SegmentType::EndBarLine) {
s = ls->prev();
break;
}
}
if (!s) {
return false;
}
for (int track = strack; track < etrack; ++track) {
Element* e = s->element(track);
if (!e || !e->isClef()) {
continue;
}
if ((nextMeasure() && (nextMeasure()->system() == system())) || toClef(e)->showCourtesy()) {
return true;
}
}
return false;
}

//---------------------------------------------------------
// isFullMeasureRest
// Check for an empty measure, filled with full measure
Expand Down
1 change: 1 addition & 0 deletions src/libmscore/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class Measure final : public MeasureBase
void checkMultiVoices(int staffIdx);
bool hasVoice(int track) const;
bool isEmpty(int staffIdx) const;
bool isCutawayClef(int staffIdx) const;
bool isFullMeasureRest() const;
bool visible(int staffIdx) const;
bool stemless(int staffIdx) const;
Expand Down
47 changes: 47 additions & 0 deletions src/libmscore/stafflines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,53 @@ void StaffLines::layoutForWidth(qreal w)
}
}

//---------------------------------------------------------
// layoutPartialWidth
/// Layout staff lines for the specified width only, aligned
/// to the left or right of the measure
//---------------------------------------------------------

void StaffLines::layoutPartialWidth(qreal w, qreal wPartial, bool alignRight)
{
const Staff* s = staff();
qreal _spatium = spatium();
wPartial *= spatium();
qreal dist = _spatium;
setPos(QPointF(0.0, 0.0));
int _lines;
if (s) {
setMag(s->mag(measure()->tick()));
setColor(s->color(measure()->tick()));
const StaffType* st = s->staffType(measure()->tick());
dist *= st->lineDistance().val();
_lines = st->lines();
rypos() = st->yoffset().val() * _spatium;
} else {
_lines = 5;
setColor(MScore::defaultColor);
}
lw = score()->styleS(Sid::staffLineWidth).val() * _spatium;
qreal x1 = pos().x();
qreal x2 = x1 + w;
qreal y = pos().y();
bbox().setRect(x1, -lw * .5 + y, w, (_lines - 1) * dist + lw);

if (_lines == 1) {
qreal extraSize = _spatium;
bbox().adjust(0, -extraSize, 0, extraSize);
}

lines.clear();
for (int i = 0; i < _lines; ++i) {
if (alignRight) {
lines.push_back(QLineF(x2 - wPartial, y, x2, y));
} else {
lines.push_back(QLineF(x1, y, x1 + wPartial, y));
}
y += dist;
}
}

//---------------------------------------------------------
// draw
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/libmscore/stafflines.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ class StaffLines final : public Element
Measure* measure() const { return (Measure*)parent(); }
qreal y1() const;
void layoutForWidth(qreal width);
void layoutPartialWidth(qreal w, qreal wPartial, bool alignLeft);
};
} // namespace Ms

0 comments on commit c25c182

Please sign in to comment.