Skip to content

Commit

Permalink
fix #38501: cheap partial fix for start position of cross-staff and c…
Browse files Browse the repository at this point in the history
…ross-system gliss
  • Loading branch information
MarcSabatella committed Nov 7, 2014
1 parent 28a4ebd commit 98235e5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 25 deletions.
51 changes: 39 additions & 12 deletions libmscore/glissando.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "score.h"
#include "segment.h"
#include "staff.h"
#include "system.h"
#include "style.h"
#include "sym.h"
#include "xml.h"
Expand Down Expand Up @@ -60,18 +61,18 @@ void Glissando::layout()
if (chord == 0)
return;
Note* anchor2 = chord->upNote();
Segment* s = chord->segment();
s = s->prev1();
while (s) {
if ((s->segmentType() & (Segment::Type::ChordRest)) && s->element(track()))
Segment* s2 = chord->segment();
Segment* s1 = s2->prev1();
while (s1) {
if ((s1->segmentType() & (Segment::Type::ChordRest)) && s1->element(track()))
break;
s = s->prev1();
s1 = s1->prev1();
}
if (s == 0) {
if (s1 == 0) {
qDebug("no segment for first note of glissando found");
return;
}
ChordRest* cr = static_cast<ChordRest*>(s->element(track()));
ChordRest* cr = static_cast<ChordRest*>(s1->element(track()));
if (cr == 0 || cr->type() != Element::Type::CHORD) {
qDebug("no first note for glissando found, track %d", track());
return;
Expand All @@ -82,8 +83,34 @@ void Glissando::layout()
setPos(0.0, 0.0);
adjustReadPos();

QPointF cp1 = anchor1->pagePos();
QPointF cp2 = anchor2->pagePos();
// since line will be drawn relative to end note,
// calculate offsets for start note coordinates relative to end note
qreal x1off;
qreal y1off;
QPointF cp1 = anchor1->pagePos();
QPointF cp2 = anchor2->pagePos();

// layout of glissandi happens before we have staff positions within the system
// so these "page" positions are not accurate across different staves
// cheap partial fix for cross-staff glissandi: adjust vertical position according to difference in staffMove
int moveDiff = anchor2->chord()->staffMove() - anchor1->chord()->staffMove();
if (moveDiff)
y1off = moveDiff * 4.0 * _spatium;

// now calculate offsets
if (s1->system() == s2->system()) {
// normal case - start and end note in same system
x1off = cp2.x() - cp1.x();
if (!moveDiff)
y1off = cp2.y() - cp1.y();
}
else {
// cheap partial fix for cross system glissandi: just draw a short line into end note
// TODO: draw line coming out of start note on previous system
x1off = 4.0 * _spatium;
if (!moveDiff)
y1off = anchor2->pos().y() - anchor1->pos().y();
}

// line starting point
int dots = static_cast<Chord*>(cr)->dots();
Expand All @@ -92,8 +119,8 @@ void Glissando::layout()
// if no dots, from right of ledger line, if any; from right of note head, if no ledger line
qreal x1 = (dots ? anchor1->dot(dots-1)->pos().x() + anchor1->dot(dots-1)->width()
: (ledLin ? ledLin->pos().x() + ledLin->width() : anchor1->headWidth()) )
- (cp2.x() - cp1.x()); // make relative to end note
qreal y1 = anchor1->pos().y();
- x1off; // make relative to end note
qreal y1 = anchor2->y() - y1off;
// line end point: left of note head
qreal x2 = anchor2->pos().x();
qreal y2 = anchor2->pos().y();
Expand Down Expand Up @@ -121,7 +148,7 @@ void Glissando::layout()
}

// shorten line to avoid end note ledger line
ledLin=anchor2->chord()->ledgerLines();
ledLin = anchor2->chord()->ledgerLines();
if (ledLin)
x2 = ledLin->pos().x();
// shorten line so it doesn't go through end note accidental or arpeggio
Expand Down
15 changes: 11 additions & 4 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3586,13 +3586,20 @@ qreal Score::computeMinWidth(Segment* fs, bool firstMeasureInSystem)
cr->layout();

// special case:
// make extra space for ties continued from previous system
// make extra space for ties or glissandi continued from previous system

if (firstMeasureInSystem && cr->type() == Element::Type::CHORD && cr->tick() == cr->measure()->tick()) {
Chord* c = static_cast<Chord*>(cr);
for (Note* note : c->notes()) {
if (note->tieBack())
minDistance = qMax(minDistance, _spatium * 2);
if (c->glissando()) {
minDistance = qMax(minDistance, _spatium * 2);
}
else {
for (Note* note : c->notes()) {
if (note->tieBack()) {
minDistance = qMax(minDistance, _spatium * 2);
break;
}
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3175,14 +3175,20 @@ void Measure::layoutX(qreal stretch)
}

// special case:
// make extra space for ties continued from previous system
// make extra space for ties or glissandi continued from previous system

if (cr->type() == Element::Type::CHORD) {
Chord* c = static_cast<Chord*>(cr);
if (system()->firstMeasure() == this && c->tick() == tick()) {
for (Note* note : c->notes()) {
if (note->tieBack()) {
minDistance = qMax(minDistance, _spatium * 2);
if (c->glissando()) {
minDistance = qMax(minDistance, _spatium * 2);
}
else {
for (Note* note : c->notes()) {
if (note->tieBack()) {
minDistance = qMax(minDistance, _spatium * 2);
break;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vtest/gen
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else
emmentaler-text-1 gonville-text-1 bravura-text-1 musejazz-text-1\
emmentaler-text-2 gonville-text-2 bravura-text-2 musejazz-text-2\
emmentaler-text-3 gonville-text-3 bravura-text-3 musejazz-text-3\
frametext ottava slurs-1 slurs-2 hairpins-1 pedal-1 line-1 line-2 line-3 line-4\
frametext ottava slurs-1 slurs-2 hairpins-1 pedal-1 line-1 line-2 line-3 line-4 gliss-1 gliss-2\
chord-layout-1 chord-layout-2 chord-layout-3 chord-layout-4 chord-layout-5\
chord-layout-6 chord-layout-7 chord-layout-8 chord-layout-9 chord-layout-10\
chord-layout-11 chord-layout-12 chord-layout-13 chord-layout-14 cross-1\
Expand Down
8 changes: 4 additions & 4 deletions vtest/gen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ set SRC=mmrest-1,bravura-mmrest,gonville-mmrest,mmrest-2,mmrest-4,mmrest-5,mmres
emmentaler-6,bravura-6,gonville-6,emmentaler-7,bravura-7,gonville-7, ^
emmentaler-8,bravura-8,gonville-8,emmentaler-9,bravura-9,gonville-9,i ^
emmentaler-10,bravura-10,gonville-10,emmentaler-11,bravura-11,gonville-11, ^
emmentaler-text-1,bravura-test-1,gonville-test-1,musejazz-text-1 ^
emmentaler-text-2,bravura-test-2,gonville-test-2,musejazz-text-2 ^
emmentaler-text-3,bravura-test-3,gonville-test-3,musejazz-text-3 ^
frametext,ottava,slurs-1,slurs-2,hairpins-1,pedal-1,line-1,line-2,line-3,line-4, ^
emmentaler-text-1,bravura-test-1,gonville-test-1,musejazz-text-1, ^
emmentaler-text-2,bravura-test-2,gonville-test-2,musejazz-text-2, ^
emmentaler-text-3,bravura-test-3,gonville-test-3,musejazz-text-3, ^
frametext,ottava,slurs-1,slurs-2,hairpins-1,pedal-1,line-1,line-2,line-3,line-4,gliss-1,gliss-2, ^
chord-layout-1,chord-layout-2,chord-layout-3,chord-layout-4,chord-layout-5, ^
chord-layout-6,chord-layout-7,chord-layout-8,chord-layout-9,chord-layout-10, ^
chord-layout-11,chord-layout-12,chord-layout-13,chord-layout-14,cross-1, ^
Expand Down
Binary file added vtest/gliss-1-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/gliss-1.mscz
Binary file not shown.
Binary file added vtest/gliss-2-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/gliss-2.mscz
Binary file not shown.

0 comments on commit 98235e5

Please sign in to comment.