ソースを参照

feat(Rhythm): Show rhythm in new part. (merge #776) (see EngravingRules.ShowRhythmAgainAfterPartEndOrFinalBarline)

Merge pull request #776 from opensheetmusicdisplay/fix/ShowRhythmAfterEndLine

fix: show rhythm in first system measure, if last system ended with end-barline
Simon 5 年 前
コミット
1c76733d5a

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

@@ -58,6 +58,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;
@@ -293,6 +294,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;
 
@@ -740,6 +742,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;
     }

+ 13 - 3
src/MusicalScore/Graphical/MusicSystemBuilder.ts

@@ -55,6 +55,7 @@ export class MusicSystemBuilder {
 
     public buildMusicSystems(): MusicSystem[] {
         const systemMaxWidth: number = this.getFullPageSystemWidth();
+        let prevMeasureEndsPart: boolean = false;
         this.measureListIndex = 0;
         this.currentSystemParams = new SystemBuildParameters();
 
@@ -75,7 +76,7 @@ export class MusicSystemBuilder {
                 graphicalMeasures[idx].resetLayout();
             }
             const sourceMeasure: SourceMeasure = graphicalMeasures[0].parentSourceMeasure;
-            const sourceMeasureEndsSystem: boolean = sourceMeasure.BreakSystemAfter;
+            const sourceMeasureEndsPart: boolean = sourceMeasure.HasEndLine;
             const isSystemStartMeasure: boolean = this.currentSystemParams.IsSystemStartMeasure();
             const isFirstSourceMeasure: boolean = sourceMeasure === this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();
             let currentMeasureBeginInstructionsWidth: number = this.rules.MeasureLeftMargin;
@@ -89,7 +90,14 @@ export class MusicSystemBuilder {
             const measureStartLine: SystemLinesEnum = this.getMeasureStartLine();
             currentMeasureBeginInstructionsWidth += this.getLineWidth(graphicalMeasures[0], measureStartLine, isSystemStartMeasure);
             if (!this.leadSheet) {
-                currentMeasureBeginInstructionsWidth += this.addBeginInstructions(graphicalMeasures, isSystemStartMeasure, isFirstSourceMeasure);
+                let forceShowRhythm: boolean = false;
+                if (prevMeasureEndsPart && this.rules.ShowRhythmAgainAfterPartEndOrFinalBarline) {
+                    forceShowRhythm = true;
+                }
+                currentMeasureBeginInstructionsWidth += this.addBeginInstructions(  graphicalMeasures,
+                                                                                    isSystemStartMeasure,
+                                                                                    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;
@@ -123,13 +131,15 @@ export class MusicSystemBuilder {
                 );
                 this.updateActiveClefs(sourceMeasure, graphicalMeasures);
                 this.measureListIndex++;
-                if (sourceMeasureEndsSystem) {
+                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.
             }
         }
         if (this.currentSystemParams.systemMeasures.length > 0) {

+ 1 - 2
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -495,8 +495,7 @@ export class InstrumentReader {
           if (this.repetitionInstructionReader !== undefined) {
            const measureEndsSystem: boolean = this.repetitionInstructionReader.handleLineRepetitionInstructions(xmlNode);
            if (measureEndsSystem) {
-             this.currentMeasure.BreakSystemAfter = true;
-             this.currentMeasure.endsPiece = true;
+             this.currentMeasure.HasEndLine = true;
            }
           }
           const location: IXmlAttribute = xmlNode.attribute("location");

+ 1 - 1
src/MusicalScore/ScoreIO/MusicSheetReader.ts

@@ -147,7 +147,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         }
 
         while (couldReadMeasure) {
-            if (this.currentMeasure !== undefined && this.currentMeasure.endsPiece) {
+            if (this.currentMeasure !== undefined && this.currentMeasure.HasEndLine) {
                 sourceMeasureCounter = 0;
             }
             this.currentMeasure = new SourceMeasure(this.completeNumberOfStaves, this.musicSheet.Rules);

+ 6 - 11
src/MusicalScore/VoiceData/SourceMeasure.ts

@@ -27,8 +27,7 @@ export class SourceMeasure {
     constructor(completeNumberOfStaves: number, rules: EngravingRules) {
         this.completeNumberOfStaves = completeNumberOfStaves;
         this.implicitMeasure = false;
-        this.breakSystemAfter = false;
-        this.endsPiece = false;
+        this.hasEndLine = false;
         this.endingBarStyleXml = "";
         this.endingBarStyleEnum = SystemLinesEnum.SingleThin;
         this.firstInstructionsStaffEntries = new Array(completeNumberOfStaves);
@@ -46,10 +45,6 @@ export class SourceMeasure {
      */
     public measureListIndex: number;
     /**
-     * The measure number for showing on the music sheet. Typically starts with 1.
-     */
-    public endsPiece: boolean;
-    /**
      * The style of the ending bar line.
      */
     public endingBarStyleXml: string;
@@ -68,7 +63,7 @@ export class SourceMeasure {
     private tempoExpressions: MultiTempoExpression[] = [];
     private verticalSourceStaffEntryContainers: VerticalSourceStaffEntryContainer[] = [];
     private implicitMeasure: boolean;
-    private breakSystemAfter: boolean;
+    private hasEndLine: boolean;
     private graphicalMeasureErrors: boolean[] = [];
     private firstInstructionsStaffEntries: SourceStaffEntry[];
     private lastInstructionsStaffEntries: SourceStaffEntry[];
@@ -122,12 +117,12 @@ export class SourceMeasure {
         this.implicitMeasure = value;
     }
 
-    public get BreakSystemAfter(): boolean {
-        return this.breakSystemAfter;
+    public get HasEndLine(): boolean {
+        return this.hasEndLine;
     }
 
-    public set BreakSystemAfter(value: boolean) {
-        this.breakSystemAfter = value;
+    public set HasEndLine(value: boolean) {
+        this.hasEndLine = value;
     }
 
     public get StaffLinkedExpressions(): MultiExpression[][] {