diff --git a/libmscore/note.cpp b/libmscore/note.cpp index 83a57b7f332b0..70daaf2bc1219 100644 --- a/libmscore/note.cpp +++ b/libmscore/note.cpp @@ -2151,6 +2151,16 @@ bool Note::dotIsUp() const return (_userDotPosition == Direction::UP); } +static bool hasAlteredUnison(Note* note) + { + const auto& chordNotes = note->chord()->notes(); + AccidentalVal accVal = tpc2alter(note->tpc()); + int relLine = absStep(note->tpc(), note->epitch()); + return std::find_if(chordNotes.begin(), chordNotes.end(), [note, accVal, relLine](Note* n) { + return n != note && !n->hidden() && absStep(n->tpc(), n->epitch()) == relLine && tpc2alter(n->tpc()) != accVal; + }) != chordNotes.end(); +} + //--------------------------------------------------------- // updateAccidental // set _accidental and _line depending on tpc @@ -2183,6 +2193,11 @@ void Note::updateAccidental(AccidentalState* as) else if (acci == AccidentalType::NONE) acci = AccidentalType::NATURAL; } + else if (hasAlteredUnison(this)) { + if ((acci = Accidental::value2subtype(accVal)) == AccidentalType::NONE) { + acci = AccidentalType::NATURAL; + } + } if (acci != AccidentalType::NONE && !_hidden) { if (_accidental == 0) { Accidental* a = new Accidental(score()); diff --git a/mtest/libmscore/note/altered-unison.mscx b/mtest/libmscore/note/altered-unison.mscx new file mode 100644 index 0000000000000..873c39c507152 --- /dev/null +++ b/mtest/libmscore/note/altered-unison.mscx @@ -0,0 +1,187 @@ + + + 3.6.2 + 3224f34 + + + 0 + 480 + + 1 + 1 + 1 + 0 + + + + 2021-07-31 + + + + Microsoft Windows + + + + + x + + 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 + + Piano + + Piano + Pno. + Piano + 21 + 108 + 21 + 108 + keyboard.piano + + 100 + 95 + + + 100 + 33 + + + 100 + 50 + + + 100 + 67 + + + 100 + 100 + + + 120 + 67 + + + 150 + 100 + + + 150 + 50 + + + 120 + 50 + + + 120 + 100 + + + + Fluid + + + + + + 10 + + + x + + + + + + 4 + 4 + + + quarter + + accidentalFlat + 7012 + + + accidentalNatural + 7119 + + + + quarter + + accidentalSharp + 7321 + + + accidentalNatural + 7214 + + + + half + + + + +
+
diff --git a/mtest/libmscore/note/tst_note.cpp b/mtest/libmscore/note/tst_note.cpp index ba09887798e77..9bc2a320723b3 100644 --- a/mtest/libmscore/note/tst_note.cpp +++ b/mtest/libmscore/note/tst_note.cpp @@ -48,6 +48,7 @@ class TestNote : public QObject, public MTest void tpcTranspose2(); void noteLimits(); void tpcDegrees(); + void alteredUnison(); void LongNoteAfterShort_183746(); }; @@ -488,6 +489,18 @@ void TestNote::noteLimits() QVERIFY(saveCompareScore(score, "notelimits-test.mscx", DIR + "notelimits-ref.mscx")); } +void TestNote::alteredUnison() + { + MasterScore* score = readScore(DIR + "altered-unison.mscx"); + Measure* m = score->firstMeasure(); + Chord* c = m->findChord(Fraction(0, 1), 0); + QVERIFY(c->downNote()->accidental() && c->downNote()->accidental()->accidentalType() == Ms::AccidentalType::FLAT); + QVERIFY(c->upNote()->accidental() && c->upNote()->accidental()->accidentalType() == Ms::AccidentalType::NATURAL); + c = m->findChord(Fraction(1, 4), 0); + QVERIFY(c->downNote()->accidental() && c->downNote()->accidental()->accidentalType() == Ms::AccidentalType::NATURAL); + QVERIFY(c->upNote()->accidental() && c->upNote()->accidental()->accidentalType() == Ms::AccidentalType::SHARP); + } + void TestNote::tpcDegrees() { QCOMPARE(tpc2degree(Tpc::TPC_C, Key::C), 0);