Skip to content

Commit

Permalink
fix #25803: account for user offset during chord layout
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed May 27, 2014
1 parent a7f05da commit fbc6761
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 21 deletions.
20 changes: 11 additions & 9 deletions libmscore/chord.cpp
Expand Up @@ -1693,7 +1693,8 @@ void Chord::layoutPitched()
c->layoutPitched();

qreal _spatium = spatium();
qreal minNoteDistance = score()->styleS(StyleIdx::dotNoteDistance).val() * _spatium;
qreal dotNoteDistance = score()->styleS(StyleIdx::dotNoteDistance).val() * _spatium;
qreal minNoteDistance = score()->styleS(StyleIdx::minNoteDistance).val() * _spatium;
qreal minTieLength = score()->styleS(StyleIdx::MinTieLength).val() * _spatium;

while (_ledgerLines) {
Expand Down Expand Up @@ -1743,11 +1744,11 @@ void Chord::layoutPitched()

Accidental* accidental = note->accidental();
if (accidental) {
qreal x = accidental->x() + note->x();
// convert x position of accidental to segment coordinate system
if (_noteType == NoteType::NORMAL)
x += note->chord()->x();
x -= score()->styleS(StyleIdx::accidentalDistance).val() * _spatium;
qreal x = accidental->pos().x() + note->pos().x();
if (_noteType == NoteType::NOTE_NORMAL)
x += ipos().x();
// x -= score()->styleS(StyleIdx::accidentalDistance).val() * _spatium;
lll = qMax(lll, -x);
}

Expand Down Expand Up @@ -1835,7 +1836,7 @@ void Chord::layoutPitched()
lll += _spatium * .5;

if (dots()) {
qreal x = dotPosX() + minNoteDistance
qreal x = dotPosX() + dotNoteDistance
+ (dots()-1) * score()->styleS(StyleIdx::dotDotDistance).val() * _spatium;
x += symWidth(SymId::augmentationDot);
rrr = qMax(rrr, x);
Expand Down Expand Up @@ -1863,7 +1864,7 @@ void Chord::layoutPitched()
s = s->prev(Segment::SegChordRest);
if (s && s->element(track()) && s->element(track())->type() == ElementType::CHORD
&& static_cast<Chord*>(s->element(track()))->ledgerLines()) {
// TODO: detect case were one chord is above staff, the other below
// TODO: detect case where one chord is above staff, the other below
lll = qMax(_spatium * 0.8f, lll);
}
}
Expand Down Expand Up @@ -1936,7 +1937,8 @@ void Chord::layoutPitched()
void Chord::layoutTablature()
{
qreal _spatium = spatium();
qreal minNoteDistance = score()->styleS(StyleIdx::dotNoteDistance).val() * _spatium;
qreal dotNoteDistance = score()->styleS(StyleIdx::dotNoteDistance).val() * _spatium;
qreal minNoteDistance = score()->styleS(StyleIdx::minNoteDistance).val() * _spatium;

for (Chord* c : _graceNotes)
c->layoutTablature();
Expand Down Expand Up @@ -2059,7 +2061,7 @@ void Chord::layoutTablature()
lll += _spatium * .5;

if (dots()) {
qreal x = dotPosX() + minNoteDistance
qreal x = dotPosX() + dotNoteDistance
+ (dots()-1) * score()->styleS(StyleIdx::dotDotDistance).val() * _spatium;
x += symWidth(SymId::augmentationDot);
if (x > rrr)
Expand Down
31 changes: 25 additions & 6 deletions libmscore/layout.cpp
Expand Up @@ -771,12 +771,15 @@ void Score::layoutChords3(QList<Note*>& notes, Staff* staff, Segment* segment)

note->rypos() = (note->line() + stepOffset) * stepDistance;
note->rxpos() = x;
// we need to do this now
// or else note pos / readPos / userOff will be out of sync
// and we rely on note->x() throughout the layout process
note->adjustReadPos();

// find leftmost non-mirrored note to set as X origin for accidental layout
// a mirrored note that extends to left of segment X origin
// will displace accidentals only if there is conflict
qreal sx = chord->x() + note->x();

qreal sx = x + chord->x(); // segment-relative X position of note
if (note->mirror() && !chord->up() && sx < 0.0)
leftNotes.append(note);
else if (sx < lx)
Expand Down Expand Up @@ -1014,6 +1017,9 @@ void Score::layoutChords3(QList<Note*>& notes, Staff* staff, Segment* segment)
}

for (const AcEl& e : aclist) {
// even though we initially calculate accidental position relative to segment
// we must record pos for accidental relative to note,
// since pos is always interpreted relative to parent
Note* note = e.note;
qreal x = e.x + lx - (note->x() + note->chord()->x());
note->accidental()->setPos(x, 0);
Expand Down Expand Up @@ -3460,10 +3466,12 @@ qreal Score::computeMinWidth(Segment* fs)
for (Note* note : c->notes()) {
if (note->accidental()) {
accidental = true;
accidentalX = qMin(accidentalX, note->accidental()->x() + note->x());
// segment-relative
accidentalX = qMin(accidentalX, note->accidental()->x() + note->x() + c->x());
}
else
noteX = qMin(noteX, note->x());
// segment-relative
noteX = qMin(noteX, note->x() + c->x());
}
}
}
Expand Down Expand Up @@ -3494,8 +3502,19 @@ qreal Score::computeMinWidth(Segment* fs)
minDistance = qMax(minDistance, clefKeyRightMargin);
}
cr->layout();
space.max(cr->space());
foreach(Lyrics* l, cr->lyricsList()) {

// calculate space needed for segment
// take cr position into account
// by converting to segment-relative space
qreal cx = cr->userOff().x();
qreal lx = qMax(cx, 0.0); // nudge left shouldn't require more leading space
qreal rx = qMin(cx, 0.0); // nudge right shouldn't require more trailing space
Space crSpace = cr->space();
Space segRelSpace(crSpace.lw()-lx, crSpace.rw()+rx);
space.max(segRelSpace);

// lyrics
foreach (Lyrics* l, cr->lyricsList()) {
if (!l)
continue;
if (!l->isEmpty()) {
Expand Down
17 changes: 14 additions & 3 deletions libmscore/measure.cpp
Expand Up @@ -3133,10 +3133,10 @@ void Measure::layoutX(qreal stretch)
for (Note* note : c->notes()) {
if (note->accidental()) {
accidental = true;
accidentalX = qMin(accidentalX, note->accidental()->x() + note->x());
accidentalX = qMin(accidentalX, note->accidental()->x() + note->x() + c->x());
}
else
noteX = qMin(noteX, note->x());
noteX = qMin(noteX, note->x() + c->x());
}
}
}
Expand Down Expand Up @@ -3177,7 +3177,18 @@ void Measure::layoutX(qreal stretch)
if ((pt & Segment::SegKeySig) || firstClef)
minDistance = qMax(minDistance, clefKeyRightMargin);
}
space.max(cr->space());

// calculate space needed for segment
// take cr position into account
// by converting to segment-relative space
qreal cx = cr->userOff().x();
qreal lx = qMax(cx, 0.0); // nudge left shouldn't require more leading space
qreal rx = qMin(cx, 0.0); // nudge right shouldn't require more trailing space
Space crSpace = cr->space();
Space segRelSpace(crSpace.lw()-lx, crSpace.rw()+rx);
space.max(segRelSpace);

// lyrics
int n = cr->lyricsList().size();
for (int i = 0; i < n; ++i) {
Lyrics* l = cr->lyricsList().at(i);
Expand Down
4 changes: 3 additions & 1 deletion libmscore/note.cpp
Expand Up @@ -1526,7 +1526,9 @@ void Note::layout()

void Note::layout2()
{
adjustReadPos();
// this is now done in Score::layoutChords3()
// so that the results are available there
// adjustReadPos();

int dots = chord()->dots();
if (dots) {
Expand Down
Binary file modified vtest/accidental-8.mscz
Binary file not shown.
2 changes: 1 addition & 1 deletion vtest/gen
Expand Up @@ -26,7 +26,7 @@ else
chord-layout-6 chord-layout-7 chord-layout-8 chord-layout-9 chord-layout-10 chord-layout-11\
accidental-1 accidental-2 accidental-3 accidental-4\
accidental-5 accidental-6 accidental-7 accidental-8\
tie-1 grace-1 harmony-1 beams-1 beams-2"
tie-1 grace-1 harmony-1 beams-1 beams-2 user-offset-1 user-offset-2"
fi

DPI=130
Expand Down
2 changes: 1 addition & 1 deletion vtest/gen.bat
Expand Up @@ -13,7 +13,7 @@ set SRC=mmrest-1,bravura-mmrest,mmrest-2,mmrest-4,mmrest-5,mmrest-6,mmrest-7,mmr
chord-layout-6,chord-layout-7,chord-layout-8,chord-layout-9,chord-layout-10, chord-layout-11, ^
accidental-1,accidental-2,accidental-3,accidental-4, ^
accidental-5,accidental-6,accidental-7,accidental-8, ^
tie-1,grace-1,harmony-1,beams-1,beams-2
tie-1,grace-1,harmony-1,beams-1,beams-2,user-offset-1,user-offset-2

set MSCORE=..\win32install\bin\mscore.exe
set DPI=130
Expand Down
Binary file added vtest/user-offset-1.mscz
Binary file not shown.
Binary file added vtest/user-offset-2.mscz
Binary file not shown.

0 comments on commit fbc6761

Please sign in to comment.