Skip to content

Commit

Permalink
Rehearsal mark vs tempo positioning
Browse files Browse the repository at this point in the history
Backport of musescore#26436
  • Loading branch information
mike-spa authored and Jojo-Schmitz committed Feb 11, 2025
1 parent f0be61c commit 01d26f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
31 changes: 18 additions & 13 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "note.h"
#include "page.h"
#include "part.h"
#include "rehearsalmark.h"
#include "repeat.h"
#include "score.h"
#include "segment.h"
Expand Down Expand Up @@ -3868,7 +3869,7 @@ void alignHarmonies(const System* system, const std::vector<Segment*>& sl, bool
qreal shift = be->rypos();
be->rypos() = reference - be->ryoffset();
shift -= be->rypos();
for (Element* e : qAsConst(elements[s])) {
for (Element*& e : elements[s]) {
if ((above && e->placeBelow()) || (!above && e->placeAbove()))
continue;
modified.append(e);
Expand All @@ -3886,7 +3887,7 @@ void alignHarmonies(const System* system, const std::vector<Segment*>& sl, bool

void addToSkyline(const System* system)
{
for (Element* e : qAsConst(modified)) {
for (Element*& e : modified) {
const Segment* s = toSegment(e->parent());
const MeasureBase* m = toMeasureBase(s->parent());
system->staff(e->staffIdx())->skyline().add(e->shape().translated(e->pos() + s->pos() + m->pos()));
Expand Down Expand Up @@ -4854,6 +4855,18 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
}
}

//-------------------------------------------------------------
// RehearsalMark
//-------------------------------------------------------------
// Layout before tempo text but autoplace after
std::vector<RehearsalMark*> rehearsMarks;
for (const Segment* s : sl) {
for (Element* e : s->annotations()) {
if (e->isRehearsalMark())
e->layout();
}
}

//-------------------------------------------------------------
// TempoText
//-------------------------------------------------------------
Expand All @@ -4865,6 +4878,9 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
}
}

for (RehearsalMark* rehearsMark : rehearsMarks)
rehearsMark->autoplaceSegmentElement();

//-------------------------------------------------------------
// Jump, Marker
//-------------------------------------------------------------
Expand All @@ -4879,17 +4895,6 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
}
}

//-------------------------------------------------------------
// RehearsalMark
//-------------------------------------------------------------

for (const Segment* s : sl) {
for (Element* e : s->annotations()) {
if (e->isRehearsalMark())
e->layout();
}
}

//-------------------------------------------------------------
// Image
//-------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion libmscore/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ static const StyleType styleTypes[] {
{ Sid::rehearsalMarkFrameFgColor, "rehearsalMarkFrameFgColor", QColor(0, 0, 0, 255) },
{ Sid::rehearsalMarkFrameBgColor, "rehearsalMarkFrameBgColor", QColor(255, 255, 255, 0) },
{ Sid::rehearsalMarkPlacement, "rehearsalMarkPlacement", int(Placement::ABOVE) },
{ Sid::rehearsalMarkPosAbove, "rehearsalMarkPosAbove", QPointF(.0, -3.0) },
{ Sid::rehearsalMarkPosAbove, "rehearsalMarkPosAbove", QPointF(.0, -2.0) },
{ Sid::rehearsalMarkPosBelow, "rehearsalMarkPosBelow", QPointF(.0, 4.0) },
{ Sid::rehearsalMarkMinDistance, "rehearsalMarkMinDistance", Spatium(0.5) },

Expand Down Expand Up @@ -3766,6 +3766,11 @@ bool MStyle::readProperties450(XmlReader& e, int mscVersion)
e.skipCurrentElement();
else if (tag == "mergeMatchingRests") // Mu4.5+ only, let's skip
e.skipCurrentElement();
else if (tag == "rehearsalMarkPosAbove") { // -3.0 -> -2.0
int rehearsalMarkPosAbove = e.readDouble();
if (!qFuzzyCompare(rehearsalMarkPosAbove,2.0)) // Changed from 4.5+ default
set(Sid::rehearsalMarkPosAbove, rehearsalMarkPosAbove);
}
else if (tag == "minEmptyMeasures") { // 2 -> 1
int minEmptyMeasures = e.readInt();
if (minEmptyMeasures != 1) // Changed from 4.5+ default
Expand All @@ -3787,6 +3792,11 @@ bool MStyle::readProperties450(XmlReader& e, int mscVersion)
else if (tag == "minLaissezVibLength" // Mu4.5+ only, let's skip
|| tag =="laissezVibUseSmuflSym") // Mu4.5+ only, let's skip
e.skipCurrentElement();
else if (tag == "rehearsalMarkPosAbove") { // -3.0 -> -2.0
int rehearsalMarkPosAbove = e.readDouble();
if (!qFuzzyCompare(rehearsalMarkPosAbove,2.0)) // Changed from 4.5+ default
set(Sid::rehearsalMarkPosAbove, rehearsalMarkPosAbove);
}
else if (tag.startsWith("noteLine")) // Mu4.5+ only, let's skip
e.skipCurrentElement();
else if (tag == "glissandoType" // Mu4.5+ only, let's skip
Expand Down
13 changes: 11 additions & 2 deletions libmscore/tempotext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "measure.h"
#include "musescoreCore.h"
#include "rehearsalmark.h"
#include "score.h"
#include "staff.h"
#include "system.h"
Expand Down Expand Up @@ -435,13 +436,21 @@ void TempoText::layout()
{
TextBase::layout();

if (!autoplace())
return;

Segment* s = segment();
if (!s) // for use in palette
return;

// tempo text on first chordrest of measure should align over time sig if present
//
if (autoplace() && s->rtick().isZero()) {

if (RehearsalMark* rehearsalMark = toRehearsalMark(s->findAnnotation(ElementType::REHEARSAL_MARK, track(), track()))) {
qreal rightEdge = rehearsalMark->bbox().translated(rehearsalMark->pos()).right();
const qreal padding = 0.5 * fontMetrics().xHeight();
rxpos() += rightEdge + padding;
}
else if (s->rtick().isZero()) {
Segment* p = segment()->prev(SegmentType::TimeSig);
if (p) {
rxpos() -= s->x() - p->x();
Expand Down

0 comments on commit 01d26f6

Please sign in to comment.