Pārlūkot izejas kodu

refactor: use enum for endingBarStyle

Simon Schmid 5 gadi atpakaļ
vecāks
revīzija
7ae61a9b8e

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

@@ -681,7 +681,7 @@ export class MusicSystemBuilder {
         if (this.nextMeasureBeginsLineRepetition() && this.thisMeasureEndsLineRepetition()) {
             return SystemLinesEnum.DotsBoldBoldDots;
         }
-        if (this.thisMeasureEndsLineRepetition() && (sourceMeasure && !sourceMeasure.endsPiece)) { // TODO right place to check endsPiece?
+        if (this.thisMeasureEndsLineRepetition()) {
             return SystemLinesEnum.DotsThinBold;
         }
         // always end piece with final barline: not a good idea. user should be able to override final barline.
@@ -696,28 +696,8 @@ export class MusicSystemBuilder {
         if (!sourceMeasure) {
             return SystemLinesEnum.SingleThin;
         }
-        if (sourceMeasure.endingBarStyle === "regular") {
-            return SystemLinesEnum.SingleThin;
-        } else if (sourceMeasure.endingBarStyle === "dotted") {
-            return SystemLinesEnum.Dotted;
-        } else if (sourceMeasure.endingBarStyle === "dashed") {
-            return SystemLinesEnum.Dashed;
-        } else if (sourceMeasure.endingBarStyle === "heavy") {
-            return SystemLinesEnum.Bold;
-        } else if (sourceMeasure.endingBarStyle === "light-light") {
-            return SystemLinesEnum.DoubleThin;
-        } else if (sourceMeasure.endingBarStyle === "light-heavy") {
-            return SystemLinesEnum.ThinBold;
-        } else if (sourceMeasure.endingBarStyle === "heavy-light") {
-            return SystemLinesEnum.BoldThin;
-        } else if (sourceMeasure.endingBarStyle === "heavy-heavy") {
-            return SystemLinesEnum.DoubleBold;
-        } else if (sourceMeasure.endingBarStyle === "tick") {
-            return SystemLinesEnum.Tick;
-        } else if (sourceMeasure.endingBarStyle === "short") {
-            return SystemLinesEnum.Short;
-        } else if (sourceMeasure.endingBarStyle === "none") {
-            return SystemLinesEnum.None;
+        if (sourceMeasure.endingBarStyleEnum !== undefined) {
+            return sourceMeasure.endingBarStyleEnum;
         }
         // TODO: print an error message if the default fallback is used.
         return SystemLinesEnum.SingleThin;

+ 29 - 0
src/MusicalScore/Graphical/SystemLinesEnum.ts

@@ -14,3 +14,32 @@ export enum SystemLinesEnum {
     Tick = 12,            /*              [bar-style=tick]*/
     Short = 13            /*              [bar-style=short]*/
 }
+
+export class SystemLinesEnumHelper {
+    public static xmlBarlineStyleToSystemLinesEnum(xmlValue: string): SystemLinesEnum {
+        if (xmlValue === "regular") {
+            return SystemLinesEnum.SingleThin;
+        } else if (xmlValue === "dotted") {
+            return SystemLinesEnum.Dotted;
+        } else if (xmlValue === "dashed") {
+            return SystemLinesEnum.Dashed;
+        } else if (xmlValue === "heavy") {
+            return SystemLinesEnum.Bold;
+        } else if (xmlValue === "light-light") {
+            return SystemLinesEnum.DoubleThin;
+        } else if (xmlValue === "light-heavy") {
+            return SystemLinesEnum.ThinBold;
+        } else if (xmlValue === "heavy-light") {
+            return SystemLinesEnum.BoldThin;
+        } else if (xmlValue === "heavy-heavy") {
+            return SystemLinesEnum.DoubleBold;
+        } else if (xmlValue === "tick") {
+            return SystemLinesEnum.Tick;
+        } else if (xmlValue === "short") {
+            return SystemLinesEnum.Short;
+        } else if (xmlValue === "none") {
+            return SystemLinesEnum.None;
+        }
+        return SystemLinesEnum.SingleThin;
+    }
+}

+ 1 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -93,7 +93,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         // constructor sets beginning and end bar type to standard
 
         this.stave.setBegBarType(Vex.Flow.Barline.type.NONE); // technically not correct, but we'd need to set the next measure's beginning bar type
-        if (this.parentSourceMeasure && this.parentSourceMeasure.endingBarStyle === "none") {
+        if (this.parentSourceMeasure && this.parentSourceMeasure.endingBarStyleEnum === SystemLinesEnum.None) {
             // fix for vexflow ignoring ending barline style after new stave, apparently
             this.stave.setEndBarType(Vex.Flow.Barline.type.NONE);
         }

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

@@ -25,6 +25,7 @@ import {RepetitionInstructionReader} from "./MusicSymbolModules/RepetitionInstru
 import {SlurReader} from "./MusicSymbolModules/SlurReader";
 import {StemDirectionType} from "../VoiceData/VoiceEntry";
 import {NoteType, NoteTypeHandler} from "../VoiceData";
+import {SystemLinesEnumHelper} from "../Graphical";
 //import Dictionary from "typescript-collections/dist/lib/Dictionary";
 
 // FIXME: The following classes are missing
@@ -478,7 +479,9 @@ export class InstrumentReader {
           }
           const location: IXmlAttribute = xmlNode.attribute("location");
           if (location && location.value === "right") {
-              this.currentMeasure.endingBarStyle = xmlNode.element("bar-style").value;
+            const stringValue: string = xmlNode.element("bar-style").value;
+            this.currentMeasure.endingBarStyleXml = stringValue;
+            this.currentMeasure.endingBarStyleEnum = SystemLinesEnumHelper.xmlBarlineStyleToSystemLinesEnum(stringValue);
           }
           // TODO do we need to process bars with left location too?
         } else if (xmlNode.name === "sound") {

+ 5 - 3
src/MusicalScore/VoiceData/SourceMeasure.ts

@@ -11,7 +11,7 @@ import {MultiTempoExpression} from "./Expressions/MultiTempoExpression";
 import {KeyInstruction} from "./Instructions/KeyInstruction";
 import {AbstractNotationInstruction} from "./Instructions/AbstractNotationInstruction";
 import {Repetition} from "../MusicSource/Repetition";
-import {GraphicalMeasure} from "../Graphical";
+import {GraphicalMeasure, SystemLinesEnum} from "../Graphical";
 //import {BaseIdClass} from "../../Util/BaseIdClass"; // SourceMeasure originally extended BaseIdClass, but ids weren't used.
 
 /**
@@ -29,7 +29,8 @@ export class SourceMeasure {
         this.implicitMeasure = false;
         this.breakSystemAfter = false;
         this.endsPiece = false;
-        this.endingBarStyle = "";
+        this.endingBarStyleXml = "";
+        this.endingBarStyleEnum = SystemLinesEnum.SingleThin;
         this.firstInstructionsStaffEntries = new Array(completeNumberOfStaves);
         this.lastInstructionsStaffEntries = new Array(completeNumberOfStaves);
         this.TempoInBPM = 0;
@@ -50,7 +51,8 @@ export class SourceMeasure {
     /**
      * The style of the ending bar line.
      */
-    public endingBarStyle: string;
+    public endingBarStyleXml: string;
+    public endingBarStyleEnum: SystemLinesEnum;
 
     private measureNumber: number;
     private absoluteTimestamp: Fraction;