From 8415e64472a8fb13f7f89cdc585e04d799db97ca Mon Sep 17 00:00:00 2001 From: Lovens Date: Sat, 20 Nov 2021 10:29:25 +0100 Subject: [PATCH] Fix GH#9779 beam stem direction flip Update chord's set stem direction method to set the beam's direction to Direction::AUTO if applicable. Update the beam's set direction method to update its notes' stem direction. When a beam's direction is set with the "x" keyboard key, the "_direction" member of the beam class is no longer equal to "Direction::AUTO". So, in the beam's layout code the final beam direction is not taken from the first note in the note group (of the beam) but from the "_direction" member. The problem is that if the user tries to set the beam's direction with a note stem direction (in the property panel), it will be ignored in the beam's layout code. Backport of #9800, resp. duplicate of #9851 --- libmscore/beam.cpp | 8 +- libmscore/chord.cpp | 4 +- libmscore/chord.h | 2 +- .../beam/flipBeamStemDir-01-ref.mscx | 663 ++++++++++++++++++ mtest/libmscore/beam/flipBeamStemDir.mscx | 663 ++++++++++++++++++ mtest/libmscore/beam/tst_beam.cpp | 21 + mtest/libmscore/beam/updateReference | 2 +- 7 files changed, 1359 insertions(+), 4 deletions(-) create mode 100644 mtest/libmscore/beam/flipBeamStemDir-01-ref.mscx create mode 100644 mtest/libmscore/beam/flipBeamStemDir.mscx diff --git a/libmscore/beam.cpp b/libmscore/beam.cpp index 0b0e8df962b1f..2923d49a123a9 100644 --- a/libmscore/beam.cpp +++ b/libmscore/beam.cpp @@ -2228,8 +2228,14 @@ std::vector Beam::gripsPositions(const EditData& ed) const void Beam::setBeamDirection(Direction d) { _direction = d; - if (d != Direction::AUTO) + if (d != Direction::AUTO) { _up = d == Direction::UP; + if (!_elements.empty()) { + Chord* c = toChord(_elements.first()); + if (c) + c->setStemDirection(d, d); + } + } } //--------------------------------------------------------- diff --git a/libmscore/chord.cpp b/libmscore/chord.cpp index 22f887326dbc9..8af8a49b45aa7 100644 --- a/libmscore/chord.cpp +++ b/libmscore/chord.cpp @@ -2762,7 +2762,7 @@ qreal Chord::dotPosX() const // setStemDirection //--------------------------------------------------------- -void Chord::setStemDirection(Direction d) +void Chord::setStemDirection(Direction d, Direction beamDir) { _stemDirection = d; if (beam()) { @@ -2771,6 +2771,8 @@ void Chord::setStemDirection(Direction d) if (c) c->_stemDirection = d; } + if (beamDir == Direction::AUTO) + beam()->setBeamDirection(beamDir); } } diff --git a/libmscore/chord.h b/libmscore/chord.h index 2a4a2031f74c4..50baea68664a2 100644 --- a/libmscore/chord.h +++ b/libmscore/chord.h @@ -106,7 +106,7 @@ class Chord final : public ChordRest { bool readProperties(XmlReader&) override; Element* drop(EditData&) override; - void setStemDirection(Direction d); + void setStemDirection(Direction d, Direction beamDir = Direction::AUTO); Direction stemDirection() const { return _stemDirection; } LedgerLine* ledgerLines() { return _ledgerLines; } diff --git a/mtest/libmscore/beam/flipBeamStemDir-01-ref.mscx b/mtest/libmscore/beam/flipBeamStemDir-01-ref.mscx new file mode 100644 index 0000000000000..cb12dff70d38b --- /dev/null +++ b/mtest/libmscore/beam/flipBeamStemDir-01-ref.mscx @@ -0,0 +1,663 @@ + + + + + 0 + 480 + + 1 + 1 + 1 + 0 + + + + + + + mscx + + + + + + + Orchestral + + Keyboards + +
+ flutes + oboes + clarinets + saxophones + bassoons + +
+
+ horns + trumpets + cornets + flugelhorns + trombones + tubas +
+
+ timpani +
+
+ keyboard-percussion + drums + unpitched-metal-percussion + unpitched-wooden-percussion + other-percussion +
+ keyboards + harps + organs + synths +
+ plucked-strings +
+ +
+ voices +
+
+ orchestral-strings +
+ +
+ + + + stdNormal + + + 1 + + + + stdNormal + + F + + Piano + + Piano + Pno. + Piano + 21 + 108 + 21 + 108 + keyboard.piano + F + + + + + + + + + + 4 + 4 + + + 17 + 17 + + + eighth + down + + 72 + 14 + + + + eighth + down + + 72 + 14 + + + + eighth + down + + 72 + 14 + + + + eighth + down + + 72 + 14 + + + + half + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + + + 4 + 4 + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + +
+
diff --git a/mtest/libmscore/beam/flipBeamStemDir.mscx b/mtest/libmscore/beam/flipBeamStemDir.mscx new file mode 100644 index 0000000000000..cb12dff70d38b --- /dev/null +++ b/mtest/libmscore/beam/flipBeamStemDir.mscx @@ -0,0 +1,663 @@ + + + + + 0 + 480 + + 1 + 1 + 1 + 0 + + + + + + + mscx + + + + + + + Orchestral + + Keyboards + +
+ flutes + oboes + clarinets + saxophones + bassoons + +
+
+ horns + trumpets + cornets + flugelhorns + trombones + tubas +
+
+ timpani +
+
+ keyboard-percussion + drums + unpitched-metal-percussion + unpitched-wooden-percussion + other-percussion +
+ keyboards + harps + organs + synths +
+ plucked-strings +
+ +
+ voices +
+
+ orchestral-strings +
+ +
+ + + + stdNormal + + + 1 + + + + stdNormal + + F + + Piano + + Piano + Pno. + Piano + 21 + 108 + 21 + 108 + keyboard.piano + F + + + + + + + + + + 4 + 4 + + + 17 + 17 + + + eighth + down + + 72 + 14 + + + + eighth + down + + 72 + 14 + + + + eighth + down + + 72 + 14 + + + + eighth + down + + 72 + 14 + + + + half + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + + + 4 + 4 + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + + + + measure + 4/4 + + + + +
+
diff --git a/mtest/libmscore/beam/tst_beam.cpp b/mtest/libmscore/beam/tst_beam.cpp index 3ee4346cf4124..664d6483d6874 100644 --- a/mtest/libmscore/beam/tst_beam.cpp +++ b/mtest/libmscore/beam/tst_beam.cpp @@ -49,6 +49,7 @@ class TestBeam : public QObject, public MTest void beamCrossMeasure3() { beam("Beam-CrossM3.mscx"); } void beamCrossMeasure4() { beam("Beam-CrossM4.mscx"); } void beamStemDir(); + void flipBeamStemDir(); }; //--------------------------------------------------------- @@ -116,6 +117,26 @@ void TestBeam::beamStemDir() delete score; } +//--------------------------------------------------------- +// flipBeamStemDir +// This method tests if a beam's stem direction can be +// set with a note after its direction has been set +// with the beam's own setBeamDirection method. +//--------------------------------------------------------- +void TestBeam::flipBeamStemDir() + { + MasterScore* score = readScore(DIR + "flipBeamStemDir.mscx"); + QVERIFY(score); + Measure* m1 = score->firstMeasure(); + ChordRest* cr = toChordRest(m1->findSegment(SegmentType::ChordRest, m1->tick())->element(0)); + Chord* c2 = toChord(cr->beam()->elements()[1]); + cr->beam()->setBeamDirection(Direction::UP); + c2->setStemDirection(Direction::DOWN); + score->update(); + score->doLayout(); + QVERIFY(saveCompareScore(score, "flipBeamStemDir-01.mscx", DIR + "flipBeamStemDir-01-ref.mscx")); + delete score; + } QTEST_MAIN(TestBeam) #include "tst_beam.moc" diff --git a/mtest/libmscore/beam/updateReference b/mtest/libmscore/beam/updateReference index 72abd21f641ee..aaf1efe3c3e08 100755 --- a/mtest/libmscore/beam/updateReference +++ b/mtest/libmscore/beam/updateReference @@ -3,7 +3,7 @@ for a in Beam-23.mscx Beam-2.mscx Beam-A.mscx Beam-B.mscx Beam-C.mscx \ Beam-dir.mscx Beam-D.mscx Beam-E.mscx Beam-F.mscx Beam-G.mscx \ Beam-S0.mscx Beam-CrossM2.mscx Beam-CrossM3.mscx Beam-CrossM4.mscx \ - beamStemDir.mscx; do + beamStemDir.mscx flipBeamStemDir.mscx; do cp ../../../build.debug/mtest/libmscore/beam/$a . done