diff --git a/src/engraving/libmscore/note.cpp b/src/engraving/libmscore/note.cpp index 20049db29003e..98ebe5e2b7b65 100644 --- a/src/engraving/libmscore/note.cpp +++ b/src/engraving/libmscore/note.cpp @@ -2322,6 +2322,15 @@ bool Note::dotIsUp() const } } +static bool chordHasAnotherAccidentalForSameNote(Note* note) +{ + const auto& chordNotes = note->chord()->notes(); + AccidentalVal accVal = tpc2alter(note->tpc()); + return std::find_if(chordNotes.begin(), chordNotes.end(), [note, accVal](Note* n) { + return n != note && !n->hidden() && tpc2alter(n->tpc()) != accVal; + }) != chordNotes.end(); +} + //--------------------------------------------------------- // updateAccidental // set _accidental and _line depending on tpc @@ -2354,6 +2363,10 @@ void Note::updateAccidental(AccidentalState* as) } else if (acci == AccidentalType::NONE) { acci = AccidentalType::NATURAL; } + } else if (chordHasAnotherAccidentalForSameNote(this)) { + if ((acci = Accidental::value2subtype(accVal)) == AccidentalType::NONE) { + acci = AccidentalType::NATURAL; + } } if (acci != AccidentalType::NONE && !_hidden) { if (_accidental == 0) { diff --git a/src/engraving/tests/note_data/altered-unison.mscx b/src/engraving/tests/note_data/altered-unison.mscx new file mode 100644 index 0000000000000..873c39c507152 --- /dev/null +++ b/src/engraving/tests/note_data/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/src/engraving/tests/tst_note.cpp b/src/engraving/tests/tst_note.cpp index c34c5abcea62a..4349eabe98691 100644 --- a/src/engraving/tests/tst_note.cpp +++ b/src/engraving/tests/tst_note.cpp @@ -58,6 +58,7 @@ private slots: void tpcTranspose2(); void noteLimits(); void tpcDegrees(); + void alteredUnison(); void LongNoteAfterShort_183746(); }; @@ -513,6 +514,18 @@ void TestNote::tpcDegrees() //QCOMPARE(tpc2degree(Tpc::TPC_B_S, Key::C_S), 7); } +void TestNote::alteredUnison() +{ + MasterScore* score = readScore(NOTE_DATA_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); +} + //--------------------------------------------------------- /// LongNoteAfterShort_183746 /// Put a small 128th rest