Skip to content

Commit

Permalink
Fix #308242: Elements that need fixing for StaffType Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
elerouxx committed Nov 24, 2020
1 parent c5b16a4 commit ae7d3b5
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 10 deletions.
5 changes: 5 additions & 0 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ void BarLine::drawDots(QPainter* painter, qreal x) const
qreal offset = (score()->scoreFont()->name() == "Leland" || score()->scoreFont()->name() == "Bravura" || score()->scoreFont()->name() == "Petaluma") ? 0 : 0.5 * score()->spatium() * mag();
y1l = st->doty1() * _spatium + offset;
y2l = st->doty2() * _spatium + offset;

//adjust for staffType offset
qreal stYOffset = st->yoffset().val() * _spatium;
y1l += stYOffset;
y2l += stYOffset;
}
drawSymbol(SymId::repeatDot, painter, QPointF(x, y1l));
drawSymbol(SymId::repeatDot, painter, QPointF(x, y2l));
Expand Down
9 changes: 6 additions & 3 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ void Chord::addLedgerLines()
qreal lineDistance = 1;
qreal mag = 1;
bool staffVisible = true;
int stepOffset = 0; // for staff type changes with a step offset

if (segment()) { //not palette
Fraction tick = segment()->tick();
Expand All @@ -710,10 +711,11 @@ void Chord::addLedgerLines()
lineDistance = st->lineDistance(tick);
mag = staff()->mag(tick);
staffVisible = !staff()->invisible(tick);
stepOffset = st->staffType(tick)->stepOffset();
}

// need ledger lines?
if (downLine() <= lineBelow + 1 && upLine() >= -1)
if (downLine() + stepOffset <= lineBelow + 1 && upLine() + stepOffset >= -1)
return;

// the extra length of a ledger line with respect to notehead (half of it on each side)
Expand Down Expand Up @@ -746,7 +748,7 @@ void Chord::addLedgerLines()
}
for (int i = from; i < int(n) && i >= 0 ; i += delta) {
Note* note = _notes.at(i);
int l = note->line();
int l = note->line() + stepOffset;

// if 1st pass and note not below staff or 2nd pass and note not above staff
if ((!j && l <= lineBelow + 1) || (j && l >= -1))
Expand Down Expand Up @@ -1805,7 +1807,8 @@ QPointF Chord::pagePos() const
System* system = pc->segment()->system();
if (!system)
return p;
p.ry() += system->staffYpage(vStaffIdx());
qreal staffYOffset = staff() ? staff()->staffType(tick())->yoffset().val() * spatium() : 0.0;
p.ry() += system->staffYpage(vStaffIdx()) + staffYOffset;
return p;
}
return Element::pagePos();
Expand Down
10 changes: 8 additions & 2 deletions libmscore/clef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void Clef::layout()
qreal yoff = 0.0;
if (clefType() != ClefType::INVALID && clefType() != ClefType::MAX) {
symId = ClefInfo::symId(clefType());
yoff = lineDist * (lines - ClefInfo::line(clefType()));
yoff = lineDist * (5 - ClefInfo::line(clefType()));
}
else
symId = SymId::noSym;
Expand All @@ -172,24 +172,30 @@ void Clef::layout()
case ClefType::TAB: // TAB clef
// on tablature, position clef at half the number of spaces * line distance
yoff = lineDist * (lines - 1) * .5;
stepOffset = 0; // ignore stepOffset for TAB and pecussion clefs
break;
case ClefType::TAB4: // TAB clef 4 strings
// on tablature, position clef at half the number of spaces * line distance
yoff = lineDist * (lines - 1) * .5;
stepOffset = 0;
break;
case ClefType::TAB_SERIF: // TAB clef alternate style
// on tablature, position clef at half the number of spaces * line distance
yoff = lineDist * (lines - 1) * .5;
stepOffset = 0;
break;
case ClefType::TAB4_SERIF: // TAB clef alternate style
// on tablature, position clef at half the number of spaces * line distance
yoff = lineDist * (lines - 1) * .5;
stepOffset = 0;
break;
case ClefType::PERC: // percussion clefs
yoff = lineDist * (lines - 1) * 0.5;
stepOffset = 0;
break;
case ClefType::PERC2:
yoff = lineDist * (lines - 1) * 0.5;
stepOffset = 0;
break;
case ClefType::INVALID:
case ClefType::MAX:
Expand All @@ -202,7 +208,7 @@ void Clef::layout()
// other clefs are right aligned
QRectF r(symBbox(symId));
qreal x = segment() && segment()->rtick().isNotZero() ? -r.right() : 0.0;
setPos(x, yoff * _spatium + (stepOffset * -_spatium));
setPos(x, yoff * _spatium + (stepOffset * 0.5 * _spatium));

setbbox(r);
}
Expand Down
9 changes: 9 additions & 0 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ void Score::createCRSequence(const Fraction& f, ChordRest* cr, const Fraction& t
Tie* tie = new Tie(this);
tie->setStartNote(on);
tie->setEndNote(nn);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(cr->track());
on->setTieFor(tie);
nn->setTieBack(tie);
Expand Down Expand Up @@ -756,6 +758,7 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction

if (tie) {
tie->setEndNote(note);
tie->setTick2(tie->endNote()->tick());
note->setTieBack(tie);
addTie = tie;
}
Expand All @@ -779,6 +782,7 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction
if (i+1 < n) {
tie = new Tie(this);
tie->setStartNote(note);
tie->setTick(tie->startNote()->tick());
tie->setTrack(track);
note->setTieFor(tie);
}
Expand Down Expand Up @@ -819,6 +823,7 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction
if (!isRest) {
tie = new Tie(this);
tie->setStartNote((Note*)nr);
tie->setTick(tie->startNote()->tick());
tie->setTrack(nr->track());
((Note*)nr)->setTieFor(tie);
}
Expand Down Expand Up @@ -2946,6 +2951,8 @@ void Score::cmdImplode()
Tie* tie = new Tie(this);
tie->setStartNote(tn);
tie->setEndNote(nn);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(tn->track());
undoAddElement(tie);
}
Expand Down Expand Up @@ -3327,6 +3334,7 @@ Segment* Score::setChord(Segment* segment, int track, Chord* chordTemplate, Frac
for (size_t j = 0; j < notes.size(); ++j) {
tie[j] = new Tie(this);
tie[j]->setStartNote(notes[j]);
tie[j]->setTick(tie[j]->startNote()->tick());
tie[j]->setTrack(track);
notes[j]->setTieFor(tie[j]);
addTie = true;
Expand Down Expand Up @@ -3371,6 +3379,7 @@ Segment* Score::setChord(Segment* segment, int track, Chord* chordTemplate, Frac
for (size_t i = 0; i < notes.size(); ++i) {
tie[i] = new Tie(this);
tie[i]->setStartNote(notes[i]);
tie[i]->setTick(tie[i]->startNote()->tick());
tie[i]->setTrack(notes[i]->track());
notes[i]->setTieFor(tie[i]);
}
Expand Down
18 changes: 14 additions & 4 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ Chord* Score::addChord(const Fraction& tick, TDuration d, Chord* oc, bool genTie
Tie* tie = new Tie(this);
tie->setStartNote(n1);
tie->setEndNote(n2);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(n1->track());
undoAddElement(tie);
}
Expand Down Expand Up @@ -988,6 +990,8 @@ Note* Score::addTiedMidiPitch(int pitch, bool addFlag, Chord* prevChord)
Tie* tie = new Tie(this);
tie->setStartNote(nn);
tie->setEndNote(n);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(n->track());
n->setTieBack(tie);
nn->setTieFor(tie);
Expand Down Expand Up @@ -1148,6 +1152,8 @@ void Score::regroupNotesAndRests(const Fraction& startTick, const Fraction& endT
tie = new Tie(this);
tie->setStartNote(nl1[j]);
tie->setEndNote(nl2[j]);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(tr);
nl1[j]->setTieFor(tie);
nl2[j]->setTieBack(tie);
Expand Down Expand Up @@ -1195,6 +1201,8 @@ void Score::regroupNotesAndRests(const Fraction& startTick, const Fraction& endT
tie = new Tie(this);
tie->setStartNote(tieBack[i]);
tie->setEndNote(n);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(track);
n->setTieBack(tie);
tieBack[i]->setTieFor(tie);
Expand All @@ -1204,6 +1212,8 @@ void Score::regroupNotesAndRests(const Fraction& startTick, const Fraction& endT
tie = new Tie(this);
tie->setStartNote(nn);
tie->setEndNote(tieFor[i]);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(track);
n->setTieFor(tie);
tieFor[i]->setTieBack(tie);
Expand Down Expand Up @@ -1319,8 +1329,8 @@ void Score::cmdAddTie(bool addToChord)
tie->setStartNote(note);
tie->setEndNote(nnote);
tie->setTrack(note->track());
tie->setTick(note->chord()->segment()->tick());
tie->setTicks(nnote->chord()->segment()->tick() - note->chord()->segment()->tick());
tie->setTick(note->chord()->segment()->tick());
tie->setTicks(nnote->chord()->segment()->tick() - note->chord()->segment()->tick());
undoAddElement(tie);
if (!addFlag || nnote->chord()->tick() >= lastAddedChord->tick() || nnote->chord()->isGrace()) {
break;
Expand All @@ -1340,8 +1350,8 @@ tie->setTicks(nnote->chord()->segment()->tick() - note->chord()->segment()->tick
tie->setStartNote(note);
tie->setEndNote(note2);
tie->setTrack(note->track());
tie->setTick(note->chord()->segment()->tick());
tie->setTicks(note2->chord()->segment()->tick() - note->chord()->segment()->tick());
tie->setTick(note->chord()->segment()->tick());
tie->setTicks(note2->chord()->segment()->tick() - note->chord()->segment()->tick());
undoAddElement(tie);
}
}
Expand Down
9 changes: 9 additions & 0 deletions libmscore/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,9 @@ QVector<QLineF> Element::genericDragAnchorLines() const
yp = system->staffCanvasYpage(stIdx);
if (placement() == Placement::BELOW)
yp += system->staff(stIdx)->bbox().height();
//adjust anchor Y positions to staffType offset
if (staff())
yp += staff()->staffTypeForElement(this)->yoffset().val()* spatium();
}
else
yp = parent()->canvasPos().y();
Expand Down Expand Up @@ -2471,6 +2474,12 @@ void Element::autoplaceSegmentElement(bool above, bool add)
SysStaff* ss = m->system()->staff(si);
QRectF r = bbox().translated(m->pos() + s->pos() + pos());

// Adjust bbox Y pos for staffType offset
if (staffType()) {
qreal stYOffset = staffType()->yoffset().val() * sp;
r.translate(0.0, stYOffset);
}

SkylineLine sk(!above);
qreal d;
if (above) {
Expand Down
4 changes: 4 additions & 0 deletions libmscore/keysig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ void KeySig::layout()
}
}

// Follow stepOffset
if (staffType())
rypos() = staffType()->stepOffset() * 0.5 * _spatium;

// compute bbox
for (KeySym& ks : _sig.keySymbols()) {
ks.pos = ks.spos * _spatium;
Expand Down
5 changes: 5 additions & 0 deletions libmscore/ledgerline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ void LedgerLine::layout()
if (staff())
setColor(staff()->staffType(tick())->color());
qreal w2 = _width * .5;

//Adjust Y position to staffType offset
if (staffType())
rypos() += staffType()->yoffset().val() * spatium();

if (vertical)
bbox().setRect(-w2, 0, w2, _len);
else
Expand Down
3 changes: 3 additions & 0 deletions libmscore/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ QVector<QLineF> LineSegment::gripAnchorLines(Grip grip) const
y = system()->staffYpage(stIdx);
if (line()->placement() == Placement::BELOW)
y += system()->staff(stIdx)->bbox().height();
// adjust Y to staffType offset
if (staffType())
y += staffType()->yoffset().val() * spatium();
}

const Page* p = system()->page();
Expand Down
4 changes: 4 additions & 0 deletions libmscore/lyricsline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ void LyricsLineSegment::layout()
nextLyr->rxpos() -= (toX - fromX);
}

// apply yoffset for staff type change (keeps lyrics lines aligned with lyrics)
if (staffType())
rypos() += staffType()->yoffset().val() * spatium();

// set bounding box
QRectF r = QRectF(0.0, 0.0, pos2().x(), pos2().y()).normalized();
qreal lw = lyricsLine()->lineWidth() * .5;
Expand Down
2 changes: 2 additions & 0 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ Note::Note(const Note& n, bool link)
if (n._tieFor) {
_tieFor = new Tie(*n._tieFor);
_tieFor->setStartNote(this);
_tieFor->setTick(_tieFor->startNote()->tick());
_tieFor->setEndNote(0);
}
else
Expand Down Expand Up @@ -1121,6 +1122,7 @@ void Note::add(Element* e)
case ElementType::TIE: {
Tie* tie = toTie(e);
tie->setStartNote(this);
tie->setTick(tie->startNote()->tick());
tie->setTrack(track());
setTieFor(tie);
if (tie->endNote())
Expand Down
12 changes: 12 additions & 0 deletions libmscore/noteentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag, InputState* externalInputStat
Tie* tie = new Tie(this);
tie->setStartNote(note);
tie->setEndNote(firstTiedNote);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(note->track());
undoAddElement(tie);
}
Expand Down Expand Up @@ -301,6 +303,14 @@ void Score::putNote(const QPointF& pos, bool replace, bool insert)
Score* score = p.segment->score();
// it is not safe to call Score::repitchNote() if p is on a TAB staff
bool isTablature = staff(p.staffIdx)->isTabStaff(p.segment->tick());

// calculate actual clicked line from staffType offset and stepOffset
Staff* ss = score->staff(p.staffIdx);
int stepOffset = ss->staffType(p.segment->tick())->stepOffset();
qreal stYOffset = ss->staffType(p.segment->tick())->yoffset().val();
qreal lineDist = ss->staffType(p.segment->tick())->lineDistance().val();
p.line -= stepOffset + 2 * stYOffset / lineDist;

if (score->inputState().usingNoteEntryMethod(NoteEntryMethod::REPITCH) && !isTablature)
score->repitchNote(p, replace);
else {
Expand Down Expand Up @@ -546,6 +556,8 @@ void Score::repitchNote(const Position& p, bool replace)
Tie* tie = new Tie(this);
tie->setStartNote(note);
tie->setEndNote(firstTiedNote);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(note->track());
undoAddElement(tie);
}
Expand Down
2 changes: 2 additions & 0 deletions libmscore/paste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t, const Interval& src
Tie* tie = new Tie(this);
tie->setStartNote(nl1[i]);
tie->setEndNote(nl2[i]);
tie->setTick(tie->startNote()->tick());
tie->setTick2(tie->endNote()->tick());
tie->setTrack(c->track());
Tie* tie2 = nl1[i]->tieFor();
if (tie2) {
Expand Down
5 changes: 5 additions & 0 deletions libmscore/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ void SlurSegment::layoutSegment(const QPointF& p1, const QPointF& p2)
ups(Grip::START).p = p1;
ups(Grip::END).p = p2;
_extraHeight = 0.0;

//Adjust Y pos to staff type yOffset before other calculations
if (staffType())
rypos() += staffType()->yoffset().val() * spatium();

computeBezier();

if (autoplace() && system()) {
Expand Down
2 changes: 1 addition & 1 deletion libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ int Staff::channel(const Fraction& tick, int voice) const

int Staff::middleLine(const Fraction& tick) const
{
return lines(tick) - 1;
return lines(tick) - 1 - staffType(tick)->stepOffset();
}

//---------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions libmscore/textlinebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ void TextLineBaseSegment::layout()
if (spanner()->placeBelow())
rypos() = staff() ? staff()->height() : 0.0;

// adjust Y pos to staffType offset
if (staffType())
rypos() += staffType()->yoffset().val() * spatium();

if (!tl->diagonal())
_offset2.setY(0);

Expand Down
Loading

0 comments on commit ae7d3b5

Please sign in to comment.