Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmoniker1 committed Apr 8, 2020
1 parent 447e54d commit 2d568a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
10 changes: 5 additions & 5 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,16 +1424,16 @@ qreal Chord::defaultStemLength() const

qreal Chord::minAbsStemLength() const
{
if (!_tremolo)
return 0.0;

const qreal sw = score()->styleS(Sid::tremoloStrokeWidth).val();
const qreal td = score()->styleS(Sid::tremoloDistance).val();
int beamLvl = beams();
const qreal beamDist = beam() ? beam()->beamDist() : (sw * spatium());

if (!_tremolo)
return 0.0;

// single-note tremolo
else if (!_tremolo->twoNotes()) {
if (!_tremolo->twoNotes()) {
_tremolo->layout(); // guarantee right "height value"

qreal height;
Expand All @@ -1443,7 +1443,7 @@ qreal Chord::minAbsStemLength() const
height = _tremolo->pos().y() + _tremolo->height() - upPos();
const bool hasHook = beamLvl && !beam();
if (hasHook)
beamLvl += (up() ? 4.0 : 2.5); // reserve more space for stem with both hook and tremolo
beamLvl += (up() ? 4 : 2); // reserve more space for stem with both hook and tremolo

const qreal additionalHeight = beamLvl ? 0 : sw * spatium();

Expand Down
33 changes: 17 additions & 16 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2545,43 +2545,44 @@ void layoutDrumsetChord(Chord* c, const Drumset* drumset, const StaffType* st, q

//---------------------------------------------------------
// extendedStemLenWithTwoNotesTremolo
// Extend stem of one of the chords to make the tremolo less steep
// Goal: To extend stem of one of the chords to make the tremolo less steep
// Returns a modified pair of stem lengths of two chords
//---------------------------------------------------------

std::pair<qreal, qreal> extendedStemLenWithTwoNoteTremolo(Tremolo* _tremolo, qreal stemLen1, qreal stemLen2)
std::pair<qreal, qreal> extendedStemLenWithTwoNoteTremolo(Tremolo* tremolo, qreal stemLen1, qreal stemLen2)
{
const qreal _spatium = _tremolo->score()->spatium();
const qreal sw = _tremolo->score()->styleS(Sid::tremoloStrokeWidth).val();
const qreal td = _tremolo->score()->styleS(Sid::tremoloDistance).val();
Chord* c1 = _tremolo->chord1();
Chord* c2 = _tremolo->chord2();
const qreal spatium = tremolo->score()->spatium();
const qreal sw = tremolo->score()->styleS(Sid::tremoloStrokeWidth).val();
const qreal td = tremolo->score()->styleS(Sid::tremoloDistance).val();
Chord* c1 = tremolo->chord1();
Chord* c2 = tremolo->chord2();
Stem* s1 = c1->stem();
Stem* s2 = c2->stem();
const qreal sgn1 = c1->up() ? -1.0 : 1.0;
const qreal sgn2 = c2->up() ? -1.0 : 1.0;
const qreal stemTipDistance = s1 ? (s2->pagePos().y() + stemLen2) - (s1->pagePos().y() + stemLen1)
const qreal stemTipDistance = (s1 && s2) ? (s2->pagePos().y() + stemLen2) - (s1->pagePos().y() + stemLen1)
: (c2->stemPos().y() + stemLen2) - (c1->stemPos().y() + stemLen1);

// same staff & same direction: extend one of the stems
if (c1->staffMove() == c2->staffMove() && c1->up() == c2->up()) {
const bool stem1Higher = stemTipDistance > 0.0;
if (std::abs(stemTipDistance) > 1.0 * _spatium) {
if (std::abs(stemTipDistance) > 1.0 * spatium) {
if ((c1->up() && !stem1Higher) || (!c1->up() && stem1Higher))
return { stemLen1 + sgn1 * (std::abs(stemTipDistance) - 1.0 * _spatium), stemLen2 };
return { stemLen1 + sgn1 * (std::abs(stemTipDistance) - 1.0 * spatium), stemLen2 };
else /* if ((c1->up() && stem1Higher) || (!c1->up() && !stem1Higher)) */
return { stemLen1, stemLen2 + sgn2 * (std::abs(stemTipDistance) - 1.0 * _spatium) };
return { stemLen1, stemLen2 + sgn2 * (std::abs(stemTipDistance) - 1.0 * spatium) };
}
}

// TODO: cross-staff two-note tremolo. Currently doesn't generate the right result in some cases.
#if 0
// cross-staff & beam between staves: extend both stems by the same length
else if (_tremolo->crossStaffBeamBetween()) {
const qreal tremoloMinHeight = ((_tremolo->lines() - 1) * td + sw) * _spatium;
else if (tremolo->crossStaffBeamBetween()) {
const qreal tremoloMinHeight = ((tremolo->lines() - 1) * td + sw) * spatium;
const qreal dy = c1->up() ? tremoloMinHeight - stemTipDistance : tremoloMinHeight + stemTipDistance;
const bool tooShort = dy > 1.0 * _spatium;
const bool tooLong = dy < -1.0 * _spatium;
const qreal idealDistance = 1.0 * _spatium - tremoloMinHeight;
const bool tooShort = dy > 1.0 * spatium;
const bool tooLong = dy < -1.0 * spatium;
const qreal idealDistance = 1.0 * spatium - tremoloMinHeight;

if (tooShort)
return { stemLen1 + sgn1 * (std::abs(stemTipDistance) - idealDistance) / 2.0,
Expand Down
2 changes: 1 addition & 1 deletion libmscore/tremolo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void Tremolo::layoutOneNoteTremolo(qreal x, qreal y, qreal _spatium)
const qreal td = score()->styleS(Sid::tremoloDistance).val();
const qreal sw = score()->styleS(Sid::tremoloStrokeWidth).val();

qreal t;
qreal t = 0.0;
// nearest distance between note and tremolo stroke should be no less than 3.0
if (chord()->hook() || chord()->beam()) {
t = up ? -3.0 - (2.0 * (lines() - 1)) * td - 2.0 * sw : 3.0;
Expand Down

0 comments on commit 2d568a4

Please sign in to comment.