Ver Fonte

fix surplus rhythminstruction (#776). feat(Options): add EngravingRule ShowRhythmAgainAfterPartEndOrFinalBarline

fix one small issue with #776: in some cases rhythm instructions (e.g. 4/4)
were added unnecessarily at the last measure of a score,
e.g. in OSMD Function Test - All in the last measure.
this was because we sometimes loop a measure twice in MusicSystemBuilder.buildSystems().

add an EngravingRule to not add these extra rhythminsturctions.

visual regression tests:
OSMD_function_test_auto-custom-coloring-entchen.musicxml_1 45.1892
OSMD_function_test_all.xml_1 1.49208
OSMD_function_test_bar_lines.musicxml_1 1.3059
JosephHaydn_ConcertanteCello.xml_1 0.000824108

these changes are exactly what we want, added rhythm after final barline.
sschmid há 5 anos atrás
pai
commit
1cf47a1bd1

+ 8 - 0
src/MusicalScore/Graphical/EngravingRules.ts

@@ -57,6 +57,7 @@ export class EngravingRules {
     private betweenKeySymbolsDistance: number;
     private keyRightMargin: number;
     private rhythmRightMargin: number;
+    private showRhythmAgainAfterPartEndOrFinalBarline: boolean;
     private inStaffClefScalingFactor: number;
     private distanceBetweenNaturalAndSymbolWhenCancelling: number;
     private noteHelperLinesOffset: number;
@@ -289,6 +290,7 @@ export class EngravingRules {
         this.betweenKeySymbolsDistance = 0.2;
         this.keyRightMargin = 0.75;
         this.rhythmRightMargin = 1.25;
+        this.showRhythmAgainAfterPartEndOrFinalBarline = true;
         this.inStaffClefScalingFactor = 0.8;
         this.distanceBetweenNaturalAndSymbolWhenCancelling = 0.4;
 
@@ -732,6 +734,12 @@ export class EngravingRules {
     public set RhythmRightMargin(value: number) {
         this.rhythmRightMargin = value;
     }
+    public get ShowRhythmAgainAfterPartEndOrFinalBarline(): boolean {
+        return this.showRhythmAgainAfterPartEndOrFinalBarline;
+    }
+    public set ShowRhythmAgainAfterPartEndOrFinalBarline(value: boolean) {
+        this.showRhythmAgainAfterPartEndOrFinalBarline = value;
+    }
     public get InStaffClefScalingFactor(): number {
         return this.inStaffClefScalingFactor;
     }

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

@@ -90,9 +90,14 @@ export class MusicSystemBuilder {
             const measureStartLine: SystemLinesEnum = this.getMeasureStartLine();
             currentMeasureBeginInstructionsWidth += this.getLineWidth(graphicalMeasures[0], measureStartLine, isSystemStartMeasure);
             if (!this.leadSheet) {
+                let forceShowRhythm: boolean = false;
+                if (prevMeasureEndsPart && this.rules.ShowRhythmAgainAfterPartEndOrFinalBarline) {
+                    forceShowRhythm = true;
+                }
                 currentMeasureBeginInstructionsWidth += this.addBeginInstructions(  graphicalMeasures,
                                                                                     isSystemStartMeasure,
-                                                                                    isFirstSourceMeasure || prevMeasureEndsPart);
+                                                                                    isFirstSourceMeasure || forceShowRhythm);
+                // forceShowRhythm could be a fourth parameter instead in addBeginInstructions, but only affects RhythmInstruction for now.
                 currentMeasureEndInstructionsWidth += this.addEndInstructions(graphicalMeasures);
             }
             let currentMeasureVarWidth: number = 0;
@@ -129,12 +134,13 @@ export class MusicSystemBuilder {
                 if (sourceMeasureEndsPart) {
                     this.finalizeCurrentAndCreateNewSystem(graphicalMeasures, true);
                 }
+                prevMeasureEndsPart = sourceMeasureEndsPart;
             } else {
                 // finalize current system and prepare a new one
                 this.finalizeCurrentAndCreateNewSystem(graphicalMeasures, false, doXmlPageBreak);
                 // don't increase measure index to check this measure now again
+                // don't set prevMeasureEndsPart in this case! because we will loop with the same measure again.
             }
-            prevMeasureEndsPart = sourceMeasureEndsPart;
         }
         if (this.currentSystemParams.systemMeasures.length > 0) {
             this.finalizeCurrentAndCreateNewSystem(this.measureList[this.measureList.length - 1], true);