Skip to content

Commit

Permalink
Merge pull request #25374 from mike-spa/restCorrections
Browse files Browse the repository at this point in the history
Breve-rest corrections
  • Loading branch information
miiizen authored Nov 5, 2024
2 parents ee1a654 + 39d2fc3 commit a8e1c85
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
32 changes: 22 additions & 10 deletions src/engraving/dom/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,20 @@ int Rest::computeVoiceOffset(int lines, LayoutData* ldata) const
return voiceLineOffset * upSign;
}

int Rest::computeWholeRestOffset(int voiceOffset, int lines) const
int Rest::computeWholeOrBreveRestOffset(int voiceOffset, int lines) const
{
if (!isWholeRest()) {
return 0;
}
int lineMove = 0;
bool moveToLineAbove = (lines > 5)
|| ((lines > 1 || voiceOffset == -1 || voiceOffset == 2) && !(voiceOffset == -2 || voiceOffset == 1));
if (moveToLineAbove) {
lineMove = -1;
if (isWholeRest()) {
bool moveToLineAbove = (lines > 5)
|| ((lines > 1 || voiceOffset == -1 || voiceOffset == 2) && !(voiceOffset == -2 || voiceOffset == 1));
if (moveToLineAbove) {
lineMove = -1;
}
} else if (isBreveRest() && lines == 1) {
lineMove = 1;
}

if (!isFullMeasureRest()) {
if (!isFullMeasureRest() || !measure()) {
return lineMove;
}

Expand Down Expand Up @@ -529,7 +530,7 @@ int Rest::computeWholeRestOffset(int voiceOffset, int lines) const
}
}

if (hasNotesAbove && hasNotesBelow) {
if (hasNotesAbove == hasNotesBelow) {
return lineMove; // Don't do anything
}

Expand All @@ -546,6 +547,10 @@ int Rest::computeWholeRestOffset(int voiceOffset, int lines) const
lineMove = std::min(lineMove, topLine - centerLine);
}

if (isBreveRest()) {
lineMove++;
}

return lineMove;
}

Expand All @@ -556,6 +561,13 @@ bool Rest::isWholeRest() const
|| (durType == DurationType::V_MEASURE && measure() && measure()->ticks() < Fraction(2, 1));
}

bool Rest::isBreveRest() const
{
TDuration durType = durationType();
return durType == DurationType::V_BREVE
|| (durType == DurationType::V_MEASURE && measure() && measure()->ticks() >= Fraction(2, 1));
}

int Rest::computeNaturalLine(int lines) const
{
int line = (lines % 2) ? floor(double(lines) / 2) : ceil(double(lines) / 2);
Expand Down
3 changes: 2 additions & 1 deletion src/engraving/dom/rest.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Rest : public ChordRest
void setAccent(bool flag);

bool isWholeRest() const;
bool isBreveRest() const;

DeadSlapped* deadSlapped() const { return m_deadSlapped; }

Expand Down Expand Up @@ -142,7 +143,7 @@ class Rest : public ChordRest

int computeNaturalLine(int lines) const; // Natural rest vertical position
int computeVoiceOffset(int lines, LayoutData* ldata) const; // Vertical displacement in multi-voice cases
int computeWholeRestOffset(int voiceOffset, int lines) const;
int computeWholeOrBreveRestOffset(int voiceOffset, int lines) const;

SymId getSymbol(DurationType type, int line, int lines) const;
void updateSymbol(int line, int lines, LayoutData* ldata) const;
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/score/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4632,7 +4632,7 @@ void TLayout::layoutRest(const Rest* item, Rest::LayoutData* ldata, const Layout

int naturalLine = item->computeNaturalLine(lines); // Measured in 1sp steps
int voiceOffset = item->computeVoiceOffset(lines, ldata); // Measured in 1sp steps
int wholeRestOffset = item->computeWholeRestOffset(voiceOffset, lines);
int wholeRestOffset = item->computeWholeOrBreveRestOffset(voiceOffset, lines);
int finalLine = naturalLine + voiceOffset + wholeRestOffset;

ldata->sym = item->getSymbol(item->durationType().type(), finalLine + userLine, lines);
Expand Down
Binary file added vtest/scores/rests-10.mscz
Binary file not shown.
Binary file added vtest/scores/rests-9.mscz
Binary file not shown.

0 comments on commit a8e1c85

Please sign in to comment.