Skip to content

Commit

Permalink
Fix #323402: Accidentals not shown as expected for altered unisons
Browse files Browse the repository at this point in the history
backport of musescore#8772
  • Loading branch information
wizofaus authored and Jojo-Schmitz committed Aug 3, 2021
1 parent ac8394c commit 8e79bfc
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
187 changes: 187 additions & 0 deletions mtest/libmscore/note/altered-unison.mscx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="3.02">
<programVersion>3.6.2</programVersion>
<programRevision>3224f34</programRevision>
<Score>
<LayerTag id="0" tag="default"></LayerTag>
<currentLayer>0</currentLayer>
<Division>480</Division>
<Style>
<pageWidth>8.27</pageWidth>
<pageHeight>11.69</pageHeight>
<enableVerticalSpread>1</enableVerticalSpread>
<useStandardNoteNames>0</useStandardNoteNames>
<Spatium>1.75</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer"></metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="creationDate">2021-07-31</metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="platform">Microsoft Windows</metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">x</metaTag>
<Order id="orchestral" customized="1">
<name>Orchestral</name>
<instrument id="piano">
<family id="keyboards">Keyboards</family>
</instrument>
<section id="woodwind" brackets="true" showSystemMarkings="true" barLineSpan="true" thinBrackets="true">
<family>flutes</family>
<family>oboes</family>
<family>clarinets</family>
<family>saxophones</family>
<family>bassoons</family>
<unsorted group="woodwinds"/>
</section>
<section id="brass" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>horns</family>
<family>trumpets</family>
<family>cornets</family>
<family>flugelhorns</family>
<family>trombones</family>
<family>tubas</family>
</section>
<section id="timpani" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>timpani</family>
</section>
<section id="percussion" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>keyboard-percussion</family>
<family>drums</family>
<family>unpitched-metal-percussion</family>
<family>unpitched-wooden-percussion</family>
<family>other-percussion</family>
</section>
<family>keyboards</family>
<family>harps</family>
<family>organs</family>
<family>synths</family>
<section id="plucked-strings" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>plucked-strings</family>
</section>
<soloists/>
<section id="voices" brackets="true" showSystemMarkings="false" barLineSpan="false" thinBrackets="true">
<family>voices</family>
</section>
<section id="strings" brackets="true" showSystemMarkings="true" barLineSpan="true" thinBrackets="true">
<family>orchestral-strings</family>
</section>
<unsorted/>
</Order>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<bracket type="1" span="2" col="2"/>
<barLineSpan>1</barLineSpan>
</Staff>
<trackName>Piano</trackName>
<Instrument id="piano">
<longName>Piano</longName>
<shortName>Pno.</shortName>
<trackName>Piano</trackName>
<minPitchP>21</minPitchP>
<maxPitchP>108</maxPitchP>
<minPitchA>21</minPitchA>
<maxPitchA>108</maxPitchA>
<instrumentId>keyboard.piano</instrumentId>
<Articulation>
<velocity>100</velocity>
<gateTime>95</gateTime>
</Articulation>
<Articulation name="staccatissimo">
<velocity>100</velocity>
<gateTime>33</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="portato">
<velocity>100</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="marcato">
<velocity>120</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>150</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="sforzatoStaccato">
<velocity>150</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="marcatoStaccato">
<velocity>120</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="marcatoTenuto">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
<program value="0"/>
<synti>Fluid</synti>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<VBox>
<height>10</height>
<Text>
<style>Title</style>
<text>x</text>
</Text>
</VBox>
<Measure>
<voice>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
</TimeSig>
<Chord>
<durationType>quarter</durationType>
<Note>
<Accidental><subtype>accidentalFlat</subtype></Accidental>
<pitch>70</pitch><tpc>12</tpc>
</Note>
<Note>
<Accidental><subtype>accidentalNatural</subtype></Accidental>
<pitch>71</pitch><tpc>19</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<Accidental><subtype>accidentalSharp</subtype></Accidental>
<pitch>73</pitch><tpc>21</tpc>
</Note>
<Note>
<Accidental><subtype>accidentalNatural</subtype></Accidental>
<pitch>72</pitch><tpc>14</tpc>
</Note>
</Chord>
<Rest>
<durationType>half</durationType>
</Rest>
</voice>
</Measure>
</Staff>
</Score>
</museScore>
13 changes: 13 additions & 0 deletions mtest/libmscore/note/tst_note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TestNote : public QObject, public MTest
void tpcTranspose2();
void noteLimits();
void tpcDegrees();
void alteredUnison();
void LongNoteAfterShort_183746();
};

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8e79bfc

Please sign in to comment.