ソースを参照

fix(Accidentals): remember quarter sharp/flat, don't automatically put a natural after them (#903)

fix #903

this is a bit of an edge case, because quarter sharps and flats are usually not in key signatures.
sschmid 4 年 前
コミット
0696624d77

+ 10 - 4
src/MusicalScore/Graphical/AccidentalCalculator.ts

@@ -72,14 +72,20 @@ export class AccidentalCalculator {
                     this.keySignatureNoteAlterationsDict.getValue(pitchKey) !== pitch.AccidentalHalfTones) {
                     this.currentAlterationsComparedToKeyInstructionList.push(pitchKey);
                     this.currentInMeasureNoteAlterationsDict.setValue(pitchKey, pitch.AccidentalHalfTones);
-                } else {
+                } else if (pitch.Accidental !== AccidentalEnum.NONE) {
                     this.currentInMeasureNoteAlterationsDict.remove(pitchKey);
                 }
 
+                const inMeasureAlterationAccidental: AccidentalEnum = this.currentInMeasureNoteAlterationsDict.getValue(pitchKey);
                 if (pitch.Accidental === AccidentalEnum.NONE) {
-                    // If an AccidentalEnum.NONE is given, it would not be rendered.
-                    // We need here to convert to a AccidentalEnum.NATURAL:
-                    pitch = new Pitch(pitch.FundamentalNote, pitch.Octave, AccidentalEnum.NATURAL);
+                    if (Math.abs(inMeasureAlterationAccidental) === 0.5) {
+                        // fix to remember quartersharp and quarterflat and not make them natural on following notes
+                        pitch = new Pitch(pitch.FundamentalNote, pitch.Octave, AccidentalEnum.NONE);
+                    } else {
+                        // If an AccidentalEnum.NONE is given, it would not be rendered.
+                        // We need here to convert to a AccidentalEnum.NATURAL:
+                        pitch = new Pitch(pitch.FundamentalNote, pitch.Octave, AccidentalEnum.NATURAL);
+                    }
                 }
                 MusicSheetCalculator.symbolFactory.addGraphicalAccidental(graphicalNote, pitch);
             }

+ 336 - 0
test/data/test_quarter_accidentals.musicxml

@@ -0,0 +1,336 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise version="3.1">
+  <work>
+    <work-title>Quarter Accidentals Test</work-title>
+    </work>
+  <identification>
+    <encoding>
+      <software>MuseScore 3.5.2</software>
+      <encoding-date>2020-11-04</encoding-date>
+      <supports element="accidental" type="yes"/>
+      <supports element="beam" type="yes"/>
+      <supports element="print" attribute="new-page" type="yes" value="yes"/>
+      <supports element="print" attribute="new-system" type="yes" value="yes"/>
+      <supports element="stem" type="yes"/>
+      </encoding>
+    </identification>
+  <defaults>
+    <scaling>
+      <millimeters>7.05556</millimeters>
+      <tenths>40</tenths>
+      </scaling>
+    <page-layout>
+      <page-height>1683.36</page-height>
+      <page-width>1190.88</page-width>
+      <page-margins type="even">
+        <left-margin>56.6929</left-margin>
+        <right-margin>56.6929</right-margin>
+        <top-margin>56.6929</top-margin>
+        <bottom-margin>113.386</bottom-margin>
+        </page-margins>
+      <page-margins type="odd">
+        <left-margin>56.6929</left-margin>
+        <right-margin>56.6929</right-margin>
+        <top-margin>56.6929</top-margin>
+        <bottom-margin>113.386</bottom-margin>
+        </page-margins>
+      </page-layout>
+    <word-font font-family="FreeSerif" font-size="10"/>
+    <lyric-font font-family="FreeSerif" font-size="11"/>
+    </defaults>
+  <credit page="1">
+    <credit-type>title</credit-type>
+    <credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">quarter accidentals test</credit-words>
+    </credit>
+  <part-list>
+    <score-part id="P1">
+      <part-name>Piano</part-name>
+      <part-abbreviation>Pno.</part-abbreviation>
+      <score-instrument id="P1-I1">
+        <instrument-name>Piano</instrument-name>
+        </score-instrument>
+      <midi-device id="P1-I1" port="1"></midi-device>
+      <midi-instrument id="P1-I1">
+        <midi-channel>1</midi-channel>
+        <midi-program>1</midi-program>
+        <volume>78.7402</volume>
+        <pan>0</pan>
+        </midi-instrument>
+      </score-part>
+    </part-list>
+  <part id="P1">
+    <measure number="1" width="228.03">
+      <print>
+        <system-layout>
+          <system-margins>
+            <left-margin>0.00</left-margin>
+            <right-margin>-0.00</right-margin>
+            </system-margins>
+          <top-system-distance>170.00</top-system-distance>
+          </system-layout>
+        </print>
+      <attributes>
+        <divisions>1</divisions>
+        <key>
+          <fifths>0</fifths>
+          </key>
+        <time>
+          <beats>3</beats>
+          <beat-type>4</beat-type>
+          </time>
+        <clef>
+          <sign>G</sign>
+          <line>2</line>
+          </clef>
+        </attributes>
+      <note default-x="88.46" default-y="-40.00">
+        <pitch>
+          <step>E</step>
+          <alter>0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qs</text>
+          </lyric>
+        </note>
+      <note default-x="134.45" default-y="-40.00">
+        <pitch>
+          <step>E</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>up</stem>
+        </note>
+      <note default-x="180.44" default-y="-40.00">
+        <pitch>
+          <step>E</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>up</stem>
+        </note>
+      </measure>
+    <measure number="2" width="154.84">
+      <note default-x="15.27" default-y="-35.00">
+        <pitch>
+          <step>F</step>
+          <alter>-0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-flat</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qf</text>
+          </lyric>
+        </note>
+      <note default-x="61.26" default-y="-35.00">
+        <pitch>
+          <step>F</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>up</stem>
+        </note>
+      <note default-x="107.25" default-y="-35.00">
+        <pitch>
+          <step>F</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>up</stem>
+        </note>
+      </measure>
+    <measure number="3" width="167.02">
+      <note default-x="14.39" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <alter>0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qs</text>
+          </lyric>
+        </note>
+      <note default-x="64.74" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>natural</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>n</text>
+          </lyric>
+        </note>
+      <note default-x="115.08" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>up</stem>
+        </note>
+      </measure>
+    <measure number="4" width="182.75">
+      <note default-x="14.39" default-y="-25.00">
+        <pitch>
+          <step>A</step>
+          <alter>0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qs</text>
+          </lyric>
+        </note>
+      <note default-x="69.98" default-y="-25.00">
+        <pitch>
+          <step>A</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>natural</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>n</text>
+          </lyric>
+        </note>
+      <note default-x="125.56" default-y="-25.00">
+        <pitch>
+          <step>A</step>
+          <alter>0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qs</text>
+          </lyric>
+        </note>
+      </measure>
+    <measure number="5" width="185.20">
+      <note default-x="15.27" default-y="-20.00">
+        <pitch>
+          <step>B</step>
+          <alter>-0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-flat</accidental>
+        <stem>down</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qf</text>
+          </lyric>
+        </note>
+      <note default-x="71.38" default-y="-20.00">
+        <pitch>
+          <step>B</step>
+          <alter>0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-sharp</accidental>
+        <stem>down</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qs</text>
+          </lyric>
+        </note>
+      <note default-x="127.49" default-y="-20.00">
+        <pitch>
+          <step>B</step>
+          <alter>-0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <accidental>quarter-flat</accidental>
+        <stem>down</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>qf</text>
+          </lyric>
+        </note>
+      </measure>
+    <measure number="6" width="159.65">
+      <note default-x="10.00" default-y="-15.00">
+        <pitch>
+          <step>C</step>
+          <octave>5</octave>
+          </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>down</stem>
+        <lyric number="1" default-x="6.58" default-y="-46.92" relative-y="-30.00">
+          <syllabic>single</syllabic>
+          <text>n</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        </note>
+      <note>
+        <rest/>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        </note>
+      <barline location="right">
+        <bar-style>light-heavy</bar-style>
+        </barline>
+      </measure>
+    </part>
+  </score-partwise>