Sfoglia il codice sorgente

fix(Rhythm): don't print rhythm twice even if given in pickup measure and following measure (#890)

fix #890

this is actually badly exported XML, but it doesn't hurt to prevent this from happening.
previously, the time signature was shown both in the pickup and in the following measure.
sschmid 4 anni fa
parent
commit
d34f5e4d41

+ 14 - 2
src/MusicalScore/Graphical/MusicSystemBuilder.ts

@@ -518,8 +518,20 @@ export class MusicSystemBuilder {
             keyAdded = true;
         }
         if (currentRhythm !== undefined && currentRhythm.PrintObject && this.rules.RenderTimeSignatures) {
-            measure.addRhythmAtBegin(currentRhythm);
-            rhythmAdded = true;
+            let printRhythm: boolean = true;
+            // check for previous pickup measure
+            const pickupMeasureNumber: number = measure.MeasureNumber - 1;
+            if (measure.MeasureNumber - 1 >= 0) {
+                const previousMeasure: SourceMeasure = this.measureList[pickupMeasureNumber][0]?.parentSourceMeasure;
+                if (previousMeasure?.ImplicitMeasure && previousMeasure?.RhythmPrinted) {
+                    printRhythm = false;
+                }
+            }
+            if (printRhythm) {
+                measure.addRhythmAtBegin(currentRhythm);
+                measure.parentSourceMeasure.RhythmPrinted = true;
+                rhythmAdded = true;
+            }
         }
         if (clefAdded || keyAdded || rhythmAdded) {
             instructionsLengthX += measure.beginInstructionsWidth;

+ 1 - 0
src/MusicalScore/VoiceData/SourceMeasure.ts

@@ -61,6 +61,7 @@ export class SourceMeasure {
     private measureNumber: number;
     public MeasureNumberXML: number;
     public MeasureNumberPrinted: number; // measureNumber if MeasureNumberXML undefined or NaN. Set in getPrintedMeasureNumber()
+    public RhythmPrinted: boolean = false; // whether this measure prints a rhythm on the score
     public multipleRestMeasures: number; // usually undefined (0), unless "multiple-rest" given in XML (e.g. 4 measure rest)
     // public multipleRestMeasuresPerStaff: Dictionary<number, number>; // key: staffId. value: how many rest measures
     private absoluteTimestamp: Fraction;

+ 7 - 0
test/data/test_pickup_measure_double_rhythm.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN"
+  "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise version="2.0"><work><work-title>pickup measure double rhythm test</work-title></work><identification><creator type="composer"/><creator type="lyricist"/><rights/><encoding><software>Noteflight version 0.4</software><encoding-date>2020-10-03</encoding-date><supports attribute="new-system" element="print" type="no" value="no"/><supports attribute="new-page" element="print" type="no" value="no"/></encoding></identification><defaults><scaling><millimeters>2.1166666679999997</millimeters><tenths>10</tenths></scaling><page-layout><page-height>1320</page-height><page-width>1020</page-width><page-margins type="both"><left-margin>59.583333333333336</left-margin><right-margin>56.66666666666667</right-margin><top-margin>96.66666666666667</top-margin><bottom-margin>80</bottom-margin></page-margins></page-layout><system-layout><system-margins><left-margin>59.583333333333336</left-margin><right-margin>26.666666666666668</right-margin></system-margins><system-distance>92.5</system-distance><top-system-distance>145.83333333333334</top-system-distance></system-layout><staff-layout><staff-distance>55</staff-distance></staff-layout></defaults><part-list><score-part id="P1"><part-name>Piano</part-name><part-abbreviation>Pno.</part-abbreviation><score-instrument id="P1I1"><instrument-name>Piano</instrument-name><instrument-sound>keyboard.piano</instrument-sound></score-instrument><midi-instrument id="P1I1"><midi-channel>1</midi-channel><midi-program>1</midi-program></midi-instrument></score-part></part-list><part id="P1">
+<measure number="1"><attributes><divisions>64</divisions><key><fifths>1</fifths><mode>major</mode></key><time print-object="yes"><beats>3</beats><beat-type>4</beat-type></time><clef number="1"><sign>G</sign><line>2</line></clef></attributes><direction placement="above"><direction-type><metronome><beat-unit>quarter</beat-unit><per-minute>120</per-minute></metronome></direction-type><sound tempo="120"/></direction><direction placement="above"><direction-type><metronome><beat-unit>quarter</beat-unit><per-minute>120</per-minute></metronome></direction-type><sound tempo="120"/></direction><note><pitch><step>D</step><octave>4</octave></pitch><duration>64</duration><voice>1</voice><type>quarter</type></note></measure>
+<measure number="2"><attributes><time print-object="yes"><beats>3</beats><beat-type>4</beat-type></time></attributes><note><pitch><step>G</step><octave>4</octave></pitch><duration>64</duration><voice>1</voice><type>quarter</type></note><note><pitch><step>G</step><octave>4</octave></pitch><duration>32</duration><voice>1</voice><type>eighth</type><beam number="1">begin</beam></note><note><pitch><step>A</step><octave>4</octave></pitch><duration>32</duration><voice>1</voice><type>eighth</type><beam number="1">end</beam></note><note><pitch><step>G</step><octave>4</octave></pitch><duration>32</duration><voice>1</voice><type>eighth</type><beam number="1">begin</beam></note><note><pitch><step>F</step><alter>1</alter><octave>4</octave></pitch><duration>32</duration><voice>1</voice><type>eighth</type><accidental>sharp</accidental><beam number="1">end</beam></note></measure>
+</part></score-partwise>