Pārlūkot izejas kodu

feat(bar lines): Add support for double and final bar lines (#519)

original commits by earboxer in PR #519
Zach DeCook 6 gadi atpakaļ
vecāks
revīzija
e05b99a3fc

+ 25 - 0
src/MusicalScore/Graphical/MusicSystemBuilder.ts

@@ -685,6 +685,31 @@ export class MusicSystemBuilder {
         if (this.nextMeasureHasKeyInstructionChange() || this.thisMeasureEndsWordRepetition() || this.nextMeasureBeginsWordRepetition()) {
             return SystemLinesEnum.DoubleThin;
         }
+        const sourceMeasure: SourceMeasure = this.measureList[this.measureListIndex][0].parentSourceMeasure;
+        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;
+        }
+        // TODO: print an error message if the default fallback is used.
         return SystemLinesEnum.SingleThin;
     }
 

+ 14 - 7
src/MusicalScore/Graphical/SystemLinesEnum.ts

@@ -1,9 +1,16 @@
 export enum SystemLinesEnum {
-    SingleThin = 0,
-    DoubleThin = 1,
-    ThinBold = 2,
-    BoldThinDots = 3,
-    DotsThinBold = 4,
-    DotsBoldBoldDots = 5,
-    None = 6
+    SingleThin = 0,       /*SINGLE,       [bar-style=regular]*/
+    DoubleThin = 1,       /*DOUBLE,       [bar-style=light-light]*/
+    ThinBold = 2,         /*END,          [bar-style=light-heavy]*/
+    BoldThinDots = 3,     /*REPEAT_BEGIN, repeat[direction=forward]*/
+    DotsThinBold = 4,     /*REPEAT_END,   repeat[direction=backward]*/
+    DotsBoldBoldDots = 5, /*REPEAT_BOTH*/
+    None = 6,             /*              [bar-style=none]*/
+    Dotted = 7,           /*              [bar-style=dotted]*/
+    Dashed = 8,           /*              [bar-style=dashed]*/
+    Bold = 9,             /*              [bar-style=heavy]*/
+    BoldThin = 10,        /*              [bar-style=heavy-light]*/
+    DoubleBold = 11,      /*              [bar-style=heavy-heavy]*/
+    Tick = 12,            /*              [bar-style=tick]*/
+    Short = 13            /*              [bar-style=short]*/
 }

+ 4 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -199,6 +199,10 @@ export class VexFlowMeasure extends GraphicalMeasure {
                     case SystemLinesEnum.ThinBold:
                         this.stave.setEndBarType(Vex.Flow.Barline.type.END);
                         break;
+                    case SystemLinesEnum.None:
+                        this.stave.setEndBarType(Vex.Flow.Barline.type.NONE);
+                        break;
+                    // TODO: Add support for additional Barline types when VexFlow supports them
                     default:
                         break;
                 }

+ 3 - 0
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -473,6 +473,9 @@ export class InstrumentReader {
              this.currentMeasure.endsPiece = true;
            }
           }
+          if (xmlNode.element("bar-style") !== undefined) {
+            this.currentMeasure.endingBarStyle = xmlNode.element("bar-style").value;
+          }
         } else if (xmlNode.name === "sound") {
           // (*) MetronomeReader.readTempoInstruction(xmlNode, this.musicSheet, this.currentXmlMeasureIndex);
         } else if (xmlNode.name === "harmony") {

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

@@ -29,6 +29,7 @@ export class SourceMeasure {
         this.implicitMeasure = false;
         this.breakSystemAfter = false;
         this.endsPiece = false;
+        this.endingBarStyle = "";
         this.firstInstructionsStaffEntries = new Array(completeNumberOfStaves);
         this.lastInstructionsStaffEntries = new Array(completeNumberOfStaves);
         for (let i: number = 0; i < completeNumberOfStaves; i++) {
@@ -45,6 +46,10 @@ export class SourceMeasure {
      * The measure number for showing on the music sheet. Typically starts with 1.
      */
     public endsPiece: boolean;
+    /**
+     * The style of the ending bar line.
+     */
+    public endingBarStyle: string;
 
     private measureNumber: number;
     private absoluteTimestamp: Fraction;